From patchwork Fri Jun 16 12:45:36 2017 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: 105740 Delivered-To: patch@linaro.org Received: by 10.182.29.35 with SMTP id g3csp1258603obh; Fri, 16 Jun 2017 05:49:25 -0700 (PDT) X-Received: by 10.84.179.65 with SMTP id a59mr12330159plc.82.1497617364913; Fri, 16 Jun 2017 05:49:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497617364; cv=none; d=google.com; s=arc-20160816; b=VhzCFIc4KNSVGp9S/tgraJbcBqjGhKBKgMV1NClzqi9ekYDORoyF7HNhguGphGl1av T3ygKrtB45yXySiMaG0PV20WqigTfnyXbZAZ54ErxKYkiJhiqoVHQEKwjVrhvQKKA+G1 Mf+Y0HYv1LyryoZxehKyMbqzK0986PipnKG7+af3IrBIPPKdDU5iR9W9yLAJLNMy/pQS b6MlA5IDL70zjMWvJlXJpZWRzJNLnqbBcyWdOrt3kAMdUJEtvGpfdD+WaYKZalpwNvc8 wmaEDqMhy15Qj8kiL8n2FOCR0tLEt+ALo8OcgLhWHltQbKOPw9x6GAQAbDG8tkpN7M0P YLXg== 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=sO2HMhbqNNZCkgrq1ojTFYlpz4/xtdSPXnfk3NGWU4o=; b=Vbwdxa+llgL7MkAvmIzXX+4O2CqLHIr/gJo7UzMeMAx3+XmG+fu3/yeAk07cnT7VfD mrMkPwKO8Q+iuMO8aDqwdm94yzg74FMEAeeCJoI7uFmWK7UX9iB1rIP2Z9vpLcMjkOxd bVOdz4yNwAssCvjMQ+7cfmywtjgvmouC0W4xWHkXHyrR4up2eSGajfmo3+r/Op0O8+dR VTx1I5vvUm1kNUQZBU3kuc4YFCE4OJN3hcPY/79xir+bwDLGQ6yA7pnnqY8/ca770UJn Tx0IsUX36JPpZoT1lPo2DnMtuzQhoRxQHF2Vw0kh89w/zh73qqLm4npQAIB7ERqCA6Cz SKXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.b=kSwDQvPK; 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 w18si1885448pfi.492.2017.06.16.05.49.24; Fri, 16 Jun 2017 05:49:24 -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.b=kSwDQvPK; 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 S1753932AbdFPMtL (ORCPT + 25 others); Fri, 16 Jun 2017 08:49:11 -0400 Received: from fllnx209.ext.ti.com ([198.47.19.16]:38676 "EHLO fllnx209.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753745AbdFPMtI (ORCPT ); Fri, 16 Jun 2017 08:49:08 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by fllnx209.ext.ti.com (8.15.1/8.15.1) with ESMTP id v5GCkWvD022366; Fri, 16 Jun 2017 07:46:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1497617192; bh=dezjP0bVuhTC1/UeyJ1Lo29UCvOatckGfSxDNSDN/1Y=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=kSwDQvPKADWSMHX+O89M8s2HyYzQMV+0qENdpjeRLFbcG3wye0k9LmuI4yN7xi4Yh GPoEvxFnhzybRjTYFWmg800MUI5GUzmWSVeUjZxCBpw+GFtGk7DJ5AXkp7hmRv1R6B jAuwnMPTKQ6v/X+sP9AnzicsUd9E+7SIbbrWv2EQ= Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id v5GCkRA4012828; Fri, 16 Jun 2017 07:46:27 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.294.0; Fri, 16 Jun 2017 07:46:26 -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 v5GCjjBk000652; Fri, 16 Jun 2017 07:46:23 -0500 From: Kishon Vijay Abraham I To: Ulf Hansson , Rob Herring , Tony Lindgren , CC: Russell King , Ravikumar Kattekola , , , , , , Subject: [PATCH 08/16] mmc: host: omap_hsmmc: Add software timer when timeout greater than hardware capablility Date: Fri, 16 Jun 2017 18:15:36 +0530 Message-ID: <20170616124544.15046-9-kishon@ti.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170616124544.15046-1-kishon@ti.com> References: <20170616124544.15046-1-kishon@ti.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mugunthan V N DRA7 Errata No i834: When using high speed HS200 and SDR104 cards, the functional clock for MMC module will be 192MHz. At this frequency, the maximum obtainable timeout (DTO =0xE) in hardware is (1/192MHz)*2^27 = 700ms. Commands taking longer than 700ms will be affected by this small window frame and will be timing out frequently even without a genune timeout from the card. Workarround for this errata is use a software timer instead of hardware timer to provide the delay requested by the upper layer So adding a software timer as a work around for the errata. Instead of using software timeout only for larger delays requested when using HS200/SDR104 cards which results in hardware and software timer race conditions, so move all the timeout request to use software timer when HS200/SDR104 card is connected and use hardware timer when other type cards are connected. Also start the software timer after queueing to DMA to ensure we are more likely to expire within correct limits. To be ever more sure that we won't expire this soft timer too early, we're adding a 1000000ns slack to the data timeout requested by the upper layer. [rk@ti.com: fix compiler warning in sw timeout function and use sw timeout for busy timeout] Signed-off-by: Ravikumar Kattekola Signed-off-by: Mugunthan V N [kishon@ti.com: Fix the timeout value to account for the entire transfer to complete here.] Signed-off-by: Kishon Vijay Abraham I Signed-off-by: Sekhar Nori --- drivers/mmc/host/omap_hsmmc.c | 126 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 109 insertions(+), 17 deletions(-) -- 2.11.0 diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c index f1d5e8385591..3676ffa72929 100644 --- a/drivers/mmc/host/omap_hsmmc.c +++ b/drivers/mmc/host/omap_hsmmc.c @@ -185,6 +185,11 @@ #define PSTATE_DLEV (0xF << 20) #define PSTATE_DLEV_DAT0 (0x1 << 20) +#define MMC_BLOCK_TRANSFER_TIME_NS(blksz, bus_width, freq) \ + ((unsigned long long) \ + (2 * (((blksz) * NSEC_PER_SEC * \ + (8 / (bus_width))) / (freq)))) + /* * One controller can have multiple slots, like on some omap boards using * omap.c controller driver. Luckily this is not currently done on any known @@ -250,6 +255,8 @@ struct omap_hsmmc_host { struct omap_hsmmc_platform_data *pdata; bool is_tuning; + struct timer_list timer; + unsigned long long data_timeout; /* return MMC cover switch state, can be NULL if not supported. * @@ -631,8 +638,8 @@ static void omap_hsmmc_enable_irq(struct omap_hsmmc_host *host, if (host->use_dma) irq_mask &= ~(BRR_EN | BWR_EN); - /* Disable timeout for erases */ - if (cmd->opcode == MMC_ERASE) + /* Disable timeout for erases or when using software timeout */ + if (cmd && (cmd->opcode == MMC_ERASE || host->data_timeout)) irq_mask &= ~DTO_EN; if (host->flags & CLKEXTFREE_ENABLED) @@ -1239,8 +1246,16 @@ static void omap_hsmmc_do_irq(struct omap_hsmmc_host *host, int status) } OMAP_HSMMC_WRITE(host->base, STAT, status); - if (end_cmd || ((status & CC_EN) && host->cmd)) + if (end_cmd || ((status & CC_EN) && host->cmd)) { omap_hsmmc_cmd_done(host, host->cmd); + if (host->data_timeout) { + unsigned long timeout; + + timeout = jiffies + + nsecs_to_jiffies(host->data_timeout); + mod_timer(&host->timer, timeout); + } + } if ((end_trans || (status & TC_EN)) && host->mrq) omap_hsmmc_xfer_done(host, data); } @@ -1254,7 +1269,19 @@ static irqreturn_t omap_hsmmc_irq(int irq, void *dev_id) int status; status = OMAP_HSMMC_READ(host->base, STAT); + while (status & (INT_EN_MASK | CIRQ_EN)) { + /* + * During a successful bulk data transfer command-completion + * interrupt and transfer-completion interrupt will be + * generated, but software-timeout timer should be deleted + * only on non-cc interrupts (transfer complete or error) + */ + if (host->data_timeout && (status & (~CC_EN))) { + del_timer(&host->timer); + host->data_timeout = 0; + } + if (host->req_in_progress) omap_hsmmc_do_irq(host, status); @@ -1268,6 +1295,25 @@ static irqreturn_t omap_hsmmc_irq(int irq, void *dev_id) return IRQ_HANDLED; } +static void omap_hsmmc_soft_timeout(unsigned long data) +{ + struct omap_hsmmc_host *host = (struct omap_hsmmc_host *)data; + bool end_trans = false; + + omap_hsmmc_disable_irq(host); + if (host->data || host->response_busy) { + host->response_busy = 0; + end_trans = true; + } + + hsmmc_command_incomplete(host, -ETIMEDOUT, 0); + if (end_trans && host->mrq) + omap_hsmmc_xfer_done(host, host->data); + else if (host->cmd) + omap_hsmmc_cmd_done(host, host->cmd); + host->data_timeout = 0; +} + static void set_sd_bus_power(struct omap_hsmmc_host *host) { unsigned long i; @@ -1462,6 +1508,9 @@ static void set_data_timeout(struct omap_hsmmc_host *host, unsigned long long timeout = timeout_ns; unsigned int cycle_ns; uint32_t reg, clkd, dto = 0; + struct mmc_ios *ios = &host->mmc->ios; + struct mmc_data *data = host->mrq->data; + struct mmc_command *cmd = host->mrq->cmd; reg = OMAP_HSMMC_READ(host->base, SYSCTL); clkd = (reg & CLKD_MASK) >> CLKD_SHIFT; @@ -1471,23 +1520,60 @@ static void set_data_timeout(struct omap_hsmmc_host *host, cycle_ns = 1000000000 / (host->clk_rate / clkd); do_div(timeout, cycle_ns); timeout += timeout_clks; - if (timeout) { - while ((timeout & 0x80000000) == 0) { - dto += 1; - timeout <<= 1; - } - dto = 31 - dto; + + if (!timeout) + goto out; + + while ((timeout & 0x80000000) == 0) { + dto += 1; timeout <<= 1; - if (timeout && dto) - dto += 1; - if (dto >= 13) - dto -= 13; - else - dto = 0; - if (dto > 14) - dto = 14; + } + dto = 31 - dto; + timeout <<= 1; + if (timeout && dto) + dto += 1; + if (dto >= 13) + dto -= 13; + else + dto = 0; + if (dto > 14) { + /* + * DRA7 Errata No i834: When using high speed HS200 and + * SDR104 cards, the functional clock for MMC module + * will be 192MHz. At this frequency, the maximum + * obtainable timeout (DTO =0xE) in hardware is + * (1/192MHz)*2^27 = 700ms. Commands taking longer than + * 700ms will be affected by this small window frame + * and will be timing out frequently even without a + * genuine timeout from the card. Workaround for + * this errata is use a software timer instead of + * hardware timer to provide the timeout requested + * by the upper layer. + * + * The timeout from the upper layer denotes the delay + * between the end bit of the read command and the + * start bit of the data block and in the case of + * multiple-read operation, they also define the + * typical delay between the end bit of a data + * block and the start bit of next data block. + * + * Calculate the total timeout value for the entire + * transfer to complete from the timeout value given + * by the upper layer. + */ + if (data) + host->data_timeout = (data->blocks * + (timeout_ns + + MMC_BLOCK_TRANSFER_TIME_NS( + data->blksz, ios->bus_width, + ios->clock))); + else if (cmd->flags & MMC_RSP_BUSY) + host->data_timeout = timeout_ns; + + dto = 14; } +out: reg &= ~DTO_MASK; reg |= dto << DTO_SHIFT; OMAP_HSMMC_WRITE(host->base, SYSCTL, reg); @@ -2347,6 +2433,8 @@ static int omap_hsmmc_probe(struct platform_device *pdev) mmc->ops = &omap_hsmmc_ops; spin_lock_init(&host->irq_lock); + setup_timer(&host->timer, omap_hsmmc_soft_timeout, + (unsigned long)host); host->fclk = devm_clk_get(&pdev->dev, "fck"); if (IS_ERR(host->fclk)) { @@ -2511,6 +2599,8 @@ static int omap_hsmmc_remove(struct platform_device *pdev) dma_release_channel(host->tx_chan); dma_release_channel(host->rx_chan); + del_timer_sync(&host->timer); + pm_runtime_dont_use_autosuspend(host->dev); pm_runtime_put_sync(host->dev); pm_runtime_disable(host->dev); @@ -2544,6 +2634,8 @@ static int omap_hsmmc_suspend(struct device *dev) if (host->dbclk) clk_disable_unprepare(host->dbclk); + del_timer_sync(&host->timer); + pm_runtime_put_sync(host->dev); return 0; }