Re: [Linux-stm32] [PATCH 1/1] mmc: mmci: add threaded irq to abort DPSM of non-functional state

From: Ludovic BARRE
Date: Thu Nov 28 2019 - 09:06:41 EST


hi Ulf

just a gentleman ping about this thread.

small summarize:
This patch return an IRQ_WAKE_THREAD only when the variant is
busy_timeout capable and a datatimeout occurs on R1B request.

So the threaded irq is called only to treat this specific error.
Normally, there is no impact on HW flow control or for legacy variants.

In your previous message, you seem to suggest using threaded irq to
manage HW flow control (pio mode). But Like you mention below, the mmci
legacy could timing sensitive.

For the moment, I prefer to use the threaded irq just to manage this
error. If needed, the irq threade could be extended later.

What do you think about that?

Kind regards
Ludo

Le 11/15/19 Ã 3:59 PM, Ludovic BARRE a ÃcritÂ:
hi Ulf

Le 11/14/19 Ã 4:09 PM, Ulf Hansson a ÃcritÂ:
On Wed, 13 Nov 2019 at 18:25, Ludovic Barre <ludovic.Barre@xxxxxx> wrote:

From: Ludovic Barre <ludovic.barre@xxxxxx>

If datatimeout occurs on R1B request, the Data Path State Machine stays
in busy and is non-functional. Only a reset aborts the DPSM.

Please clarify/extend this information to tell that this is for the
variant, that keeps DPSM enabled and uses the data timer while sending
a CMD12. Or something along those lines.


yes, of course.


Like a reset must be outside of critical section, this patch adds

/s/critical section/atomic context

OK, thanks


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@xxxxxx>
---
 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;
+
ÂÂÂÂÂÂÂÂ 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;
ÂÂÂÂÂÂÂÂ } 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);

In general it's a good idea to move drivers into using a threaded IRQ handler.

However, the reason this hasn't been done for mmci before, is because
there are some legacy variants, that doesn't support HW flow control.

With this patch, the mmci_irq_threaded is called only when
a datatimeout occurs on R1B request else the mmci_irq return IRQ_HANDLED
and the threaded irq is not called.
So normally, there is no impact for legacy variants.


Unless I am mistaken, that means when the fifo gets full during data
transfers - it's too late to act. In other words, running the handler
in hard IRQ context, should increase the probability of not missing
the deadline.

If a threaded IRQ handler also is sufficient for these legacy
variants, only tests can tell.

An option, would be to use a threaded handler for those variants that
supports HW flow control. Not sure how messy the code would be with
this option, perhaps you can give this a try?
For all these reasons you mentioned above, I'm not sure it's safe to extend the thread manager to anything other than "aborting the DPSM" on
R1B datatiemout ? what do you think about that?

I prefer just used the irq threaded for specific errors case which need
be outside of atomic context.



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


Kind regards
Uffe

_______________________________________________
Linux-stm32 mailing list
Linux-stm32@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
https://st-md-mailman.stormreply.com/mailman/listinfo/linux-stm32