Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2551708ybh; Mon, 5 Aug 2019 02:58:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqzptGJGHrwWFLy5hqXLQH79vgCwziXNPcCqEericv/FIj/thbL/UfzQ3IK4GZuN6MThVpG+ X-Received: by 2002:a62:1456:: with SMTP id 83mr72591273pfu.228.1564999087398; Mon, 05 Aug 2019 02:58:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564999087; cv=none; d=google.com; s=arc-20160816; b=OZxxGmBBm3Q86PYC2RC8DrZ2+NVdMvNLyxvb2zsWWbqpw/8mGu75xBDfM9LQBJRHc5 ZnKA4ULnRXw4Hp/zF/r0Xbi7VNrsskySdQ9rS82uI4YTpZ8blvoNJD9bj8244qDd2aT+ BvCUZm9Cwrjl9T0wiWU4ITZNKjJG8fVgyHeYFkXTrpBrhRVg3dA00SJNHPeq9tIwnaIg GUVddGNYD3L8yAdbhIJk70vuIHGmxDEt0i0Q+FhX0+o9P8sJ7qdKj2wXKcqhUeC2YoXQ X8pX26ca9B2zkM8vkSlONxeuZPp58MYqPT9SedL1jr9dW00Mdw8PoMFAwYK4l95H18Od 2ttg== 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; bh=wuSEYQ/MVeznlvXAHY047ivvLEOAFrfYgBPlSUOUncM=; b=H0g9pVTgp/f0IUK4cjLeZiqLePg3cQflHQtEH+O7iFUSAb81y7JNwteWAlxdMvbHCP EMgkQFUepIlHbODxPQLLn1XqMrodz9gLGqx8vMBk4qzC87vq7a7B9BTc71Er2w6V4mpE hmgMEtiVs1r0e8dZWLp08vuhLCXGHR/2lCEjDSZZ2xVH6Egj5G1qjhAUok307tInp/7L mYi8gtxpTuTC03XeVn5ey7umqVne3i9w3lFDD7NFwGS6GBsmaffJwQXD8qqgL9rEO2oE O5LbLd3nWTi/eiUO9wHPJKaPMw6YilzEAPrjOamDBjn4N20f31jLcUHW5RCbbaNZ9k0q pV6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=ZRBcDBjI; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h69si44784618pge.543.2019.08.05.02.57.51; Mon, 05 Aug 2019 02:58:07 -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=@st.com header.s=STMicroelectronics header.b=ZRBcDBjI; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728279AbfHEJ5L (ORCPT + 99 others); Mon, 5 Aug 2019 05:57:11 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:32866 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728231AbfHEJ5K (ORCPT ); Mon, 5 Aug 2019 05:57:10 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x758asfg025755; Mon, 5 Aug 2019 11:57:00 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=wuSEYQ/MVeznlvXAHY047ivvLEOAFrfYgBPlSUOUncM=; b=ZRBcDBjIaGGzGjohNTqHqzM/OUpHtM0lRm08NzQKbw6+2MLPHNjhtXags1ddVKLqEL8+ x40xlsCPSN1gU9Ew5+3NKTtdlYQ+iwmpb35YkRdgxWy8o5B8ijABbh3PwuET4RwumaPT RzDRVpZbJIS5K8ti/OFW1D3Bwwjw9u2MMgY493MMGDG9rtaVUGtU6bYE92IMCfP0kv1v YxAx48ki7Pa4r0PTNfv2QpQWoD2zz0qKoWHAvv7rHF+UR3BQLolmMlZZAQj5IhqqEFC4 7luvxL/9CkJ4yhmJva+y0XhhIdCBFoZUeI9x8ArtQlH9AGnF6fTjsXAebaFwia4zxrV2 IQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2u515mamub-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 05 Aug 2019 11:57:00 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id C4F2C41; Mon, 5 Aug 2019 09:56:59 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas22.st.com [10.75.90.92]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id B65AD3023C2; Mon, 5 Aug 2019 11:56:59 +0200 (CEST) Received: from SAFEX1HUBCAS23.st.com (10.75.90.47) by Safex1hubcas22.st.com (10.75.90.92) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 5 Aug 2019 11:56:59 +0200 Received: from lmecxl0923.lme.st.com (10.48.0.237) by webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 5 Aug 2019 11:56:59 +0200 From: Ludovic Barre To: Ulf Hansson , Rob Herring CC: , Maxime Coquelin , Alexandre Torgue , , , , , , Ludovic Barre Subject: [PATCH V4 1/3] mmc: mmci: add hardware busy timeout feature Date: Mon, 5 Aug 2019 11:56:24 +0200 Message-ID: <20190805095626.25998-2-ludovic.Barre@st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190805095626.25998-1-ludovic.Barre@st.com> References: <20190805095626.25998-1-ludovic.Barre@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.48.0.237] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-08-05_04:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ludovic Barre In some variants, the data timer starts and decrements when the DPSM enters in Wait_R or Busy state (while data transfer or MMC_RSP_BUSY), and generates a data timeout error if the counter reach 0. -Define max_busy_timeout (in ms) according to clock. -Set data timer register if the command has rsp_busy flag. If busy_timeout is not defined by framework, the busy length after Data Burst is defined as 1 second (refer: 4.6.2.2 Write of sd specification part1 v6-0). -Add MCI_DATATIMEOUT error management in mmci_cmd_irq. Signed-off-by: Ludovic Barre --- drivers/mmc/host/mmci.c | 37 ++++++++++++++++++++++++++++++++----- drivers/mmc/host/mmci.h | 3 +++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 4c35e7609c89..e79c9148af84 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -1078,6 +1078,7 @@ static void mmci_start_command(struct mmci_host *host, struct mmc_command *cmd, u32 c) { void __iomem *base = host->base; + unsigned long long clks = 0; dev_dbg(mmc_dev(host->mmc), "op %02x arg %08x flags %08x\n", cmd->opcode, cmd->arg, cmd->flags); @@ -1100,6 +1101,19 @@ mmci_start_command(struct mmci_host *host, struct mmc_command *cmd, u32 c) else c |= host->variant->cmdreg_srsp; } + + if (host->variant->busy_timeout && !cmd->data) { + if (cmd->flags & MMC_RSP_BUSY) { + if (!cmd->busy_timeout) + cmd->busy_timeout = 1000; + + clks = (unsigned long long)cmd->busy_timeout; + clks *= host->cclk; + do_div(clks, MSEC_PER_SEC); + } + writel_relaxed(clks, host->base + MMCIDATATIMER); + } + if (/*interrupt*/0) c |= MCI_CPSM_INTERRUPT; @@ -1206,6 +1220,7 @@ mmci_cmd_irq(struct mmci_host *host, struct mmc_command *cmd, { void __iomem *base = host->base; bool sbc, busy_resp; + u32 err_msk; if (!cmd) return; @@ -1218,8 +1233,12 @@ mmci_cmd_irq(struct mmci_host *host, struct mmc_command *cmd, * handling. Note that we tag on any latent IRQs postponed * due to waiting for busy status. */ - if (!((status|host->busy_status) & - (MCI_CMDCRCFAIL|MCI_CMDTIMEOUT|MCI_CMDSENT|MCI_CMDRESPEND))) + err_msk = MCI_CMDCRCFAIL | MCI_CMDTIMEOUT; + if (host->variant->busy_timeout && busy_resp) + err_msk |= MCI_DATATIMEOUT; + + if (!((status | host->busy_status) & + (err_msk | MCI_CMDSENT | MCI_CMDRESPEND))) return; /* Handle busy detection on DAT0 if the variant supports it. */ @@ -1238,8 +1257,7 @@ mmci_cmd_irq(struct mmci_host *host, struct mmc_command *cmd, * while, to allow it to be set, but tests indicates that it * isn't needed. */ - if (!host->busy_status && - !(status & (MCI_CMDCRCFAIL|MCI_CMDTIMEOUT)) && + if (!host->busy_status && !(status & err_msk) && (readl(base + MMCISTATUS) & host->variant->busy_detect_flag)) { writel(readl(base + MMCIMASK0) | @@ -1293,6 +1311,9 @@ mmci_cmd_irq(struct mmci_host *host, struct mmc_command *cmd, cmd->error = -ETIMEDOUT; } else if (status & MCI_CMDCRCFAIL && cmd->flags & MMC_RSP_CRC) { cmd->error = -EILSEQ; + } else if (host->variant->busy_timeout && busy_resp && + status & MCI_DATATIMEOUT) { + cmd->error = -ETIMEDOUT; } else { cmd->resp[0] = readl(base + MMCIRESPONSE0); cmd->resp[1] = readl(base + MMCIRESPONSE1); @@ -1951,6 +1972,8 @@ static int mmci_probe(struct amba_device *dev, * Enable busy detection. */ if (variant->busy_detect) { + u32 max_busy_timeout = 0; + mmci_ops.card_busy = mmci_card_busy; /* * Not all variants have a flag to enable busy detection @@ -1960,7 +1983,11 @@ static int mmci_probe(struct amba_device *dev, mmci_write_datactrlreg(host, host->variant->busy_dpsm_flag); mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY; - mmc->max_busy_timeout = 0; + + if (variant->busy_timeout) + max_busy_timeout = ~0UL / (mmc->f_max / MSEC_PER_SEC); + + mmc->max_busy_timeout = max_busy_timeout; } /* Prepare a CMD12 - needed to clear the DPSM on some variants. */ diff --git a/drivers/mmc/host/mmci.h b/drivers/mmc/host/mmci.h index 4f071bd34e59..8f86130af566 100644 --- a/drivers/mmc/host/mmci.h +++ b/drivers/mmc/host/mmci.h @@ -290,6 +290,8 @@ struct mmci_host; * @signal_direction: input/out direction of bus signals can be indicated * @pwrreg_clkgate: MMCIPOWER register must be used to gate the clock * @busy_detect: true if the variant supports busy detection on DAT0. + * @busy_timeout: true if the variant starts data timer when the DPSM + * enter in Wait_R or Busy state. * @busy_dpsm_flag: bitmask enabling busy detection in the DPSM * @busy_detect_flag: bitmask identifying the bit in the MMCISTATUS register * indicating that the card is busy @@ -336,6 +338,7 @@ struct variant_data { u8 signal_direction:1; u8 pwrreg_clkgate:1; u8 busy_detect:1; + u8 busy_timeout:1; u32 busy_dpsm_flag; u32 busy_detect_flag; u32 busy_detect_mask; -- 2.17.1