sunxi a20 mmc timeout fix
Subsystems (2)
cover sunxi a20 mmc timeout fix
Hello,
I had serious problems with root filesustem on SD card on Cubieboard2 when clock gating was on.
It turns out that sunxi_mmc_oclk_onoff has way too short timeout ofr setting the clock.
So here are some patches for
- bumping the timout
- spamming dmesg when the time to set the clock seems too long
- setting SDXC_LOW_POWER_ON which is unset but never set
Also feel free to just bump the timeout to reasonably high value so the board can boot reliably with mmc clock gating enabled.
Thanks
Michal
Michal Suchanek (2):
mmc: sunxi: fix timeout in sunxi_mmc_oclk_onoff
mmc: sunxi: Also set SDXC_LOW_POWER_ON
drivers/mmc/host/sunxi-mmc.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
Signature · 1 line
2.1.4
PATCH 1/2 mmc: sunxi: fix timeout in sunxi_mmc_oclk_onoff
The 250ms timeout is too short.
On my system enabling the oclk takes under 50ms and disabling slightly over 100ms when idle. Under load disabling the clock can take over 350ms.
This does not make mmc clock gating look like good option to have on sunxi but the system should not crash with mmc clock gating enabled nonetheless.
This patch sets the timeout to 750ms and adds debug prints which show how long enabling/disabling the clock took so more data can be collected from other systems.
--- drivers/mmc/host/sunxi-mmc.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
drivers/mmc/host/sunxi-mmc.c +19 -3
@@ -595,7 +595,7 @@ static irqreturn_t sunxi_mmc_handle_manual_stop(int irq, void *dev_id)static int sunxi_mmc_oclk_onoff (struct sunxi_mmc_host *host,u32 oclk_en) { -unsigned long expire = jiffies +msecs_to_jiffies (250 ); +unsigned long start, end;u32 rval; rval =mmc_readl (host,REG_CLKCR );
@@ -604,6 +604,8 @@ static int sunxi_mmc_oclk_onoff(struct sunxi_mmc_host *host, u32 oclk_en)if (oclk_en) rval |=SDXC_CARD_CLOCK_ON ; + start = jiffies; + end = start +msecs_to_jiffies (750 );mmc_writel (host,REG_CLKCR , rval); rval =SDXC_START |SDXC_UPCLK_ONLY |SDXC_WAIT_PRE_OVER ;
@@ -611,15 +613,29 @@ static int sunxi_mmc_oclk_onoff(struct sunxi_mmc_host *host, u32 oclk_en)do { rval =mmc_readl (host,REG_CMDR ); - }while (time_before (jiffies, expire) && (rval &SDXC_START )); + }while (time_before (jiffies, end) && (rval &SDXC_START )); + end = jiffies;/* clear irq status bits set by the command */ mmc_writel (host,REG_RINTR ,mmc_readl (host,REG_RINTR ) & ~SDXC_SDIO_INTERRUPT );if (rval &SDXC_START ) { -dev_err (mmc_dev (host->mmc),"fatal err update clk timeout\n" ); +dev_err (mmc_dev (host->mmc), +"fatal err update oclk timeout. Could not %s in %ims.\n" , + oclk_en ?"enable" :"disable" , +jiffies_to_msecs (end-start));return -EIO ; + }else { +int msecs =jiffies_to_msecs (end-start); +const char *ing = oclk_en ?"enabling" :"disabling" ; + +if ((msecs >150 ) || (oclk_en && (msecs >50 ))) +dev_warn (mmc_dev (host->mmc), +"%s oclk took %ims" , ing, msecs); +else +dev_dbg (mmc_dev (host->mmc), +"%s oclk took %ims" , ing, msecs); }return 0 ;
Signature · 1 line
2.1.4
Re: [linux-sunxi] [PATCH 1/2] mmc: sunxi: fix timeout in sunxi_mmc_oclk_onoff
Hi Michal,
Quoted 33 lines · Michal Suchanek
The 250ms timeout is too short.
On my system enabling the oclk takes under 50ms and disabling slightly over 100ms when idle. Under load disabling the clock can take over 350ms.
This does not make mmc clock gating look like good option to have on sunxi but the system should not crash with mmc clock gating enabled nonetheless.
This patch sets the timeout to 750ms and adds debug prints which show how long enabling/disabling the clock took so more data can be collected from other systems.
Signed-off-by Michal Suchanek <[email protected]>--- drivers/mmc/host/sunxi-mmc.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)drivers/mmc/host/sunxi-mmc.c +1
-1@@ -595,7 +595,7 @@ static irqreturn_t sunxi_mmc_handle_manual_stop(int irq, void *dev_id)static int sunxi_mmc_oclk_onoff (struct sunxi_mmc_host *host,u32 oclk_en) { -unsigned long expire = jiffies +msecs_to_jiffies (250 ); +unsigned long start, end;u32 rval; rval =mmc_readl (host,REG_CLKCR );
drivers/mmc/host/sunxi-mmc.c static int sunxi_mmc_oclk_onoff(struct sunxi_mmc_host *host, u32 oclk_en) · line 608
Quoted 5 lines
drivers/mmc/host/sunxi-mmc.c +2
-0@@ -604,6 +604,8 @@ static int sunxi_mmc_oclk_onoff(struct sunxi_mmc_host *host, u32 oclk_en)if (oclk_en) rval |=SDXC_CARD_CLOCK_ON ; + start = jiffies; + end = start +msecs_to_jiffies (750 );
You might want to make the timeout value a #define so it's not buried in the code like this.
Thanks,
Signature · 4 lines
Julian Calaby Email: julian.calaby at gmail.com Profile: http://www.google.com/profiles/julian.calaby/
Re: [PATCH 1/2] mmc: sunxi: fix timeout in sunxi_mmc_oclk_onoff
In reply to Michal SuchanekHi,
Quoted 10 lines · Michal Suchanek
The 250ms timeout is too short.
On my system enabling the oclk takes under 50ms and disabling slightly over 100ms when idle. Under load disabling the clock can take over 350ms.
This does not make mmc clock gating look like good option to have on sunxi but the system should not crash with mmc clock gating enabled nonetheless.
Quoted 5 lines
This patch sets the timeout to 750ms and adds debug prints which show how long enabling/disabling the clock took so more data can be collected from other systems.
Signed-off-by Michal Suchanek <[email protected]>
Looks good: Reviewed-by: Hans de Goede <[email protected]>
Regards,
Hans
Quoted 59 lines
--- drivers/mmc/host/sunxi-mmc.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)drivers/mmc/host/sunxi-mmc.c +19
-3@@ -595,7 +595,7 @@ static irqreturn_t sunxi_mmc_handle_manual_stop(int irq, void *dev_id)static int sunxi_mmc_oclk_onoff (struct sunxi_mmc_host *host,u32 oclk_en) { -unsigned long expire = jiffies +msecs_to_jiffies (250 ); +unsigned long start, end;u32 rval; rval =mmc_readl (host,REG_CLKCR );@@ -604,6 +604,8 @@ static int sunxi_mmc_oclk_onoff(struct sunxi_mmc_host *host, u32 oclk_en)if (oclk_en) rval |=SDXC_CARD_CLOCK_ON ; + start = jiffies; + end = start +msecs_to_jiffies (750 );mmc_writel (host,REG_CLKCR , rval); rval =SDXC_START |SDXC_UPCLK_ONLY |SDXC_WAIT_PRE_OVER ;@@ -611,15 +613,29 @@ static int sunxi_mmc_oclk_onoff(struct sunxi_mmc_host *host, u32 oclk_en)do { rval =mmc_readl (host,REG_CMDR ); - }while (time_before (jiffies, expire) && (rval &SDXC_START )); + }while (time_before (jiffies, end) && (rval &SDXC_START )); + end = jiffies;/* clear irq status bits set by the command */ mmc_writel (host,REG_RINTR ,mmc_readl (host,REG_RINTR ) & ~SDXC_SDIO_INTERRUPT );if (rval &SDXC_START ) { -dev_err (mmc_dev (host->mmc),"fatal err update clk timeout\n" ); +dev_err (mmc_dev (host->mmc), +"fatal err update oclk timeout. Could not %s in %ims.\n" , + oclk_en ?"enable" :"disable" , +jiffies_to_msecs (end-start));return -EIO ; + }else { +int msecs =jiffies_to_msecs (end-start); +const char *ing = oclk_en ?"enabling" :"disabling" ; + +if ((msecs >150 ) || (oclk_en && (msecs >50 ))) +dev_warn (mmc_dev (host->mmc), +"%s oclk took %ims" , ing, msecs); +else +dev_dbg (mmc_dev (host->mmc), +"%s oclk took %ims" , ing, msecs); }return 0 ;
Re: [PATCH 1/2] mmc: sunxi: fix timeout in sunxi_mmc_oclk_onoff
In reply to Michal SuchanekHi Michal,
The patch itself looks good, but there's a few style issues.
Quoted 49 lines · Michal Suchanek
The 250ms timeout is too short.
On my system enabling the oclk takes under 50ms and disabling slightly over 100ms when idle. Under load disabling the clock can take over 350ms.
This does not make mmc clock gating look like good option to have on sunxi but the system should not crash with mmc clock gating enabled nonetheless.
This patch sets the timeout to 750ms and adds debug prints which show how long enabling/disabling the clock took so more data can be collected from other systems.
Signed-off-by Michal Suchanek <[email protected]>--- drivers/mmc/host/sunxi-mmc.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)drivers/mmc/host/sunxi-mmc.c +5
-2@@ -595,7 +595,7 @@ static irqreturn_t sunxi_mmc_handle_manual_stop(int irq, void *dev_id)static int sunxi_mmc_oclk_onoff (struct sunxi_mmc_host *host,u32 oclk_en) { -unsigned long expire = jiffies +msecs_to_jiffies (250 ); +unsigned long start, end;u32 rval; rval =mmc_readl (host,REG_CLKCR );@@ -604,6 +604,8 @@ static int sunxi_mmc_oclk_onoff(struct sunxi_mmc_host *host, u32 oclk_en)if (oclk_en) rval |=SDXC_CARD_CLOCK_ON ; + start = jiffies; + end = start +msecs_to_jiffies (750 );mmc_writel (host,REG_CLKCR , rval); rval =SDXC_START |SDXC_UPCLK_ONLY |SDXC_WAIT_PRE_OVER ;@@ -611,15 +613,29 @@ static int sunxi_mmc_oclk_onoff(struct sunxi_mmc_host *host, u32 oclk_en)do { rval =mmc_readl (host,REG_CMDR ); - }while (time_before (jiffies, expire) && (rval &SDXC_START )); + }while (time_before (jiffies, end) && (rval &SDXC_START )); + end = jiffies;
drivers/mmc/host/sunxi-mmc.c static int sunxi_mmc_oclk_onoff(struct sunxi_mmc_host *host, u32 oclk_en) · line 627
Quoted 10 lines
drivers/mmc/host/sunxi-mmc.c +4
-1/* clear irq status bits set by the command */ mmc_writel (host,REG_RINTR ,mmc_readl (host,REG_RINTR ) & ~SDXC_SDIO_INTERRUPT );if (rval &SDXC_START ) { -dev_err (mmc_dev (host->mmc),"fatal err update clk timeout\n" ); +dev_err (mmc_dev (host->mmc), +"fatal err update oclk timeout. Could not %s in %ims.\n" , + oclk_en ?"enable" :"disable" , +jiffies_to_msecs (end-start));
You should have spaces around that operator.
drivers/mmc/host/sunxi-mmc.c static int sunxi_mmc_oclk_onoff(struct sunxi_mmc_host *host, u32 oclk_en) · line 630
Quoted 3 lines
drivers/mmc/host/sunxi-mmc.c +2
-0return -EIO ; + }else { +int msecs =jiffies_to_msecs (end-start);
Ditto.
drivers/mmc/host/sunxi-mmc.c static int sunxi_mmc_oclk_onoff(struct sunxi_mmc_host *host, u32 oclk_en) · line 638
Quoted 8 lines
drivers/mmc/host/sunxi-mmc.c +8
-0+const char *ing = oclk_en ?"enabling" :"disabling" ; + +if ((msecs >150 ) || (oclk_en && (msecs >50 ))) +dev_warn (mmc_dev (host->mmc), +"%s oclk took %ims" , ing, msecs); +else +dev_dbg (mmc_dev (host->mmc), +"%s oclk took %ims" , ing, msecs);
And this should be aligned with the opening parenthesis.
Thanks!
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150525/989fadfb/attachment.sig>
PATCH 2/2 mmc: sunxi: Also set SDXC_LOW_POWER_ON
In reply to Michal SuchanekThe function sunxi_mmc_oclk_onoff filters out the SDXC_LOW_POWER_ON flag but never sets it.
Set SDXC_LOW_POWER_ON when oclk is disabled.
--- drivers/mmc/host/sunxi-mmc.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/mmc/host/sunxi-mmc.c +2 -0
@@ -603,6 +603,8 @@ static int sunxi_mmc_oclk_onoff(struct sunxi_mmc_host *host, u32 oclk_en)if (oclk_en) rval |=SDXC_CARD_CLOCK_ON ; +else + rval |=SDXC_LOW_POWER_ON ; start = jiffies; end = start +msecs_to_jiffies (750 );
Signature · 1 line
2.1.4
Hans de Goede
NAKRe: [PATCH 2/2] mmc: sunxi: Also set SDXC_LOW_POWER_ON
Hi,
Quoted 4 lines · Michal Suchanek
The function
sunxi_mmc_oclk_onofffilters out theSDXC_LOW_POWER_ONflag but never sets it.Set
SDXC_LOW_POWER_ONwhen oclk is disabled.
Nack, looking at the datasheet I do not thing this patch actually does anything, according to the datasheet setting this bit to 1 results
in: "Turn off card clock when FSM in IDLE state", iow this does mmc clock gating on idle automatically in hardware, since we completely disable the clock on clock-off by clearing SDXC_CARD_CLOCK_ON setting this bit on clock-off is a nop.
We could consider actually setting this to safe power when setting the clock on, for doing that it would be good to look at the android code and see if it ever sets this bit and if so when.
WRT CONFIG_MMC_CLKGATE we are probably better off using SDXC_LOW_POWER_ON then that when it is enabled. So maybe we should set SDXC_LOW_POWER_ON based on #ifdef WRT CONFIG_MMC_CLKGATE, and have some way to tell the mmc core to not do clock gating on this host ?
Regards,
Hans
Quoted 20 lines
Signed-off-by Michal Suchanek <[email protected]>--- drivers/mmc/host/sunxi-mmc.c | 2 ++ 1 file changed, 2 insertions(+)drivers/mmc/host/sunxi-mmc.c +2
-0@@ -603,6 +603,8 @@ static int sunxi_mmc_oclk_onoff(struct sunxi_mmc_host *host, u32 oclk_en)if (oclk_en) rval |=SDXC_CARD_CLOCK_ON ; +else + rval |=SDXC_LOW_POWER_ON ; start = jiffies; end = start +msecs_to_jiffies (750 );
Re: [PATCH 2/2] mmc: sunxi: Also set SDXC_LOW_POWER_ON
Quoted 17 lines · Hans de Goede
Hi,
Quoted 5 lines · Michal Suchanek
The function
sunxi_mmc_oclk_onofffilters out theSDXC_LOW_POWER_ONflag but never sets it.Set
SDXC_LOW_POWER_ONwhen oclk is disabled.Nack, looking at the datasheet I do not thing this patch actually does anything, according to the datasheet setting this bit to 1 results
in: "Turn off card clock when FSM in IDLE state", iow this does mmc clock gating on idle automatically in hardware, since we completely disable the clock on clock-off by clearingSDXC_CARD_CLOCK_ONsetting this bit on clock-off is a nop.
Quoted 8 lines
We could consider actually setting this to safe power when setting the clock on, for doing that it would be good to look at the android code and see if it ever sets this bit and if so when.
WRT
CONFIG_MMC_CLKGATEwe are probably better off usingSDXC_LOW_POWER_ONthen that when it is enabled. So maybe we should setSDXC_LOW_POWER_ONbased on #ifdef WRTCONFIG_MMC_CLKGATE, and have some way to tell the mmc core to not do clock gating on this host ?
I am planning to remove the entire thing for CONFIG_MMC_CLKGATE, maybe it's time to do that now!?
Most hosts use runtime PM to deal with clock gating at idle and browsing def configs tells me that CONFIG_MMC_CLKGATE isn't much used.
Kind regards
Uffe
Re: [PATCH 2/2] mmc: sunxi: Also set SDXC_LOW_POWER_ON
Hi,
Quoted 22 lines · Ulf Hansson
Quoted 21 lines · Hans de Goede
Hi,
Quoted 5 lines · Michal Suchanek
The function
sunxi_mmc_oclk_onofffilters out theSDXC_LOW_POWER_ONflag but never sets it.Set
SDXC_LOW_POWER_ONwhen oclk is disabled.Nack, looking at the datasheet I do not thing this patch actually does anything, according to the datasheet setting this bit to 1 results
in: "Turn off card clock when FSM in IDLE state", iow this does mmc clock gating on idle automatically in hardware, since we completely disable the clock on clock-off by clearingSDXC_CARD_CLOCK_ONsetting this bit on clock-off is a nop.We could consider actually setting this to safe power when setting the clock on, for doing that it would be good to look at the android code and see if it ever sets this bit and if so when.
Quoted 7 lines
Quoted 4 lines
WRT
CONFIG_MMC_CLKGATEwe are probably better off usingSDXC_LOW_POWER_ONthen that when it is enabled. So maybe we should setSDXC_LOW_POWER_ONbased on #ifdef WRTCONFIG_MMC_CLKGATE, and have some way to tell the mmc core to not do clock gating on this host ?I am planning to remove the entire thing for
CONFIG_MMC_CLKGATE, maybe it's time to do that now!?
Removing it now sounds like a good plan to me, we would still need to look into maybe enabling SDXC_LOW_POWER_ON on sunxi in some cases to save power, but that is an orthogonal problem.
Regards,
Hans