Skip to contentSkip to conversation

sdhci: do not program timer when tuning_count is zero

PATCH In review Arend van Spriel 4 participants 14 messages Nov 7, 2013 – Nov 13, 2013

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

PATCH 1/1 sdhci: do not program timer when tuning_count is zero

When the host->tuning_count is zero it means that the retuning is disabled. Doing a mod_timer() with a zero tuning_count does something else.

---
 drivers/mmc/host/sdhci.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci.c +2 -1
index 7a7fb4f..9803e7a 100644
@@ -2007,7 +2007,8 @@ out:
 	} else {
 		host->flags &= ~SDHCI_NEEDS_RETUNING;
 		/* Reload the new initial value for timer */
-		if (host->tuning_mode == SDHCI_TUNING_MODE_1)
+		if (host->tuning_count &&
+		    host->tuning_mode == SDHCI_TUNING_MODE_1)
 			mod_timer(&host->tuning_timer, jiffies +
 				host->tuning_count * HZ);
 	}
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 1 line · Arend van Spriel

When the host->tuning_count is zero it means that the

If the tuning_count is zero, then the retuning timer shouldn't be started in the first place and not possible to run code there. Or is the tuning_count dynamically changed?

Thanks,
Aaron

Quoted 23 lines

retuning is disabled. Doing a mod_timer() with a zero tuning_count does something else.

---
 drivers/mmc/host/sdhci.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci.c +2 -1
index 7a7fb4f..9803e7a 100644
@@ -2007,7 +2007,8 @@ out:
 	} else {
 		host->flags &= ~SDHCI_NEEDS_RETUNING;
 		/* Reload the new initial value for timer */
-		if (host->tuning_mode == SDHCI_TUNING_MODE_1)
+		if (host->tuning_count &&
+		    host->tuning_mode == SDHCI_TUNING_MODE_1)
 			mod_timer(&host->tuning_timer, jiffies +
 				host->tuning_count * HZ);
 	}
#2 lore raw
Quoted 6 lines · Aaron Lu
Quoted 1 line · Arend van Spriel

When the host->tuning_count is zero it means that the

If the tuning_count is zero, then the retuning timer shouldn't be started in the first place and not possible to run code there. Or is the tuning_count dynamically changed?

Actually, the sdhci_execute_tuning() must run once to do the initial tuning procedure. This is mandatory for SDR104. However, *re*tuning is not and a zero tuning_count disables it.

The function is executed initially. The 'if' statement above the patched 'else' statement is actually responsible for programming the retuning timer for the first time. However, it requires tuning_count to be non-zero. The 'else' statement is actually for reloading the retuning timer, which is not the case. Adding the non-zero check assures the retuning timer is never started.

I guess the fact that this needs explaining indicates that the commit message should be updated. I will send a V2 for this.

Regards,
Arend

Quoted 28 lines

Thanks,
Aaron

Quoted 23 lines

retuning is disabled. Doing a mod_timer() with a zero tuning_count does something else.

---
  drivers/mmc/host/sdhci.c |    3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci.c +2 -1
index 7a7fb4f..9803e7a 100644
@@ -2007,7 +2007,8 @@ out:
  	} else {
  		host->flags &= ~SDHCI_NEEDS_RETUNING;
  		/* Reload the new initial value for timer */
-		if (host->tuning_mode == SDHCI_TUNING_MODE_1)
+		if (host->tuning_count &&
+		    host->tuning_mode == SDHCI_TUNING_MODE_1)
  			mod_timer(&host->tuning_timer, jiffies +
  				host->tuning_count * HZ);
  	}
#3 lore raw
Quoted 11 lines · Arend van Spriel
Quoted 6 lines · Aaron Lu
Quoted 1 line · Arend van Spriel

When the host->tuning_count is zero it means that the

If the tuning_count is zero, then the retuning timer shouldn't be started in the first place and not possible to run code there. Or is the tuning_count dynamically changed?

Actually, the sdhci_execute_tuning() must run once to do the initial tuning procedure. This is mandatory for SDR104. However, *re*tuning is not and a zero tuning_count disables it.

So the host in question doesn't need do retuning while in SDR104 mode? It seems your host's retuning mode is mode_1.

Quoted 7 lines

The function is executed initially. The 'if' statement above the patched 'else' statement is actually responsible for programming the retuning timer for the first time. However, it requires tuning_count to be non-zero. The 'else' statement is actually for reloading the retuning timer, which is not the case. Adding the non-zero check assures the retuning timer is never started.

OK, I see.
The SDHCI_USING_RETUNING_TIMER flag is supposed to mean if the host is currently using retuning timer to do retuning, it could also be used to decide if retuning timer needs be re-programmed.

Anyway, a host in retuning mode 1 does not have tuning_count set seems a little odd to me...

Thanks,
Aaron

Quoted 37 lines

I guess the fact that this needs explaining indicates that the commit message should be updated. I will send a V2 for this.

Regards,
Arend

Quoted 28 lines

Thanks,
Aaron

Quoted 23 lines

retuning is disabled. Doing a mod_timer() with a zero tuning_count does something else.

---
  drivers/mmc/host/sdhci.c |    3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci.c +2 -1
index 7a7fb4f..9803e7a 100644
@@ -2007,7 +2007,8 @@ out:
  	} else {
  		host->flags &= ~SDHCI_NEEDS_RETUNING;
  		/* Reload the new initial value for timer */
-		if (host->tuning_mode == SDHCI_TUNING_MODE_1)
+		if (host->tuning_count &&
+		    host->tuning_mode == SDHCI_TUNING_MODE_1)
  			mod_timer(&host->tuning_timer, jiffies +
  				host->tuning_count * HZ);
  	}
#4 lore raw
Quoted 24 lines · Aaron Lu
Quoted 11 lines · Arend van Spriel
Quoted 6 lines · Aaron Lu
Quoted 1 line · Arend van Spriel

When the host->tuning_count is zero it means that the

If the tuning_count is zero, then the retuning timer shouldn't be started in the first place and not possible to run code there. Or is the tuning_count dynamically changed?

Actually, the sdhci_execute_tuning() must run once to do the initial tuning procedure. This is mandatory for SDR104. However, *re*tuning is not and a zero tuning_count disables it.

So the host in question doesn't need do retuning while in SDR104 mode? It seems your host's retuning mode is mode_1.

Quoted 7 lines

The function is executed initially. The 'if' statement above the patched 'else' statement is actually responsible for programming the retuning timer for the first time. However, it requires tuning_count to be non-zero. The 'else' statement is actually for reloading the retuning timer, which is not the case. Adding the non-zero check assures the retuning timer is never started.

Quoted 4 lines

OK, I see.
The SDHCI_USING_RETUNING_TIMER flag is supposed to mean if the host is currently using retuning timer to do retuning, it could also be used to decide if retuning timer needs be re-programmed.

True. I can go for that approach.

Quoted 2 lines

Anyway, a host in retuning mode 1 does not have tuning_count set seems a little odd to me...

Looking at sdhci.h it actually seems sdhci code is missing support for the other modes:

unsigned int tuning_count; /* Timer count for re-tuning */
unsigned int tuning_mode; /* Re-tuning mode supported by host */
#define SDHCI_TUNING_MODE_1 0
struct timer_list tuning_timer; /* Timer for tuning */

At least the other modes are not defined here.

Regards,
Arend

Quoted 42 lines

Thanks,
Aaron

Quoted 37 lines

I guess the fact that this needs explaining indicates that the commit message should be updated. I will send a V2 for this.

Regards,
Arend

Quoted 28 lines

Thanks,
Aaron

Quoted 23 lines

retuning is disabled. Doing a mod_timer() with a zero tuning_count does something else.

---
   drivers/mmc/host/sdhci.c |    3 ++-
   1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci.c +2 -1
index 7a7fb4f..9803e7a 100644
@@ -2007,7 +2007,8 @@ out:
   	} else {
   		host->flags &= ~SDHCI_NEEDS_RETUNING;
   		/* Reload the new initial value for timer */
-		if (host->tuning_mode == SDHCI_TUNING_MODE_1)
+		if (host->tuning_count &&
+		    host->tuning_mode == SDHCI_TUNING_MODE_1)
   			mod_timer(&host->tuning_timer, jiffies +
   				host->tuning_count * HZ);
   	}
#5 lore raw
Quoted 38 lines · Arend van Spriel
Quoted 24 lines · Aaron Lu
Quoted 11 lines · Arend van Spriel
Quoted 6 lines · Aaron Lu
Quoted 1 line · Arend van Spriel

When the host->tuning_count is zero it means that the

If the tuning_count is zero, then the retuning timer shouldn't be started in the first place and not possible to run code there. Or is the tuning_count dynamically changed?

Actually, the sdhci_execute_tuning() must run once to do the initial tuning procedure. This is mandatory for SDR104. However, *re*tuning is not and a zero tuning_count disables it.

So the host in question doesn't need do retuning while in SDR104 mode? It seems your host's retuning mode is mode_1.

Quoted 7 lines

The function is executed initially. The 'if' statement above the patched 'else' statement is actually responsible for programming the retuning timer for the first time. However, it requires tuning_count to be non-zero. The 'else' statement is actually for reloading the retuning timer, which is not the case. Adding the non-zero check assures the retuning timer is never started.

Quoted 4 lines

OK, I see.
The SDHCI_USING_RETUNING_TIMER flag is supposed to mean if the host is currently using retuning timer to do retuning, it could also be used to decide if retuning timer needs be re-programmed.

True. I can go for that approach.

Quoted 2 lines

Anyway, a host in retuning mode 1 does not have tuning_count set seems a little odd to me...

Looking at sdhci.h it actually seems sdhci code is missing support for the other modes:

Quoted 6 lines

unsigned int tuning_count; /* Timer count for re-tuning */
unsigned int tuning_mode; /* Re-tuning mode supported by host */
#define SDHCI_TUNING_MODE_1 0
struct timer_list tuning_timer; /* Timer for tuning */

At least the other modes are not defined here.

Right, only retuning mode 1 is implemented currently.

Thanks,
Aaron

Quoted 48 lines

Regards,
Arend

Quoted 42 lines

Thanks,
Aaron

Quoted 37 lines

I guess the fact that this needs explaining indicates that the commit message should be updated. I will send a V2 for this.

Regards,
Arend

Quoted 28 lines

Thanks,
Aaron

Quoted 23 lines

retuning is disabled. Doing a mod_timer() with a zero tuning_count does something else.

---
   drivers/mmc/host/sdhci.c |    3 ++-
   1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci.c +2 -1
index 7a7fb4f..9803e7a 100644
@@ -2007,7 +2007,8 @@ out:
   	} else {
   		host->flags &= ~SDHCI_NEEDS_RETUNING;
   		/* Reload the new initial value for timer */
-		if (host->tuning_mode == SDHCI_TUNING_MODE_1)
+		if (host->tuning_count &&
+		    host->tuning_mode == SDHCI_TUNING_MODE_1)
   			mod_timer(&host->tuning_timer, jiffies +
   				host->tuning_count * HZ);
   	}
#6 lore raw

PATCH v2 1/1 sdhci: only reprogram retuning timer when flag is set

In reply to Arend van Spriel

When the host->tuning_count is zero it means that the retuning is disabled. This is checked on the first run of sdhci_execute_tuning() by the if statement below:

	if (!(host->flags & SDHCI_NEEDS_RETUNING) && host->tuning_count &&
	    (host->tuning_mode == SDHCI_TUNING_MODE_1)) {

So only when tuning_count is non-zero it will set the host flag SDHCI_USING_RETUNING_TIMER. The else statement is only for re-programming the timer, which means that flag must be set. Because that is not checked the else statement is executed in the first run when tuning_count is zero.

This was seen on a host controller which indicated SDHCI_TUNING_MODE_1 (0) and tuning_count being zero. Suspect that (one of) these registers is not properly set.

---
This patch applies to the mmc-next branch.

V2:
- add more explanation to the commit message
- check host flag SDHCI_USING_RETUNING_TIMER

---
 drivers/mmc/host/sdhci.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/sdhci.c +1 -1
index bd8a098..5974599 100644
@@ -2014,7 +2014,7 @@ out:
 			host->tuning_count * HZ);
 		/* Tuning mode 1 limits the maximum data length to 4MB */
 		mmc->max_blk_count = (4 * 1024 * 1024) / mmc->max_blk_size;
-	} else {
+	} else if (host->flags & SDHCI_USING_RETUNING_TIMER) {
 		host->flags &= ~SDHCI_NEEDS_RETUNING;
 		/* Reload the new initial value for timer */
 		if (host->tuning_mode == SDHCI_TUNING_MODE_1)
Signature · 1 line
1.7.10.4
Reviewed-by on v2 1/1
#7 lore raw

Re: [PATCH V2] sdhci: only reprogram retuning timer when flag is set

Quoted 13 lines · Arend van Spriel

When the host->tuning_count is zero it means that the retuning is disabled. This is checked on the first run of sdhci_execute_tuning() by the if statement below:

	if (!(host->flags & SDHCI_NEEDS_RETUNING) && host->tuning_count &&
	    (host->tuning_mode == SDHCI_TUNING_MODE_1)) {

So only when tuning_count is non-zero it will set the host flag SDHCI_USING_RETUNING_TIMER. The else statement is only for re-programming the timer, which means that flag must be set. Because that is not checked the else statement is executed in the first run when tuning_count is zero.

Quoted 5 lines

This was seen on a host controller which indicated SDHCI_TUNING_MODE_1 (0) and tuning_count being zero. Suspect that (one of) these registers is not properly set.

-Aaron

Quoted 24 lines

---
This patch applies to the mmc-next branch.

V2:
- add more explanation to the commit message
- check host flag SDHCI_USING_RETUNING_TIMER

---
 drivers/mmc/host/sdhci.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/sdhci.c +1 -1
index bd8a098..5974599 100644
@@ -2014,7 +2014,7 @@ out:
 			host->tuning_count * HZ);
 		/* Tuning mode 1 limits the maximum data length to 4MB */
 		mmc->max_blk_count = (4 * 1024 * 1024) / mmc->max_blk_size;
-	} else {
+	} else if (host->flags & SDHCI_USING_RETUNING_TIMER) {
 		host->flags &= ~SDHCI_NEEDS_RETUNING;
 		/* Reload the new initial value for timer */
 		if (host->tuning_mode == SDHCI_TUNING_MODE_1)
#8 lore raw

Re: [PATCH V2] sdhci: only reprogram retuning timer when flag is set

In reply to Arend van Spriel

Hi Arend,

Quoted 33 lines · Arend van Spriel

When the host->tuning_count is zero it means that the retuning is disabled. This is checked on the first run of sdhci_execute_tuning() by the if statement below:

        if (!(host->flags & SDHCI_NEEDS_RETUNING) && host->tuning_count &&
            (host->tuning_mode == SDHCI_TUNING_MODE_1)) {

So only when tuning_count is non-zero it will set the host flag SDHCI_USING_RETUNING_TIMER. The else statement is only for re-programming the timer, which means that flag must be set. Because that is not checked the else statement is executed in the first run when tuning_count is zero.

This was seen on a host controller which indicated SDHCI_TUNING_MODE_1 (0) and tuning_count being zero. Suspect that (one of) these registers is not properly set.

---
This patch applies to the mmc-next branch.

V2:
- add more explanation to the commit message
- check host flag SDHCI_USING_RETUNING_TIMER

---
 drivers/mmc/host/sdhci.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/sdhci.c +0 -0
index bd8a098..5974599 100644

drivers/mmc/host/sdhci.c out: · line 2020

Quoted 8 lines
drivers/mmc/host/sdhci.c +1 -1
@@ -2014,7 +2014,7 @@ out:
                        host->tuning_count * HZ);
                /* Tuning mode 1 limits the maximum data length to 4MB */
                mmc->max_blk_count = (4 * 1024 * 1024) / mmc->max_blk_size;
-       } else {
+       } else if (host->flags & SDHCI_USING_RETUNING_TIMER) {
                host->flags &= ~SDHCI_NEEDS_RETUNING;
                /* Reload the new initial value for timer */
                if (host->tuning_mode == SDHCI_TUNING_MODE_1)

I wonder if we could also remove this line?
It looks to me it's not neccesary to check the tuning_mode again since we already check the flag
above and SDHCI_TUNING_MODE_1 seems like the prerequisite of SDHCI_USING_RETUNING_TIMER.

Regards
Dong Aisheng

Quoted 8 lines

--
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw

Re: [PATCH V2] sdhci: only reprogram retuning timer when flag is set

Quoted 42 lines · Dong Aisheng

Hi Arend,

Quoted 39 lines · Arend van Spriel

When the host->tuning_count is zero it means that the retuning is disabled. This is checked on the first run of sdhci_execute_tuning() by the if statement below:

         if (!(host->flags & SDHCI_NEEDS_RETUNING) && host->tuning_count &&
             (host->tuning_mode == SDHCI_TUNING_MODE_1)) {

So only when tuning_count is non-zero it will set the host flag SDHCI_USING_RETUNING_TIMER. The else statement is only for re-programming the timer, which means that flag must be set. Because that is not checked the else statement is executed in the first run when tuning_count is zero.

This was seen on a host controller which indicated SDHCI_TUNING_MODE_1 (0) and tuning_count being zero. Suspect that (one of) these registers is not properly set.

---
This patch applies to the mmc-next branch.

V2:
- add more explanation to the commit message
- check host flag SDHCI_USING_RETUNING_TIMER

---
  drivers/mmc/host/sdhci.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/sdhci.c +1 -1
index bd8a098..5974599 100644
@@ -2014,7 +2014,7 @@ out:
                         host->tuning_count * HZ);
                 /* Tuning mode 1 limits the maximum data length to 4MB */
                 mmc->max_blk_count = (4 * 1024 * 1024) / mmc->max_blk_size;
-       } else {
+       } else if (host->flags & SDHCI_USING_RETUNING_TIMER) {
                 host->flags &= ~SDHCI_NEEDS_RETUNING;
Quoted 8 lines

drivers/mmc/host/sdhci.c out: · line 2020

Quoted 2 lines
drivers/mmc/host/sdhci.c +0 -0
                 /* Reload the new initial value for timer */
                 if (host->tuning_mode == SDHCI_TUNING_MODE_1)

I wonder if we could also remove this line?
It looks to me it's not neccesary to check the tuning_mode again since we already check the flag
above and SDHCI_TUNING_MODE_1 seems like the prerequisite of SDHCI_USING_RETUNING_TIMER.

According the spec the other tuning modes also can use retuning timer. Currently, the mmc stack in upstream linux only supports tuning mode 1. When adding the other modes this if statement will probably go.

Regards,
Arend

Quoted 12 lines

Regards
Dong Aisheng

Quoted 8 lines

--
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw

Re: [PATCH V2] sdhci: only reprogram retuning timer when flag is set

Hi Arend,

Quoted 60 lines · Arend van Spriel
Quoted 49 lines · Dong Aisheng

Hi Arend,

Quoted 44 lines · Arend van Spriel

When the host->tuning_count is zero it means that the retuning is disabled. This is checked on the first run of sdhci_execute_tuning() by the if statement below:

         if (!(host->flags & SDHCI_NEEDS_RETUNING) && host->tuning_count
&&
             (host->tuning_mode == SDHCI_TUNING_MODE_1)) {

So only when tuning_count is non-zero it will set the host flag SDHCI_USING_RETUNING_TIMER. The else statement is only for re-programming the timer, which means that flag must be set. Because that is not checked the else statement is executed in the first run when tuning_count is zero.

This was seen on a host controller which indicated SDHCI_TUNING_MODE_1 (0) and tuning_count being zero. Suspect that (one of) these registers is not properly set.

---
This patch applies to the mmc-next branch.

V2:
- add more explanation to the commit message
- check host flag SDHCI_USING_RETUNING_TIMER

---
  drivers/mmc/host/sdhci.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/sdhci.c +1 -1
index bd8a098..5974599 100644
@@ -2014,7 +2014,7 @@ out:
                         host->tuning_count * HZ);
                 /* Tuning mode 1 limits the maximum data length to 4MB
 */
                 mmc->max_blk_count = (4 * 1024 * 1024) /
 mmc->max_blk_size;
-       } else {
+       } else if (host->flags & SDHCI_USING_RETUNING_TIMER) {
                 host->flags &= ~SDHCI_NEEDS_RETUNING;
                 /* Reload the new initial value for timer */
Quoted 8 lines
Quoted 1 line
                 if (host->tuning_mode == SDHCI_TUNING_MODE_1)

I wonder if we could also remove this line?
It looks to me it's not neccesary to check the tuning_mode again since we already check the flag
above and SDHCI_TUNING_MODE_1 seems like the prerequisite of SDHCI_USING_RETUNING_TIMER.

Quoted 4 lines

According the spec the other tuning modes also can use retuning timer. Currently, the mmc stack in upstream linux only supports tuning mode 1. When adding the other modes this if statement will probably go.

For currently code, it looks like also not necessary to check it since SDHCI_USING_RETUNING_TIMER will only be set when tunning_mode is SDHCI_TUNING_MODE_1.
And SDHCI_TUNING_MODE_1 just indicates the tuning mode while the flag SDHCI_USING_RETUNING_TIMER represents the retuning timer implementation. So check the flag to invoke the timer seems make more sense to me. do you agree?

Regards
Dong Aisheng

Quoted 19 lines

Regards,
Arend

Quoted 13 lines

Regards
Dong Aisheng

Quoted 8 lines

--
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#11 lore raw

Re: [PATCH V2] sdhci: only reprogram retuning timer when flag is set

Quoted 68 lines · Dong Aisheng

Hi Arend,

Quoted 60 lines · Arend van Spriel
Quoted 49 lines · Dong Aisheng

Hi Arend,

Quoted 44 lines · Arend van Spriel

When the host->tuning_count is zero it means that the retuning is disabled. This is checked on the first run of sdhci_execute_tuning() by the if statement below:

          if (!(host->flags & SDHCI_NEEDS_RETUNING) && host->tuning_count
&&
              (host->tuning_mode == SDHCI_TUNING_MODE_1)) {

So only when tuning_count is non-zero it will set the host flag SDHCI_USING_RETUNING_TIMER. The else statement is only for re-programming the timer, which means that flag must be set. Because that is not checked the else statement is executed in the first run when tuning_count is zero.

This was seen on a host controller which indicated SDHCI_TUNING_MODE_1 (0) and tuning_count being zero. Suspect that (one of) these registers is not properly set.

---
This patch applies to the mmc-next branch.

V2:
- add more explanation to the commit message
- check host flag SDHCI_USING_RETUNING_TIMER

---
   drivers/mmc/host/sdhci.c |    2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/sdhci.c +1 -1
index bd8a098..5974599 100644
@@ -2014,7 +2014,7 @@ out:
                          host->tuning_count * HZ);
                  /* Tuning mode 1 limits the maximum data length to 4MB
 */
                  mmc->max_blk_count = (4 * 1024 * 1024) /
 mmc->max_blk_size;
-       } else {
+       } else if (host->flags & SDHCI_USING_RETUNING_TIMER) {
                  host->flags &= ~SDHCI_NEEDS_RETUNING;
                  /* Reload the new initial value for timer */
Quoted 8 lines
Quoted 1 line
                  if (host->tuning_mode == SDHCI_TUNING_MODE_1)

I wonder if we could also remove this line?
It looks to me it's not neccesary to check the tuning_mode again since we already check the flag
above and SDHCI_TUNING_MODE_1 seems like the prerequisite of SDHCI_USING_RETUNING_TIMER.

Quoted 4 lines

According the spec the other tuning modes also can use retuning timer. Currently, the mmc stack in upstream linux only supports tuning mode 1. When adding the other modes this if statement will probably go.

Quoted 7 lines

For currently code, it looks like also not necessary to check it since SDHCI_USING_RETUNING_TIMER will only be set when tunning_mode is SDHCI_TUNING_MODE_1.
And SDHCI_TUNING_MODE_1 just indicates the tuning mode while the flag SDHCI_USING_RETUNING_TIMER represents the retuning timer implementation. So check the flag to invoke the timer seems make more sense to me. do you agree?

The flag SDHCI_USING_RETUNING_TIMER is only set after the initial tuning run so in the if-statement. So currently in the else-statement the fact that SDHCI_USING_RETUNING_TIMER is set implies SDHCI_TUNING_MODE_1.

Regards,
Arend

Quoted 23 lines

Regards
Dong Aisheng

Quoted 19 lines

Regards,
Arend

Quoted 13 lines

Regards
Dong Aisheng

Quoted 8 lines

--
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#12 lore raw

Re: [PATCH V2] sdhci: only reprogram retuning timer when flag is set

Quoted 88 lines · Arend van Spriel
Quoted 78 lines · Dong Aisheng

Hi Arend,

Quoted 67 lines · Arend van Spriel
Quoted 57 lines · Dong Aisheng

Hi Arend,

Quoted 43 lines · Arend van Spriel

When the host->tuning_count is zero it means that the retuning is disabled. This is checked on the first run of sdhci_execute_tuning() by the if statement below:

          if (!(host->flags & SDHCI_NEEDS_RETUNING) &&
host->tuning_count
&&
              (host->tuning_mode == SDHCI_TUNING_MODE_1)) {

So only when tuning_count is non-zero it will set the host flag SDHCI_USING_RETUNING_TIMER. The else statement is only for re-programming the timer, which means that flag must be set. Because that is not checked the else statement is executed in the first run when tuning_count is zero.

This was seen on a host controller which indicated SDHCI_TUNING_MODE_1 (0) and tuning_count being zero. Suspect that (one of) these registers is not properly set.

---
This patch applies to the mmc-next branch.

V2:
- add more explanation to the commit message
- check host flag SDHCI_USING_RETUNING_TIMER

---
   drivers/mmc/host/sdhci.c |    2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/sdhci.c +0 -0
index bd8a098..5974599 100644
@@ -2014,7 +2014,7 @@ out:
                          host->tuning_count * HZ);
                  /* Tuning mode 1 limits the maximum data length to

4MB
*/

                  mmc->max_blk_count = (4 * 1024 * 1024) /

mmc->max_blk_size;

drivers/mmc/host/sdhci.c

Quoted 5 lines
drivers/mmc/host/sdhci.c +1 -1
-       } else {
+       } else if (host->flags & SDHCI_USING_RETUNING_TIMER) {
                  host->flags &= ~SDHCI_NEEDS_RETUNING;
                  /* Reload the new initial value for timer */
                  if (host->tuning_mode == SDHCI_TUNING_MODE_1)
Quoted 5 lines

I wonder if we could also remove this line?
It looks to me it's not neccesary to check the tuning_mode again since we already check the flag
above and SDHCI_TUNING_MODE_1 seems like the prerequisite of SDHCI_USING_RETUNING_TIMER.

Quoted 5 lines

According the spec the other tuning modes also can use retuning timer. Currently, the mmc stack in upstream linux only supports tuning mode 1. When
adding the other modes this if statement will probably go.

Quoted 7 lines

For currently code, it looks like also not necessary to check it since SDHCI_USING_RETUNING_TIMER will only be set when tunning_mode is SDHCI_TUNING_MODE_1.
And SDHCI_TUNING_MODE_1 just indicates the tuning mode while the flag SDHCI_USING_RETUNING_TIMER represents the retuning timer implementation. So check the flag to invoke the timer seems make more sense to me. do you agree?

Quoted 4 lines

The flag SDHCI_USING_RETUNING_TIMER is only set after the initial tuning run so in the if-statement. So currently in the else-statement the fact that SDHCI_USING_RETUNING_TIMER is set implies SDHCI_TUNING_MODE_1.

Right, so that means we could remove the tuning_mode check in the else-statement.

drivers/mmc/host/sdhci.c +3 -4
index 2d55e6a..b2928ef 100644
@@ -2015,12 +2015,11 @@ out:
                        host->tuning_count * HZ);
                /* Tuning mode 1 limits the maximum data length to 4MB */
                mmc->max_blk_count = (4 * 1024 * 1024) / mmc->max_blk_size;
-       } else {
+       } else if (host->flags & SDHCI_USING_RETUNING_TIMER) {
                host->flags &= ~SDHCI_NEEDS_RETUNING;
                /* Reload the new initial value for timeout workqueue */
-               if (host->tuning_mode == SDHCI_TUNING_MODE_1)
-                       schedule_delayed_work(&host->tuning_timeout_work,
-                               host->tuning_count * HZ);
+               schedule_delayed_work(&host->tuning_timeout_work,
+                       host->tuning_count * HZ);
        }
 
        /*

Regards
Dong Aisheng

Quoted 30 lines

Regards,
Arend

Quoted 24 lines

Regards
Dong Aisheng

Quoted 20 lines

Regards,
Arend

Quoted 14 lines

Regards
Dong Aisheng

Quoted 8 lines

--
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw

Re: [PATCH V2] sdhci: only reprogram retuning timer when flag is set

Quoted 89 lines · Dong Aisheng
Quoted 88 lines · Arend van Spriel
Quoted 85 lines · Dong Aisheng

Hi Arend,

Quoted 67 lines · Arend van Spriel
Quoted 57 lines · Dong Aisheng

Hi Arend,

Quoted 43 lines · Arend van Spriel

When the host->tuning_count is zero it means that the retuning is disabled. This is checked on the first run of sdhci_execute_tuning() by the if statement below:

          if (!(host->flags & SDHCI_NEEDS_RETUNING) &&
host->tuning_count
&&
              (host->tuning_mode == SDHCI_TUNING_MODE_1)) {

So only when tuning_count is non-zero it will set the host flag SDHCI_USING_RETUNING_TIMER. The else statement is only for re-programming the timer, which means that flag must be set. Because that is not checked the else statement is executed in the first run when tuning_count is zero.

This was seen on a host controller which indicated SDHCI_TUNING_MODE_1 (0) and tuning_count being zero. Suspect that (one of) these registers is not properly set.

---
This patch applies to the mmc-next branch.

V2:
- add more explanation to the commit message
- check host flag SDHCI_USING_RETUNING_TIMER

---
   drivers/mmc/host/sdhci.c |    2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/sdhci.c +0 -0
index bd8a098..5974599 100644
@@ -2014,7 +2014,7 @@ out:
                          host->tuning_count * HZ);
                  /* Tuning mode 1 limits the maximum data length to

4MB
*/

                  mmc->max_blk_count = (4 * 1024 * 1024) /

mmc->max_blk_size;

drivers/mmc/host/sdhci.c out:

Quoted 5 lines
drivers/mmc/host/sdhci.c +1 -1
-       } else {
+       } else if (host->flags & SDHCI_USING_RETUNING_TIMER) {
                  host->flags &= ~SDHCI_NEEDS_RETUNING;
                  /* Reload the new initial value for timer */
                  if (host->tuning_mode == SDHCI_TUNING_MODE_1)
Quoted 5 lines

I wonder if we could also remove this line?
It looks to me it's not neccesary to check the tuning_mode again since we already check the flag
above and SDHCI_TUNING_MODE_1 seems like the prerequisite of SDHCI_USING_RETUNING_TIMER.

Quoted 5 lines

According the spec the other tuning modes also can use retuning timer. Currently, the mmc stack in upstream linux only supports tuning mode 1. When
adding the other modes this if statement will probably go.

For currently code, it looks like also not necessary to check it since SDHCI_USING_RETUNING_TIMER will only be set when tunning_mode is SDHCI_TUNING_MODE_1.
And SDHCI_TUNING_MODE_1 just indicates the tuning mode while the flag SDHCI_USING_RETUNING_TIMER represents the retuning timer implementation. So check the flag to invoke the timer seems make more sense to me. do you agree?

Quoted 7 lines
Quoted 4 lines

The flag SDHCI_USING_RETUNING_TIMER is only set after the initial tuning run so in the if-statement. So currently in the else-statement the fact that SDHCI_USING_RETUNING_TIMER is set implies SDHCI_TUNING_MODE_1.

Right, so that means we could remove the tuning_mode check in the else-statement.

I agree.

-Aaron

Quoted 59 lines
drivers/mmc/host/sdhci.c +3 -4
index 2d55e6a..b2928ef 100644
@@ -2015,12 +2015,11 @@ out:
                        host->tuning_count * HZ);
                /* Tuning mode 1 limits the maximum data length to 4MB */
                mmc->max_blk_count = (4 * 1024 * 1024) / mmc->max_blk_size;
-       } else {
+       } else if (host->flags & SDHCI_USING_RETUNING_TIMER) {
                host->flags &= ~SDHCI_NEEDS_RETUNING;
                /* Reload the new initial value for timeout workqueue */
-               if (host->tuning_mode == SDHCI_TUNING_MODE_1)
-                       schedule_delayed_work(&host->tuning_timeout_work,
-                               host->tuning_count * HZ);
+               schedule_delayed_work(&host->tuning_timeout_work,
+                       host->tuning_count * HZ);
        }
 
        /*

Regards
Dong Aisheng

Quoted 30 lines

Regards,
Arend

Quoted 24 lines

Regards
Dong Aisheng

Quoted 20 lines

Regards,
Arend

Quoted 14 lines

Regards
Dong Aisheng

Quoted 8 lines

--
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html