Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp6205530imd; Wed, 31 Oct 2018 08:18:43 -0700 (PDT) X-Google-Smtp-Source: AJdET5damX5R7PgLJcWyhxTBPeFBF9mMRGog6hKeRxfvB+nIS/E84o8xTDA1u99hbipwmAzZLSaL X-Received: by 2002:a17:902:f203:: with SMTP id gn3mr3664419plb.93.1540999123365; Wed, 31 Oct 2018 08:18:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540999123; cv=none; d=google.com; s=arc-20160816; b=OZfXzej/0Scn0kQkaPIPVceoN/LotRAovBxD9lq5b5MoqEfLDyG9pH4UtbixwSZ9Z6 wF1OaFMUmlXLKNjnaPg9UwLgdPphN00s+FjzQLJgJEFm/AXPTMpz8pDVII3YgTwo5ED5 XKQxlLnVx2AI6q/oAjXs/WingM/jInfNCFroZLkBYXV4rvVl/Pkb84QwwqNbxFtIHFb3 6RCPqelmbWmNeMGkV5VDSFCUR4Kz66ax4DLb5kvB6pJNW4WhwGUmQwSdBqXrCloOfmrX eo+FpBYqqFCx2RMv6RbRbNV3O9Id1yIBZBDn4Gb2wZonUnAmPfaoYE3/GTgh2T4i6WF4 Ic6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=EvCmC7UDDiojjF1KUdL7ZPFkIHjxz1xIoQxXLCp0G78=; b=v65Yg3Lra5SJIrwAHALnFCYWHmUT/NJ9mN3OL8Yc7UVQigbplu3S2sr5v8mBlFSdE3 TBBcD7V/aOZ8Tsxfd3TZqXPtC5fTSKm6Bleg5FoxAYP0tiYHos9rOf0K+e2fIkvPSdYx USDxzbavpbddejTVy9CbkwXKfN90xnzdrZHdhCO24jnMpcOOLQv+llpKBje0SO7sQRXz HG0mkXFiL5Df2ckknvH3b+NjbXSjprQs/V6VsoExzfxOlOn9O64nCOrmtiRppYsAjYvi CbLASgXdwQ9911oES8uUHdrXzpzsO9kSZJebZOxJISybURG1q5Tjt7Y86CtS7rTjgcrQ PKPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Wv5s07+B; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z32-v6si18226945pgk.507.2018.10.31.08.18.14; Wed, 31 Oct 2018 08:18:43 -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=@linaro.org header.s=google header.b=Wv5s07+B; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729272AbeKAAPg (ORCPT + 99 others); Wed, 31 Oct 2018 20:15:36 -0400 Received: from mail-it1-f195.google.com ([209.85.166.195]:52884 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726070AbeKAAPg (ORCPT ); Wed, 31 Oct 2018 20:15:36 -0400 Received: by mail-it1-f195.google.com with SMTP id r5-v6so16775292ith.2 for ; Wed, 31 Oct 2018 08:17:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=EvCmC7UDDiojjF1KUdL7ZPFkIHjxz1xIoQxXLCp0G78=; b=Wv5s07+BUn7ilIy+AElsqoAm7xPBIXETRmwHZKHKJ0EYCDuH+ILVCcLogcPnM1zlQj I9Dx00OoJ32Fq51vX9fOBcUCEfXXWxA4WDMgsARtqYAAT1KfTU9FonjxvJDYpB3/x+18 xh0jInBKsu0sahAIEc+s9V/UGRj78MuM4u41A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=EvCmC7UDDiojjF1KUdL7ZPFkIHjxz1xIoQxXLCp0G78=; b=Ng99eRa9Cew9GPSLWN5RDnoxl75tvryr0fvPLkpcTgFUYN+qCSXImbvm+lMmvAA6G+ OF5FGfwWsSEUfHHL5mmWHqPRVtpkJ3kcayd+jZ2xfxzqG/1KdbWbULCodr2rkBNzpVX2 Iwu9LP7d7qkv5rJwtrMLbcEzzlZM1xqU41ieWiqXMmUQTXEYXLdLckLaOHUVa10ug3jE Q6yJYX7L5S2zYXkhfDATnL8OMl3FpPTEzzbqTSF68hyDiuX9qmqjQJhd4S3K7l0vTSco +//LfTWBYqXIzlu1Mk9ERXPYbPVFxmw368FbIsqB1YTS/AnsPjHuV0nQV1OSl2fGZAJI 26Qw== X-Gm-Message-State: AGRZ1gInPUD0ZBQUJIJ4FImnjyQFoikP4+RV8uVKxlXuDKmlNj/4FTtC MlhLn5aQI3Rq9BLiJGvnQ6+j0RMlRY8MZkEcPhCmpg== X-Received: by 2002:a24:47c5:: with SMTP id t188-v6mr2331948itb.78.1540999029494; Wed, 31 Oct 2018 08:17:09 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a02:38d:0:0:0:0:0 with HTTP; Wed, 31 Oct 2018 08:16:28 -0700 (PDT) In-Reply-To: <1540894589-4004-1-git-send-email-ludovic.Barre@st.com> References: <1540894589-4004-1-git-send-email-ludovic.Barre@st.com> From: Ulf Hansson Date: Wed, 31 Oct 2018 16:16:28 +0100 Message-ID: Subject: Re: [PATCH] mmc: mmci: add variant property to send stop cmd if a command fail To: Ludovic Barre Cc: Rob Herring , Srinivas Kandagatla , Maxime Coquelin , Alexandre Torgue , Linux ARM , Linux Kernel Mailing List , DTML , "linux-mmc@vger.kernel.org" , linux-stm32@st-md-mailman.stormreply.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 30 October 2018 at 11:16, Ludovic Barre wrote: > From: Ludovic Barre > > The mmc framework follows the requirement of SD_Specification: > the STOP_TRANSMISSION is sent on multiple write/read commands > and the stop command (alone), not needed on other ADTC commands. Well, there is a bit more to it than that. Host drivers may set MMC_CAP_CMD23 support, which means pre-defined multi-block transfers, becomes preferable to open-ended ones. However, even for pre-defined transfers, a CM12 (stop transmission) should be sent, in case of data transfer errors. At least if I understand the specs correctly. By looking at the code in mmci_data_irq(), I realize that it's not considering this case - so I think that need to be fixed as to start with. > > But, if an error happens on command or data step, some variants > require a stop command "STOP_TRANSMISION" to clear the DPSM > "Data Path State Machine". If it's not done the next data > command freezes hardware block. > Needed to support the STM32 sdmmc variant. I don't really follow this, sorry. Could you start by clarifying what you mean by "data step", according to the above? As far as I understand, you need to send a CMD12 to clear the DPSM, in case of any errors happening during a data transfer (which includes ADTC commands as well), right? Or is there anything else to it? Kind regards Uffe > > Signed-off-by: Ludovic Barre > --- > drivers/mmc/host/mmci.c | 33 +++++++++++++++++++++++++++++++++ > drivers/mmc/host/mmci.h | 4 ++++ > 2 files changed, 37 insertions(+) > > diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c > index 19650ed..ecedca3 100644 > --- a/drivers/mmc/host/mmci.c > +++ b/drivers/mmc/host/mmci.c > @@ -21,6 +21,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -57,6 +58,8 @@ void sdmmc_variant_init(struct mmci_host *host); > #else > static inline void sdmmc_variant_init(struct mmci_host *host) {} > #endif > +static void > +mmci_start_command(struct mmci_host *host, struct mmc_command *cmd, u32 c); > > static unsigned int fmax = 515633; > > @@ -274,6 +277,7 @@ static struct variant_data variant_stm32_sdmmc = { > .cmdreg_lrsp_crc = MCI_CPSM_STM32_LRSP_CRC, > .cmdreg_srsp_crc = MCI_CPSM_STM32_SRSP_CRC, > .cmdreg_srsp = MCI_CPSM_STM32_SRSP, > + .cmdreg_stop = MCI_CPSM_STM32_CMDSTOP, > .data_cmd_enable = MCI_CPSM_STM32_CMDTRANS, > .irq_pio_mask = MCI_IRQ_PIO_STM32_MASK, > .datactrl_first = true, > @@ -574,6 +578,24 @@ void mmci_dma_error(struct mmci_host *host) > static void > mmci_request_end(struct mmci_host *host, struct mmc_request *mrq) > { > + /* > + * If an error happens on command or data step, some variants > + * require a stop command to reinit the DPSM. > + * If it's not done the next data command freeze hardware block. > + */ > + if (host->variant->cmdreg_stop) { > + u32 dpsm; > + > + dpsm = readl_relaxed(host->base + MMCISTATUS); > + dpsm &= MCI_STM32_DPSMACTIVE; > + > + if (dpsm && ((mrq->cmd && mrq->cmd->error) || > + (mrq->data && mrq->data->error))) { > + mmci_start_command(host, &host->stop_abort, 0); > + return; > + } > + } > + > writel(0, host->base + MMCICOMMAND); > > BUG_ON(host->data); > @@ -1106,6 +1128,10 @@ mmci_start_command(struct mmci_host *host, struct mmc_command *cmd, u32 c) > mmci_reg_delay(host); > } > > + if (host->variant->cmdreg_stop && > + cmd->opcode == MMC_STOP_TRANSMISSION) > + c |= host->variant->cmdreg_stop; > + > c |= cmd->opcode | host->variant->cmdreg_cpsm_enable; > if (cmd->flags & MMC_RSP_PRESENT) { > if (cmd->flags & MMC_RSP_136) > @@ -1957,6 +1983,13 @@ static int mmci_probe(struct amba_device *dev, > mmc->max_busy_timeout = 0; > } > > + /* prepare the stop command, used to abort and reinitialized the DPSM */ > + if (variant->cmdreg_stop) { > + host->stop_abort.opcode = MMC_STOP_TRANSMISSION; > + host->stop_abort.arg = 0; > + host->stop_abort.flags = MMC_RSP_R1B | MMC_CMD_AC; > + } > + > mmc->ops = &mmci_ops; > > /* We support these PM capabilities. */ > diff --git a/drivers/mmc/host/mmci.h b/drivers/mmc/host/mmci.h > index ec13d90..afb6ec4 100644 > --- a/drivers/mmc/host/mmci.h > +++ b/drivers/mmc/host/mmci.h > @@ -166,6 +166,7 @@ > #define MCI_ST_CEATAEND (1 << 23) > #define MCI_ST_CARDBUSY (1 << 24) > /* Extended status bits for the STM32 variants */ > +#define MCI_STM32_DPSMACTIVE BIT(12) > #define MCI_STM32_BUSYD0 BIT(20) > > #define MMCICLEAR 0x038 > @@ -269,6 +270,7 @@ struct mmci_host; > * @cmdreg_lrsp_crc: enable value for long response with crc > * @cmdreg_srsp_crc: enable value for short response with crc > * @cmdreg_srsp: enable value for short response without crc > + * @cmdreg_stop: enable value for stop and abort transmission > * @datalength_bits: number of bits in the MMCIDATALENGTH register > * @fifosize: number of bytes that can be written when MMCI_TXFIFOEMPTY > * is asserted (likewise for RX) > @@ -322,6 +324,7 @@ struct variant_data { > unsigned int cmdreg_lrsp_crc; > unsigned int cmdreg_srsp_crc; > unsigned int cmdreg_srsp; > + unsigned int cmdreg_stop; > unsigned int datalength_bits; > unsigned int fifosize; > unsigned int fifohalfsize; > @@ -384,6 +387,7 @@ struct mmci_host { > void __iomem *base; > struct mmc_request *mrq; > struct mmc_command *cmd; > + struct mmc_command stop_abort; > struct mmc_data *data; > struct mmc_host *mmc; > struct clk *clk; > -- > 2.7.4 >