linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ludovic BARRE <ludovic.barre@st.com>
To: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Rob Herring <robh+dt@kernel.org>,
	Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@st.com>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	DTML <devicetree@vger.kernel.org>,
	"linux-mmc@vger.kernel.org" <linux-mmc@vger.kernel.org>,
	<linux-stm32@st-md-mailman.stormreply.com>
Subject: Re: [PATCH 1/1] mmc: mmci: add threaded irq to abort DPSM of non-functional state
Date: Tue, 10 Dec 2019 15:03:14 +0100	[thread overview]
Message-ID: <2e5639cd-0dea-8cc1-d1aa-721025d66bac@st.com> (raw)
In-Reply-To: <CAPDyKFrZxOCkw9U05UZPRSGz2CqmhOq944z8MEVox8Y_UEYC4A@mail.gmail.com>

hi Ulf

Le 12/10/19 à 1:30 PM, Ulf Hansson a écrit :
> On Wed, 13 Nov 2019 at 18:25, Ludovic Barre <ludovic.Barre@st.com> wrote:
>>
>> From: Ludovic Barre <ludovic.barre@st.com>
>>
>> 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 <ludovic.barre@st.com>
>> ---
>>   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().

yes, it was my first implementation. after, I wanted to centralize this,
if the irq threaded would be extend.
But you are right, it's not the goal of this commit.

I resend a v2

> 
>>          } 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
> 

      reply	other threads:[~2019-12-10 14:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-13 17:25 [PATCH 1/1] mmc: mmci: add threaded irq to abort DPSM of non-functional state Ludovic Barre
2019-11-14 15:09 ` Ulf Hansson
2019-11-15 14:59   ` Ludovic BARRE
2019-11-28 14:06     ` [Linux-stm32] " Ludovic BARRE
2019-12-10 12:20       ` Ulf Hansson
2019-12-10 12:30 ` Ulf Hansson
2019-12-10 14:03   ` Ludovic BARRE [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2e5639cd-0dea-8cc1-d1aa-721025d66bac@st.com \
    --to=ludovic.barre@st.com \
    --cc=alexandre.torgue@st.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=robh+dt@kernel.org \
    --cc=srinivas.kandagatla@linaro.org \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).