Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5340825ybl; Tue, 10 Dec 2019 04:32:03 -0800 (PST) X-Google-Smtp-Source: APXvYqwTd31aZ0wascLBnN1+DGJp6eo/He7z2bBFRbzJppUj67WvO3NxNZuCiCc6+NAptN/oTZgq X-Received: by 2002:a05:6830:1492:: with SMTP id s18mr26137636otq.285.1575981123273; Tue, 10 Dec 2019 04:32:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575981123; cv=none; d=google.com; s=arc-20160816; b=UhKKL5l9+57M6NMsnWPG8/pSlggQBmVEMqAH9Ih/GG47KQSDVDvrWSTyNGrLRwYiHc ijwioGU1ZGFtOTf5b89XmMSo58V2BzfnZ7JAoiVWZKhGz6BP2WkU3JEvfEv6hzwNNkS8 7gnUq3svfzck56HrCfNW6YRc2Y511rQdgV5d6kkA74X1EnMXlXwYxsV7pmu7eaNhgeM0 BPEGTCISD8Gr3ptUYJSNmPss5mfzpAh5G8O6WNm6NZ/fzXWK4+IvycNYmbVdDP85xmt7 iED6ZmTUxoj0FnTB6V5qLXFNiKZarozLW3yeNeqgPhXVkGtA17ML9fSjqTjFlu5KXgTY K1TA== 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=Cu4xcLC6fx43ALyB2PH7P6iHLVvlsMlK6QGD81ONfJA=; b=B0/78ngwkVGMzxFmgmhZTKYB5TdMajfNBcGfpmRpVAPHUOH0orTuBGaLHAo8fHIqhD QgWpW+dz8erRHXSqMZd+kSSB2LFzP9d9H16fVRp6/Fc4z5eoSj/JhUQycIi6hMLCBo4V BpCWfqp1560XnQbMMQCSNSe8O0EzpTh/9KdRKqRowdJe+K4V2fFbl8dC30bj3/MVPR2Q 3u+Uo3xgmnK4q/F4qfBz2HkLngSmNCNCw+xIIyoYt1f6qy0qfKFWZGWEA+VmslKZyYMp GC2X1U1myuHxCKh0QG6Y82NYqPOmzRDylA40yKta4ltxJcegUr8f8z/4idbkTO/FrcM+ wFCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QayVJLfz; 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 5si2021099oih.274.2019.12.10.04.31.49; Tue, 10 Dec 2019 04:32:03 -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=QayVJLfz; 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 S1727333AbfLJMbT (ORCPT + 99 others); Tue, 10 Dec 2019 07:31:19 -0500 Received: from mail-ua1-f66.google.com ([209.85.222.66]:39946 "EHLO mail-ua1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727281AbfLJMbS (ORCPT ); Tue, 10 Dec 2019 07:31:18 -0500 Received: by mail-ua1-f66.google.com with SMTP id v18so2463736uaq.7 for ; Tue, 10 Dec 2019 04:31:17 -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=Cu4xcLC6fx43ALyB2PH7P6iHLVvlsMlK6QGD81ONfJA=; b=QayVJLfzwhxAFLgXNRzLMZdJ0IvLzxp4+fLYkgsafsn6S05wJNPxe1W2fAZYyUBGR8 BcCeWqYv6slEWraMiYfCcPv4pF0tfY9IyHA+7AWdiyjqH31IZzLc5y/xNthjj+0mqejq /gjucQhq10JYIm5v0/LMFDew4Ilc+OXTn08xJPNEu664cWU63FxtQ7yCvrJrZZa8xDGP W9EiAP+c5SMOv4CIfQw/j0wZDvKbWs+qtoigdrFb6GjKOwnzrUG6gxYkrj4TJEB4DeJS YgnZ+BySLGuychJ02elTMZf7LBTg/2mNw+VpOcdbROX8BTpOTFbTDzDl1jY4Q1isKofp L0Ww== 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=Cu4xcLC6fx43ALyB2PH7P6iHLVvlsMlK6QGD81ONfJA=; b=UpLf2NJd1lc96Ipp7/QUY1tBrpSt4osQZoqfhqpwigsgoHSO76NJCh3sx2NduJ9AlW cAbbPd6vv8uocE1whyiBTRQBGt3jrz4wvcVLh6zGeKWizhG9M1Guk59GDhEKkTQ7w88q EZSjesbzXizVTNcLn1BXi+KodvEGHXdQdJ5X1ZcGJClYFuOd7sL3cZIAinNYAoR7pb/o AlpUICVn/VysPbFWMTsOFmA8lae4OIeCOMlXvu7kPdCsIzRet1aV5cN1fpAvbklF8cSv qIDWjTJy4qiA00cAyDNzhcT3Sa/PDd8c0PNDlIfHyv/I3pV6qDNNrNMX8x0n3BWnu/kU Cjvg== X-Gm-Message-State: APjAAAXiY0xanlaTzk9hXEMFbs232WOkefBQdFDxsq0his0AWCukGSH6 o4rYT+u39id0eJ7B5adqVLGh/vC0Y1YIcTXuP6+Vqw== X-Received: by 2002:ab0:2759:: with SMTP id c25mr3460125uap.104.1575981077116; Tue, 10 Dec 2019 04:31:17 -0800 (PST) MIME-Version: 1.0 References: <20191113172514.19052-1-ludovic.Barre@st.com> In-Reply-To: <20191113172514.19052-1-ludovic.Barre@st.com> From: Ulf Hansson Date: Tue, 10 Dec 2019 13:30:41 +0100 Message-ID: Subject: Re: [PATCH 1/1] mmc: mmci: add threaded irq to abort DPSM of non-functional state 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 Wed, 13 Nov 2019 at 18:25, Ludovic Barre wrote: > > From: Ludovic Barre > > If datatimeout occurs on R1B request, the Data Path State Machine stays > in busy and is non-functional. Only a reset aborts the DPSM. > > Like a reset must be outside of critical section, this patch adds > threaded irq function to release state machine. In this case, > the mmc_request_done is called at the end of threaded irq and > skipped into irq handler. > > Signed-off-by: Ludovic Barre > --- > drivers/mmc/host/mmci.c | 44 ++++++++++++++++++++++++++++++++++++----- > drivers/mmc/host/mmci.h | 1 + > 2 files changed, 40 insertions(+), 5 deletions(-) > > diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c > index 40e72c30ea84..ec6e249c87ca 100644 > --- a/drivers/mmc/host/mmci.c > +++ b/drivers/mmc/host/mmci.c > @@ -556,6 +556,9 @@ static void mmci_dma_error(struct mmci_host *host) > static void > mmci_request_end(struct mmci_host *host, struct mmc_request *mrq) > { > + if (host->irq_action == IRQ_WAKE_THREAD) > + return; > + It seems a bit unnecessary to check this every time mmci_request_end() is called. How about avoiding to call mmci_request_end() for the one specific condition instead? See more below. > writel(0, host->base + MMCICOMMAND); > > BUG_ON(host->data); > @@ -1321,6 +1324,7 @@ mmci_cmd_irq(struct mmci_host *host, struct mmc_command *cmd, > } else if (host->variant->busy_timeout && busy_resp && > status & MCI_DATATIMEOUT) { > cmd->error = -ETIMEDOUT; > + host->irq_action = IRQ_WAKE_THREAD; You could check this flag a few lines below and if it's set to IRQ_WAKE_THREAD, avoid to call mmci_request_end(). > } else { > cmd->resp[0] = readl(base + MMCIRESPONSE0); > cmd->resp[1] = readl(base + MMCIRESPONSE1); > @@ -1532,9 +1536,9 @@ static irqreturn_t mmci_irq(int irq, void *dev_id) > { > struct mmci_host *host = dev_id; > u32 status; > - int ret = 0; > > spin_lock(&host->lock); > + host->irq_action = IRQ_HANDLED; > > do { > status = readl(host->base + MMCISTATUS); > @@ -1574,12 +1578,41 @@ static irqreturn_t mmci_irq(int irq, void *dev_id) > if (host->variant->busy_detect_flag) > status &= ~host->variant->busy_detect_flag; > > - ret = 1; > } while (status); > > spin_unlock(&host->lock); > > - return IRQ_RETVAL(ret); > + return host->irq_action; > +} > + > +/* > + * mmci_irq_threaded is call if the mmci host need to release state machines > + * before to terminate the request. > + * If datatimeout occurs on R1B request, the Data Path State Machine stays > + * in busy and is non-functional. Only a reset can to abort the DPSM. > + */ > +static irqreturn_t mmci_irq_threaded(int irq, void *dev_id) > +{ > + struct mmci_host *host = dev_id; > + unsigned long flags; > + > + if (host->rst) { > + reset_control_assert(host->rst); > + udelay(2); > + reset_control_deassert(host->rst); > + } > + > + spin_lock_irqsave(&host->lock, flags); > + writel(host->clk_reg, host->base + MMCICLOCK); > + writel(host->pwr_reg, host->base + MMCIPOWER); > + writel(MCI_IRQENABLE | host->variant->start_err, > + host->base + MMCIMASK0); > + > + host->irq_action = IRQ_HANDLED; > + mmci_request_end(host, host->mrq); > + spin_unlock_irqrestore(&host->lock, flags); > + > + return host->irq_action; > } > > static void mmci_request(struct mmc_host *mmc, struct mmc_request *mrq) > @@ -2071,8 +2104,9 @@ static int mmci_probe(struct amba_device *dev, > goto clk_disable; > } > > - ret = devm_request_irq(&dev->dev, dev->irq[0], mmci_irq, IRQF_SHARED, > - DRIVER_NAME " (cmd)", host); > + ret = devm_request_threaded_irq(&dev->dev, dev->irq[0], mmci_irq, > + mmci_irq_threaded, IRQF_SHARED, > + DRIVER_NAME " (cmd)", host); > if (ret) > goto clk_disable; > > diff --git a/drivers/mmc/host/mmci.h b/drivers/mmc/host/mmci.h > index 158e1231aa23..5e63c0596364 100644 > --- a/drivers/mmc/host/mmci.h > +++ b/drivers/mmc/host/mmci.h > @@ -412,6 +412,7 @@ struct mmci_host { > > struct timer_list timer; > unsigned int oldstat; > + u32 irq_action; > > /* pio stuff */ > struct sg_mapping_iter sg_miter; > -- > 2.17.1 > Otherwise this looks good, besides my other earlier comments, of course. Kind regards Uffe