Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4726538imu; Tue, 29 Jan 2019 06:33:25 -0800 (PST) X-Google-Smtp-Source: ALg8bN5hD2C0nF8kngqh3DgChTAggAEHOnqafixvXA+4omi16wTr2X+2GIK5gF6T5Rwpqcs9H1Ub X-Received: by 2002:a65:4683:: with SMTP id h3mr22905667pgr.225.1548772405408; Tue, 29 Jan 2019 06:33:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548772405; cv=none; d=google.com; s=arc-20160816; b=o/mxs7+I8eoQxYCUwNUqpzehLrm8kiBvPzLcRJuY1qrhH0fIPv0zXoL/hVlyesGuNF DPGBmlWiAmBynZDupt2Cjh+hbw6MM9nF9VlGM4o5v0/emWwjsUCtqYtKuJheiLsS/Ymi T72/tKXBX+dc/gEAjHgU046nE9NVbniV6oGWnEb1UquNgFNxlQMs7NlviIOOSGKp7hPs PnNBtymm2L7fnukPz2tRCV5tjE+xAOwMdG/e+oAa3l950XNaqEZNe2ReTE9n2h/r6QB7 mIIV9VUmtk7/OtC0tLp1ajPl0T4MNh7cKJukNaza4IJkiEOeTEPh/ktGMkmXcPBgyIXt EviQ== 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 :in-reply-to:references:mime-version:dkim-signature; bh=SZM6OVgxv/IBmtJypwoYcCJZu0u9rAyQfSsjwtcLSkM=; b=DU4vTeydA4a8Dv8BwYLrZE7bxjXwbQeybfvaJNSf6/ke0zurNibW67XOz4NLdoOIRK 2DcKIfoEKfSVAUiSVdA/qHbJ2/me2TAVQ+5DJWEPE0K97U2+b6s0RoCh5T65vL5j/3R9 7jocFfBl2uKqb2yLmP6iyKfMbScdAGzSrw4AhxGHLa1WvqmypvtP8we03hvd3vsi4pLC otZXHzTEgNXwA5l6FdLbX/rJzDTR3lEyjoT761l5TuGQnDgjsPUvtJf9vzSclNUoHJhF RfczLXkWrMeQAJUIVgmxEerMl0J4333wToBu7JOZWgLcrvnWHV97LD1eshSeQUK1tV8/ i0tA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dGLdF5bX; 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 m2si35641974pgs.96.2019.01.29.06.33.00; Tue, 29 Jan 2019 06:33:25 -0800 (PST) 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=dGLdF5bX; 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 S1727673AbfA2Obv (ORCPT + 99 others); Tue, 29 Jan 2019 09:31:51 -0500 Received: from mail-vs1-f65.google.com ([209.85.217.65]:44263 "EHLO mail-vs1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726997AbfA2Obv (ORCPT ); Tue, 29 Jan 2019 09:31:51 -0500 Received: by mail-vs1-f65.google.com with SMTP id u11so12029785vsp.11 for ; Tue, 29 Jan 2019 06:31:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=SZM6OVgxv/IBmtJypwoYcCJZu0u9rAyQfSsjwtcLSkM=; b=dGLdF5bXTIm9Lr3os3sri+AADTTshoVLNLq3wu64hl7s5JVkNOxDHFNh/v1+O7/BOE e1xI/A4xH4KP/wGAbJalszKC2cmfAgIVFOc2YzBfK7MBygoGDTD5nmJVRgX0qxjtyurf 0NNnBB6Wq5LyvrJ6EgDr25Sx0NO10Xc0Mto6k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SZM6OVgxv/IBmtJypwoYcCJZu0u9rAyQfSsjwtcLSkM=; b=sHBZA2yEDqdOTAAzb82Yir8s9tyTZ8JYH2ZYvEO59IoXOMw6eEue3pC4GSj0HKDj6e yKFKGdEXh6n3+p2u0ULDgvGCBuKdQ4bSroIAF27w5txOALVosLN/uNYNvwJGXHJ982Ps BUaCiai9P03qaeCBjo2yO8cmvWylVPtMjuvLMrVgAGnCEX7e+Bx/rugBkfnTLxAOrx91 DfHtEpsTo7CgCmgnrh2aagsmVFXmdheiru6N6FqoSTPlQCcwwz41Kj8cAw4aIJTMGYFa Rj1dxheW4PMvxMGXEXKTfqfqp/TMcOLbQ9XWTJLuBG7RCbmSSZdpX8aV8jUTncW6cqin tD9w== X-Gm-Message-State: AJcUukfSM1BNtTmapxYX+UCRMr7Ib2JcVnWBAN1D8AysR8QsAEwFw34r QQh7oN9VON/TFZGRu3fNf0KSpkG0CJ8sy6sedjilqp02 X-Received: by 2002:a67:b245:: with SMTP id s5mr10779714vsh.200.1548772309791; Tue, 29 Jan 2019 06:31:49 -0800 (PST) MIME-Version: 1.0 References: <1544109212-12621-1-git-send-email-ludovic.Barre@st.com> <1544109212-12621-3-git-send-email-ludovic.Barre@st.com> In-Reply-To: <1544109212-12621-3-git-send-email-ludovic.Barre@st.com> From: Ulf Hansson Date: Tue, 29 Jan 2019 15:31:12 +0100 Message-ID: Subject: Re: [PATCH V3 2/2] mmc: mmci: send stop command to clear the dpsm 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 Thu, 6 Dec 2018 at 16:13, Ludovic Barre wrote: > > From: Ludovic Barre > > The current approach with sending a CMD12 (STOP_TRANSMISSION) to > complete a data transfer request, either because of using the open > ended transmission type or because of receiving an error during a data > transfer, isn't sufficient for the STM32 sdmmc variant. > > More precisely, for STM32 sdmmc the DPSM ("Data Path State Machine") > needs to be cleared by sending a CMD12, also for the so called ADTC > commands. For this reason, let the driver send a CMD12 to complete > ADTC commands, in case it's set (depend of cmdreg_stop variant property). > > Signed-off-by: Ludovic Barre > --- > drivers/mmc/host/mmci.c | 37 +++++++++++++++++++++++++++++++++++++ > drivers/mmc/host/mmci.h | 2 ++ > 2 files changed, 39 insertions(+) > > diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c > index e352f5a..4e5643d 100644 > --- a/drivers/mmc/host/mmci.c > +++ b/drivers/mmc/host/mmci.c > @@ -58,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; > > @@ -572,9 +574,37 @@ void mmci_dma_error(struct mmci_host *host) > host->ops->dma_error(host); > } > > +static int mmci_stop_command(struct mmci_host *host, struct mmc_request *mrq) > +{ > + u32 dpsm; > + > + /* > + * If an error happens on command or data transmission > + * the DPSM stay enabled. The CPSM required a stop command > + * to reinitialize the 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 -EBUSY; > + } Unless I have got it wrong, I think there are several problems with the above code and how you call it. 1) We may be reading the MMCISTATUS register when we don't need to (because there are no errors). 2) Nothing prevents keep sending the CMD12 over and over again, for the same request. This could happen, as long as the MCI_STM32_DPSMACTIVE remains set. I guess it simply shouldn't happen, but I rather prevent this being possible altogether, as to avoid a potential hang. It's better to propagate errors. 3) There is a scenario when the DPSM has been enabled, while we fail with the "sbc" command, this isn't covered, but I think should, right? 4) host->stop_abort.error needs to be reset to zero, in-between sending the internal CMD12 command. Otherwise, we may end up re-using an error code from a failed CMD12 command, over and over again. > + > + return 0; > +} > + > static void > mmci_request_end(struct mmci_host *host, struct mmc_request *mrq) > { > + /* > + * For variant with cmdstop bit, a stop command could be needed > + * to finish the request. > + */ > + if (host->variant->cmdreg_stop && mmci_stop_command(host, mrq)) > + return; > + > writel(0, host->base + MMCICOMMAND); > > BUG_ON(host->data); > @@ -1956,6 +1986,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 2422909..35372cd 100644 > --- a/drivers/mmc/host/mmci.h > +++ b/drivers/mmc/host/mmci.h > @@ -161,6 +161,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 > @@ -377,6 +378,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 > To fix the issues I pointed out above, I decided to try out something myself. So, I will post a patch in a few minutes, can you please give it try at your end? Kind regards Uffe