mmc: sdhci: Fix recovery from tuning timeout
Adrian Hunter
maintainercover mmc: sdhci: Fix recovery from tuning timeout
Hi
Here are some small SDHCI tuning-related fixes.
Adrian Hunter (4):
Revert "mmc: sdhci: Reset cmd and data circuits after tuning failure"
mmc: sdhci: Fix recovery from tuning timeout
mmc: sdhci: Fix tuning reset after exhausting the maximum number of loops
mmc: sdhci: Always allow tuning to fall back to fixed sampling
drivers/mmc/host/sdhci.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-)
Regards
Adrian
Adrian Hunter
maintainerPATCH 1/4 Revert "mmc: sdhci: Reset cmd and data circuits after tuning failure"
This reverts commit fe5fb2e3b58f ("mmc: sdhci: Reset cmd and data circuits after tuning failure").
A better fix is available, and it will be applied to older stable releases, so get this out of the way by reverting it.
--- drivers/mmc/host/sdhci.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/mmc/host/sdhci.c +0 -4
@@ -2090,10 +2090,6 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)if (!host->tuning_done) {pr_info (DRIVER_NAME ": Timeout waiting for Buffer Read Ready interrupt during tuning procedure, falling back to fixed sampling clock\n" ); - -sdhci_do_reset (host,SDHCI_RESET_CMD ); -sdhci_do_reset (host,SDHCI_RESET_DATA ); - ctrl =sdhci_readw (host,SDHCI_HOST_CONTROL2 ); ctrl &= ~SDHCI_CTRL_TUNED_CLK ; ctrl &= ~SDHCI_CTRL_EXEC_TUNING ;
Signature · 1 line
1.9.1
Adrian Hunter
maintainerPATCH 2/4 mmc: sdhci: Fix recovery from tuning timeout
In reply to Adrian HunterClearing the tuning bits should reset the tuning circuit. However there is more to do. Reset the command and data lines for good measure, and then for eMMC ensure the card is not still trying to process a tuning command by sending a stop command.
Note the JEDEC eMMC specification says the stop command (CMD12) can be used to stop a tuning command (CMD21) whereas the SD specification is silent on the subject with respect to the SD tuning command (CMD19). Considering that CMD12 is not a valid SDIO command, the stop command is sent only when the tuning command is CMD21 i.e. for eMMC. That addresses cases seen so far which have been on eMMC.
Note that this replaces the commit fe5fb2e3b58f ("mmc: sdhci: Reset cmd and data circuits after tuning failure") which is being reverted for v4.9+.
--- drivers/mmc/host/sdhci.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/mmc/host/sdhci.c +20 -0
@@ -2095,7 +2095,27 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode) ctrl &= ~SDHCI_CTRL_EXEC_TUNING ;sdhci_writew (host, ctrl,SDHCI_HOST_CONTROL2 ); +sdhci_do_reset (host,SDHCI_RESET_CMD ); +sdhci_do_reset (host,SDHCI_RESET_DATA ); + err = -EIO ; + +if (cmd.opcode !=MMC_SEND_TUNING_BLOCK_HS200 ) + goto out; + +sdhci_writel (host, host->ier,SDHCI_INT_ENABLE ); +sdhci_writel (host, host->ier,SDHCI_SIGNAL_ENABLE ); + +spin_unlock_irqrestore (&host->lock, flags); + +memset (&cmd,0 ,sizeof (cmd)); + cmd.opcode =MMC_STOP_TRANSMISSION ; + cmd.flags =MMC_RSP_SPI_R1B |MMC_RSP_R1B |MMC_CMD_AC ; + cmd.busy_timeout =50 ; +mmc_wait_for_cmd (mmc, &cmd,0 ); + +spin_lock_irqsave (&host->lock, flags); + goto out; }
Signature · 1 line
1.9.1
Adrian Hunter
maintainerPATCH 3/4 mmc: sdhci: Fix tuning reset after exhausting the maximum number of loops
In reply to Adrian HunterIf the driver has exhausted the maximum number of tuning loops, then fixed sampling is used. To do that both SDHCI_CTRL_TUNED_CLK and SDHCI_CTRL_EXEC_TUNING must be reset to 0, but only SDHCI_CTRL_TUNED_CLK was being reset. Reset SDHCI_CTRL_EXEC_TUNING to 0 also.
--- drivers/mmc/host/sdhci.c | 1 + 1 file changed, 1 insertion(+)
drivers/mmc/host/sdhci.c +1 -0
@@ -2134,6 +2134,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)*/ if (tuning_loop_counter <0 ) { ctrl &= ~SDHCI_CTRL_TUNED_CLK ; + ctrl &= ~SDHCI_CTRL_EXEC_TUNING ;sdhci_writew (host, ctrl,SDHCI_HOST_CONTROL2 ); }if (!(ctrl &SDHCI_CTRL_TUNED_CLK )) {
Signature · 1 line
1.9.1
Adrian Hunter
maintainerPATCH 4/4 mmc: sdhci: Always allow tuning to fall back to fixed sampling
In reply to Adrian HunterSDHCI falls back to fixed sampling if there is an error during tuning. However it also reports an error unless there is periodic re-tuning. That is not the best option because:
a) there is a reasonable chance that fixed sampling will work, especially at room temperature.
b) re-tuning will be done again anyway if there are CRC errors. Change to return no error always when falling back to fixed sampling.
--- drivers/mmc/host/sdhci.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-)
drivers/mmc/host/sdhci.c +2 -18
@@ -2098,8 +2098,6 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)sdhci_do_reset (host,SDHCI_RESET_CMD );sdhci_do_reset (host,SDHCI_RESET_DATA ); - err = -EIO ; -if (cmd.opcode !=MMC_SEND_TUNING_BLOCK_HS200 ) goto out;
@@ -2137,24 +2135,10 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode) ctrl &= ~SDHCI_CTRL_EXEC_TUNING ;sdhci_writew (host, ctrl,SDHCI_HOST_CONTROL2 ); } -if (!(ctrl &SDHCI_CTRL_TUNED_CLK )) { +if (!(ctrl &SDHCI_CTRL_TUNED_CLK ))pr_info (DRIVER_NAME ": Tuning procedure failed, falling back to fixed sampling clock\n" ); - err = -EIO ; - } - out: -if (tuning_count) { -/* -* In case tuning fails, host controllers which support -* re-tuning can try tuning again at a later time, when the -* re-tuning timer expires. So for these controllers, we -* return 0. Since there might be other controllers who do not -* have this capability, we return error for them. -*/ - err =0 ; - } - - host->mmc->retune_period = err ?0 : tuning_count; + host->mmc->retune_period = tuning_count;sdhci_writel (host, host->ier,SDHCI_INT_ENABLE );sdhci_writel (host, host->ier,SDHCI_SIGNAL_ENABLE );
Signature · 1 line
1.9.1
Quoted 38 lines · Adrian Hunter
Clearing the tuning bits should reset the tuning circuit. However there is more to do. Reset the command and data lines for good measure, and then for eMMC ensure the card is not still trying to process a tuning command by sending a stop command.
Note the JEDEC eMMC specification says the stop command (CMD12) can be used to stop a tuning command (CMD21) whereas the SD specification is silent on the subject with respect to the SD tuning command (CMD19). Considering that CMD12 is not a valid SDIO command, the stop command is sent only when the tuning command is CMD21 i.e. for eMMC. That addresses cases seen so far which have been on eMMC.
Note that this replaces the commit
fe5fb2e3b58f("mmc: sdhci: Reset cmd and data circuits after tuning failure") which is being reverted for v4.9+.Signed-off-by Adrian Hunter <[email protected]>Tested-by Dan O'Donovan <[email protected]>--- drivers/mmc/host/sdhci.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)drivers/mmc/host/sdhci.c +7
-0@@ -2095,7 +2095,27 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode) ctrl &= ~SDHCI_CTRL_EXEC_TUNING ;sdhci_writew (host, ctrl,SDHCI_HOST_CONTROL2 ); +sdhci_do_reset (host,SDHCI_RESET_CMD ); +sdhci_do_reset (host,SDHCI_RESET_DATA ); + err = -EIO ; + +if (cmd.opcode !=MMC_SEND_TUNING_BLOCK_HS200 ) + goto out; +
drivers/mmc/host/sdhci.c static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode) · line 2115
Quoted 10 lines
drivers/mmc/host/sdhci.c +10
-0+sdhci_writel (host, host->ier,SDHCI_INT_ENABLE ); +sdhci_writel (host, host->ier,SDHCI_SIGNAL_ENABLE ); + +spin_unlock_irqrestore (&host->lock, flags); + +memset (&cmd,0 ,sizeof (cmd)); + cmd.opcode =MMC_STOP_TRANSMISSION ; + cmd.flags =MMC_RSP_SPI_R1B |MMC_RSP_R1B |MMC_CMD_AC ; + cmd.busy_timeout =50 ; +mmc_wait_for_cmd (mmc, &cmd,0 );
No, please don't add more hacks to send commands internally from sdhci.
Maybe even before you start fix the problems for tuning, perhaps you try to clean up the current code when sending CMD21/19 in sdhci_execute_tuning()?
Moreover, according to the change log above, it seems like a generic thing to send CMD12 to abort tuning. In such case, we could either make the core deal with it in the error path - or we could implement a "mmc_abort_tuning()" function, host drivers may call when needed.
Quoted 9 lines
drivers/mmc/host/sdhci.c +3
-1+ +spin_lock_irqsave (&host->lock, flags); + goto out; } --1.9.1
Kind regards
Uffe
Adrian Hunter
maintainerQuoted 52 lines · Ulf Hansson
Quoted 38 lines · Adrian Hunter
Clearing the tuning bits should reset the tuning circuit. However there is more to do. Reset the command and data lines for good measure, and then for eMMC ensure the card is not still trying to process a tuning command by sending a stop command.
Note the JEDEC eMMC specification says the stop command (CMD12) can be used to stop a tuning command (CMD21) whereas the SD specification is silent on the subject with respect to the SD tuning command (CMD19). Considering that CMD12 is not a valid SDIO command, the stop command is sent only when the tuning command is CMD21 i.e. for eMMC. That addresses cases seen so far which have been on eMMC.
Note that this replaces the commit
fe5fb2e3b58f("mmc: sdhci: Reset cmd and data circuits after tuning failure") which is being reverted for v4.9+.Signed-off-by Adrian Hunter <[email protected]>Tested-by Dan O'Donovan <[email protected]>--- drivers/mmc/host/sdhci.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)drivers/mmc/host/sdhci.c +7
-0@@ -2095,7 +2095,27 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode) ctrl &= ~SDHCI_CTRL_EXEC_TUNING ;sdhci_writew (host, ctrl,SDHCI_HOST_CONTROL2 ); +sdhci_do_reset (host,SDHCI_RESET_CMD ); +sdhci_do_reset (host,SDHCI_RESET_DATA ); + err = -EIO ; + +if (cmd.opcode !=MMC_SEND_TUNING_BLOCK_HS200 ) + goto out; +drivers/mmc/host/sdhci.c static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode) · line 2115
Quoted 10 lines
drivers/mmc/host/sdhci.c +10
-0+sdhci_writel (host, host->ier,SDHCI_INT_ENABLE ); +sdhci_writel (host, host->ier,SDHCI_SIGNAL_ENABLE ); + +spin_unlock_irqrestore (&host->lock, flags); + +memset (&cmd,0 ,sizeof (cmd)); + cmd.opcode =MMC_STOP_TRANSMISSION ; + cmd.flags =MMC_RSP_SPI_R1B |MMC_RSP_R1B |MMC_CMD_AC ; + cmd.busy_timeout =50 ; +mmc_wait_for_cmd (mmc, &cmd,0 );No, please don't add more hacks to send commands internally from sdhci.
Quoted 8 lines
Maybe even before you start fix the problems for tuning, perhaps you try to clean up the current code when sending CMD21/19 in
sdhci_execute_tuning()?Moreover, according to the change log above, it seems like a generic thing to send CMD12 to abort tuning. In such case, we could either make the core deal with it in the error path - or we could implement a "
mmc_abort_tuning()" function, host drivers may call when needed.
I am not sure a cleanup would apply cleanly to stable trees. It would be nicer to have these patches for stable and then a cleanup on top. Would that be acceptable?
Quoted 57 lines · Adrian Hunter
Quoted 56 lines · Ulf Hansson
Quoted 38 lines · Adrian Hunter
Clearing the tuning bits should reset the tuning circuit. However there is more to do. Reset the command and data lines for good measure, and then for eMMC ensure the card is not still trying to process a tuning command by sending a stop command.
Note the JEDEC eMMC specification says the stop command (CMD12) can be used to stop a tuning command (CMD21) whereas the SD specification is silent on the subject with respect to the SD tuning command (CMD19). Considering that CMD12 is not a valid SDIO command, the stop command is sent only when the tuning command is CMD21 i.e. for eMMC. That addresses cases seen so far which have been on eMMC.
Note that this replaces the commit
fe5fb2e3b58f("mmc: sdhci: Reset cmd and data circuits after tuning failure") which is being reverted for v4.9+.Signed-off-by Adrian Hunter <[email protected]>Tested-by Dan O'Donovan <[email protected]>--- drivers/mmc/host/sdhci.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)drivers/mmc/host/sdhci.c +7
-0@@ -2095,7 +2095,27 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode) ctrl &= ~SDHCI_CTRL_EXEC_TUNING ;sdhci_writew (host, ctrl,SDHCI_HOST_CONTROL2 ); +sdhci_do_reset (host,SDHCI_RESET_CMD ); +sdhci_do_reset (host,SDHCI_RESET_DATA ); + err = -EIO ; + +if (cmd.opcode !=MMC_SEND_TUNING_BLOCK_HS200 ) + goto out; +drivers/mmc/host/sdhci.c static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode) · line 2115
Quoted 10 lines
drivers/mmc/host/sdhci.c +10
-0+sdhci_writel (host, host->ier,SDHCI_INT_ENABLE ); +sdhci_writel (host, host->ier,SDHCI_SIGNAL_ENABLE ); + +spin_unlock_irqrestore (&host->lock, flags); + +memset (&cmd,0 ,sizeof (cmd)); + cmd.opcode =MMC_STOP_TRANSMISSION ; + cmd.flags =MMC_RSP_SPI_R1B |MMC_RSP_R1B |MMC_CMD_AC ; + cmd.busy_timeout =50 ; +mmc_wait_for_cmd (mmc, &cmd,0 );No, please don't add more hacks to send commands internally from sdhci.
Maybe even before you start fix the problems for tuning, perhaps you try to clean up the current code when sending CMD21/19 in
sdhci_execute_tuning()?
Quoted 9 lines
Quoted 4 lines
Moreover, according to the change log above, it seems like a generic thing to send CMD12 to abort tuning. In such case, we could either make the core deal with it in the error path - or we could implement a "
mmc_abort_tuning()" function, host drivers may call when needed.I am not sure a cleanup would apply cleanly to stable trees. It would be nicer to have these patches for stable and then a cleanup on top. Would that be acceptable?
Yes. That's ok. Can you please re-spin with cleanups on top then.
Kind regards
Uffe