Skip to contentSkip to conversation

mmc: dw_mmc: avoid long timeout if register invalid

PATCH Superseded Christian Löhle 3 participants 7 messages Sep 17, 2021 – Oct 1, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: dw_mmc: avoid long timeout if register invalid

Set the limit to 1s if the register is at reset value.

---
 drivers/mmc/host/dw_mmc.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/mmc/host/dw_mmc.c +8 -0
index 6578cc64ae9e..cd9a6e0a7449 100644
@@ -1983,6 +1983,14 @@ static void dw_mci_set_drto(struct dw_mci *host)
 	/* add a bit spare time */
 	drto_ms += 10;
 
+	/*
+	 * If TMOUT register still holds the reset value the above calculation
+	 * would yield a timeout of over 167 seconds, limit it to 1000ms.
+	 * Normal reads/writes should not take anywhere close to 120s.
+	 */
+	if (drto_ms > 120000)
+		drto_ms = 1000;
+
 	spin_lock_irqsave(&host->irq_lock, irqflags);
 	if (!test_bit(EVENT_DATA_COMPLETE, &host->pending_events))
 		mod_timer(&host->dto_timer,
Signature · 4 lines
2.32.0
Hyperstone GmbH | Line-Eid-Strasse 3 | 78467 Konstanz
Managing Directors: Dr. Jan Peter Berns.
Commercial register of local courts: Freiburg HRB381782
#1 lore raw
Quoted 1 line · Christian Löhle

Set the limit to 1s if the register is at reset value.

One second could be to short, we have seen some cards take up to 10s on write operations. Although that was quite a few years ago.

TMOUT is only used for reads if I understand correctly, so it should be ok anyways.

/Jesper

Quoted 29 lines
---
 drivers/mmc/host/dw_mmc.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/mmc/host/dw_mmc.c +8 -0
index 6578cc64ae9e..cd9a6e0a7449 100644
@@ -1983,6 +1983,14 @@ static void dw_mci_set_drto(struct dw_mci *host)
 	/* add a bit spare time */
 	drto_ms += 10;
 
+	/*
+	 * If TMOUT register still holds the reset value the above calculation
+	 * would yield a timeout of over 167 seconds, limit it to 1000ms.
+	 * Normal reads/writes should not take anywhere close to 120s.
+	 */
+	if (drto_ms > 120000)
+		drto_ms = 1000;
+
 	spin_lock_irqsave(&host->irq_lock, irqflags);
 	if (!test_bit(EVENT_DATA_COMPLETE, &host->pending_events))
 		mod_timer(&host->dto_timer,
Signature · 4 lines
2.32.0
Hyperstone GmbH | Line-Eid-Strasse 3 | 78467 Konstanz
Managing Directors: Dr. Jan Peter Berns.
Commercial register of local courts: Freiburg HRB381782

/^JN - Jesper Nilsson

Signature · 1 line
               Jesper Nilsson -- [email protected]
#2 lore raw

From: Jesper Nilsson <[email protected]>
Sent: Friday, September 17, 2021 3:41 PM
To: Christian Löhle
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] mmc: dw_mmc: avoid long timeout if register invalid

Quoted 7 lines

One second could be to short, we have seen some cards take up to 10s on write operations. Although that was quite a few years ago.

TMOUT is only used for reads if I understand correctly, so it should be ok anyways.

/Jesper

Yes, apart from it only affecting reads, the calculated timeout is only that high if the register still holds the reset value. I've only seen and would expect this for initialization 'read' commands, like ACMD13, or ACMD51.
I have chosen 1s to hit an expectation that I would consider normal, that a card is initialized in a couple of seconds after plugging in, or never.

Regards,
Christian=
Hyperstone GmbH | Line-Eid-Strasse 3 | 78467 Konstanz Managing Directors: Dr. Jan Peter Berns. Commercial register of local courts: Freiburg HRB381782

maintainer
#3 lore raw
In reply to Christian Löhle

Hi,

Quoted 14 lines · Christian Löhle

Set the limit to 1s if the register is at reset value.

---
 drivers/mmc/host/dw_mmc.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/mmc/host/dw_mmc.c +0 -0
index 6578cc64ae9e..cd9a6e0a7449 100644
@@ -1983,6 +1983,14 @@ static void dw_mci_set_drto(struct dw_mci *host)
 	/* add a bit spare time */

drivers/mmc/host/dw_mmc.c static void dw_mci_set_drto(struct dw_mci *host) · line 1993

Quoted 10 lines
drivers/mmc/host/dw_mmc.c +8 -0
 	drto_ms += 10;
 
+	/*
+	 * If TMOUT register still holds the reset value the above calculation
+	 * would yield a timeout of over 167 seconds, limit it to 1000ms.
+	 * Normal reads/writes should not take anywhere close to 120s.
+	 */
+	if (drto_ms > 120000)
+		drto_ms = 1000;
+

If dtrt_ms is 167sec, it means that bus_hz should be 0 or 1. What value is your host->bus_hz?

Best Regards,
Jaehoon Chung

Quoted 4 lines
drivers/mmc/host/dw_mmc.c +0 -0
 	spin_lock_irqsave(&host->irq_lock, irqflags);
 	if (!test_bit(EVENT_DATA_COMPLETE, &host->pending_events))
 		mod_timer(&host->dto_timer,
#4 lore raw

Hey,
so more generally the timeout here can be 41954 up to 167783 ms.
Is 42s too low to view it as invalid here?
Would you prefer the patch exluding the specific timeout values instead of anything above 41954?

Regards,
Christian

From: Jaehoon Chung <[email protected]>
Sent: Friday, September 24, 2021 11:49 AM
To: Christian Löhle; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] mmc: dw_mmc: avoid long timeout if register invalid
Hi,

Quoted 16 lines · Christian Löhle

Set the limit to 1s if the register is at reset value.

---
  drivers/mmc/host/dw_mmc.c | 8 ++++++++

  1 file changed, 8 insertions(+)
drivers/mmc/host/dw_mmc.c +0 -0
index 6578cc64ae9e..cd9a6e0a7449 100644
@@ -1983,6 +1983,14 @@ static void dw_mci_set_drto(struct dw_mci *host)
         /* add a bit spare time */
         drto_ms += 10;

Quoted 8 lines

+     /*
+      * If TMOUT register still holds the reset value the above calculation +      * would yield a timeout of over 167 seconds, limit it to 1000ms. +      * Normal reads/writes should not take anywhere close to 120s. +      */
+     if (drto_ms > 120000)
+             drto_ms = 1000;
+

If dtrt_ms is 167sec, it means that bus_hz should be 0 or 1. What value is your host->bus_hz?

Best Regards,
Jaehoon Chung

Quoted 4 lines

        spin_lock_irqsave(&host->irq_lock, irqflags); if (!test_bit(EVENT_DATA_COMPLETE, &host->pending_events)) mod_timer(&host->dto_timer,

    =

Hyperstone GmbH | Line-Eid-Strasse 3 | 78467 Konstanz Managing Directors: Dr. Jan Peter Berns. Commercial register of local courts: Freiburg HRB381782

#6 lore raw

PATCH v2 1/1 mmc: dw_mmc: avoid long timeout if register invalid

In reply to Christian Löhle

Set the limit to 1s if the register is at reset value.

---
 drivers/mmc/host/dw_mmc.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/mmc/host/dw_mmc.c +7 -0
index 6578cc64ae9e..96b620a9fd52 100644
@@ -1983,6 +1983,13 @@ static void dw_mci_set_drto(struct dw_mci *host)
 	/* add a bit spare time */
 	drto_ms += 10;
 
+	/*
+	 * If TMOUT register still holds the reset value the above calculation
+	 * would yield a timeout of over 167 seconds, limit it to 1000ms.
+	 */
+	if (drto_clks == 0xFFFFFF)
+		drto_ms = 1000;
+
 	spin_lock_irqsave(&host->irq_lock, irqflags);
 	if (!test_bit(EVENT_DATA_COMPLETE, &host->pending_events))
 		mod_timer(&host->dto_timer,
Signature · 4 lines
2.32.0
Hyperstone GmbH | Line-Eid-Strasse 3 | 78467 Konstanz
Managing Directors: Dr. Jan Peter Berns.
Commercial register of local courts: Freiburg HRB381782
maintainer
#5 lore raw
In reply to Christian Löhle

Hi

Quoted 5 lines · Christian Löhle

Hey,
so more generally the timeout here can be 41954 up to 167783 ms.
Is 42s too low to view it as invalid here?
Would you prefer the patch exluding the specific timeout values instead of anything above 41954?

It's dependent with bus_hz value and div value.
So it's always not 167 or 42 seconds. Your comment is "TMOUT register is invalid". But it's not invalid value.
We can set to proper value at TMOUT register during probing or somewhere, according to each boards.

I understood what you want to avoid the long time timeout.
- I think your commit-msg, subject and comment need to describe in more detail. (Not register invalid)
- Not always 42 or 167secs when TMOUT is 0xFFFFFF. In some cases, it's under 100ms even though TMOUT is 0xFFFFFF.

If I misunderstood something, let me know, plz.

Anyway, Thanks for reporting this.

Best Regards,
Jaehoon Chung

Quoted 58 lines

Regards,
Christian

From: Jaehoon Chung <[email protected]>
Sent: Friday, September 24, 2021 11:49 AM
To: Christian Löhle; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] mmc: dw_mmc: avoid long timeout if register invalid
Hi,

Quoted 16 lines · Christian Löhle

Set the limit to 1s if the register is at reset value.

---
  drivers/mmc/host/dw_mmc.c | 8 ++++++++

  1 file changed, 8 insertions(+)
drivers/mmc/host/dw_mmc.c +0 -0
index 6578cc64ae9e..cd9a6e0a7449 100644
@@ -1983,6 +1983,14 @@ static void dw_mci_set_drto(struct dw_mci *host)
         /* add a bit spare time */
         drto_ms += 10;

Quoted 8 lines

+     /*
+      * If TMOUT register still holds the reset value the above calculation +      * would yield a timeout of over 167 seconds, limit it to 1000ms. +      * Normal reads/writes should not take anywhere close to 120s. +      */
+     if (drto_ms > 120000)
+             drto_ms = 1000;
+

If dtrt_ms is 167sec, it means that bus_hz should be 0 or 1. What value is your host->bus_hz?

Best Regards,
Jaehoon Chung

Quoted 4 lines

        spin_lock_irqsave(&host->irq_lock, irqflags); if (!test_bit(EVENT_DATA_COMPLETE, &host->pending_events)) mod_timer(&host->dto_timer,

    =

Hyperstone GmbH | Line-Eid-Strasse 3 | 78467 Konstanz Managing Directors: Dr. Jan Peter Berns. Commercial register of local courts: Freiburg HRB381782