diff mbox series

[U-Boot,1/2] mmc: Fix timeout values passed to mmc_wait_dat0()

Message ID 20190814195251.14208-1-semen.protsenko@linaro.org
State Accepted
Commit 116cffeca6fe4de701d4cd5e2b5bfe5e0f1597a9
Delegated to: Peng Fan
Headers show
Series [U-Boot,1/2] mmc: Fix timeout values passed to mmc_wait_dat0() | expand

Commit Message

Sam Protsenko Aug. 14, 2019, 7:52 p.m. UTC
mmc_wait_dat0() expects timeout argument to be in usec units. But some
overlying functions operate on timeout in msec units. Convert timeout
from msec to usec when passing it to mmc_wait_dat0().

This fixes 'avb' commands on BeagleBoard X15, because next chain was
failing:

    get_partition() -> mmc_switch_part() -> __mmc_switch() ->
    mmc_wait_dat0()

when passing incorrect timeout from __mmc_switch() to mmc_wait_dat0().

Fixes: bb98b8c5c06a ("mmc: During a switch, poll on dat0 if available and check the final status")
Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
---
 drivers/mmc/mmc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Eugeniu Rosca Aug. 16, 2019, 4:17 p.m. UTC | #1
Hi Sam,

CC: Peng

On Wed, Aug 14, 2019 at 10:52:50PM +0300, Sam Protsenko wrote:
> mmc_wait_dat0() expects timeout argument to be in usec units.

I agree, based on the documentation of wait_dat0() from commit:
https://gitlab.denx.de/u-boot/u-boot/commit/c10b85d6c25f9#5a47a9a1803c0a873c9ec4b91ce244822405d1ec_413_436

> But some
> overlying functions operate on timeout in msec units.

That seems to be also true. The two functions touched in this commit
(mmc_poll_for_busy, __mmc_switch) seem to originate from Linux, where
they clearly accept MS timeout granularity [1-2].

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=716bdb8953c7c
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f90d2e4035d45

> Convert timeout
> from msec to usec when passing it to mmc_wait_dat0().

I've reviewed all the callers of mmc_wait_dat0() and I couldn't find any
other occurrences of passing MS values to this function.

I've run 'ext2load mmc 0:1 0x48000000 Image' several times on
H3-Salvator-X w/o noticing any issues.

I agree with the idea of s/timeout/timeout_{us,ms}/ in the second patch
from this series.

> 
> This fixes 'avb' commands on BeagleBoard X15, because next chain was
> failing:
> 
>     get_partition() -> mmc_switch_part() -> __mmc_switch() ->
>     mmc_wait_dat0()
> 
> when passing incorrect timeout from __mmc_switch() to mmc_wait_dat0().
> 
> Fixes: bb98b8c5c06a ("mmc: During a switch, poll on dat0 if available and check the final status")
> Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>

Reviewed-by: Eugeniu Rosca <rosca.eugeniu@gmail.com>
Tested-by: Eugeniu Rosca <rosca.eugeniu@gmail.com>
Peng Fan Aug. 19, 2019, 1:55 a.m. UTC | #2
> Subject: [PATCH 1/2] mmc: Fix timeout values passed to mmc_wait_dat0()
> 
> mmc_wait_dat0() expects timeout argument to be in usec units. But some
> overlying functions operate on timeout in msec units. Convert timeout from
> msec to usec when passing it to mmc_wait_dat0().
> 
> This fixes 'avb' commands on BeagleBoard X15, because next chain was
> failing:
> 
>     get_partition() -> mmc_switch_part() -> __mmc_switch() ->
>     mmc_wait_dat0()
> 
> when passing incorrect timeout from __mmc_switch() to mmc_wait_dat0().
> 
> Fixes: bb98b8c5c06a ("mmc: During a switch, poll on dat0 if available and
> check the final status")
> Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
> ---
>  drivers/mmc/mmc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index
> eecc7d687e..e247730ff2 100644
> --- a/drivers/mmc/mmc.c
> +++ b/drivers/mmc/mmc.c
> @@ -235,7 +235,7 @@ int mmc_poll_for_busy(struct mmc *mmc, int
> timeout)
>  	unsigned int status;
>  	int err;
> 
> -	err = mmc_wait_dat0(mmc, 1, timeout);
> +	err = mmc_wait_dat0(mmc, 1, timeout * 1000);
>  	if (err != -ENOSYS)
>  		return err;
> 
> @@ -778,7 +778,7 @@ static int __mmc_switch(struct mmc *mmc, u8 set,
> u8 index, u8 value,
>  	start = get_timer(0);
> 
>  	/* poll dat0 for rdy/buys status */
> -	ret = mmc_wait_dat0(mmc, 1, timeout);
> +	ret = mmc_wait_dat0(mmc, 1, timeout * 1000);
>  	if (ret && ret != -ENOSYS)
>  		return ret;
> 

Reviewed-by: Peng Fan <peng.fan@nxp.com>

> --
> 2.20.1
Igor Opaniuk Aug. 19, 2019, 8:57 a.m. UTC | #3
Hi Sam,
So you finally found it :)

On Wed, Aug 14, 2019 at 10:52 PM Sam Protsenko
<semen.protsenko@linaro.org> wrote:
>
> mmc_wait_dat0() expects timeout argument to be in usec units. But some
> overlying functions operate on timeout in msec units. Convert timeout
> from msec to usec when passing it to mmc_wait_dat0().
>
> This fixes 'avb' commands on BeagleBoard X15, because next chain was
> failing:
>
>     get_partition() -> mmc_switch_part() -> __mmc_switch() ->
>     mmc_wait_dat0()
>
> when passing incorrect timeout from __mmc_switch() to mmc_wait_dat0().
>
> Fixes: bb98b8c5c06a ("mmc: During a switch, poll on dat0 if available and check the final status")
> Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
> ---
>  drivers/mmc/mmc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
> index eecc7d687e..e247730ff2 100644
> --- a/drivers/mmc/mmc.c
> +++ b/drivers/mmc/mmc.c
> @@ -235,7 +235,7 @@ int mmc_poll_for_busy(struct mmc *mmc, int timeout)
>         unsigned int status;
>         int err;
>
> -       err = mmc_wait_dat0(mmc, 1, timeout);
> +       err = mmc_wait_dat0(mmc, 1, timeout * 1000);
>         if (err != -ENOSYS)
>                 return err;
>
> @@ -778,7 +778,7 @@ static int __mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value,
>         start = get_timer(0);
>
>         /* poll dat0 for rdy/buys status */
> -       ret = mmc_wait_dat0(mmc, 1, timeout);
> +       ret = mmc_wait_dat0(mmc, 1, timeout * 1000);
>         if (ret && ret != -ENOSYS)
>                 return ret;
>
> --
> 2.20.1
>

Tested-by: Igor Opaniuk <igor.opaniuk@gmail.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>
Peng Fan Aug. 27, 2019, 7:40 a.m. UTC | #4
> Subject: [PATCH 1/2] mmc: Fix timeout values passed to mmc_wait_dat0()
> 
> mmc_wait_dat0() expects timeout argument to be in usec units. But some
> overlying functions operate on timeout in msec units. Convert timeout from
> msec to usec when passing it to mmc_wait_dat0().
> 
> This fixes 'avb' commands on BeagleBoard X15, because next chain was
> failing:
> 
>     get_partition() -> mmc_switch_part() -> __mmc_switch() ->
>     mmc_wait_dat0()
> 
> when passing incorrect timeout from __mmc_switch() to mmc_wait_dat0().
> 
> Fixes: bb98b8c5c06a ("mmc: During a switch, poll on dat0 if available and
> check the final status")
> Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>

Applied to mmc/master.

Thanks,
Peng.
Sam Protsenko Aug. 29, 2019, 7:21 p.m. UTC | #5
Hi Peng,

On Tue, Aug 27, 2019 at 10:40 AM Peng Fan <peng.fan@nxp.com> wrote:
>
> > Subject: [PATCH 1/2] mmc: Fix timeout values passed to mmc_wait_dat0()
> >
> > mmc_wait_dat0() expects timeout argument to be in usec units. But some
> > overlying functions operate on timeout in msec units. Convert timeout from
> > msec to usec when passing it to mmc_wait_dat0().
> >
> > This fixes 'avb' commands on BeagleBoard X15, because next chain was
> > failing:
> >
> >     get_partition() -> mmc_switch_part() -> __mmc_switch() ->
> >     mmc_wait_dat0()
> >
> > when passing incorrect timeout from __mmc_switch() to mmc_wait_dat0().
> >
> > Fixes: bb98b8c5c06a ("mmc: During a switch, poll on dat0 if available and
> > check the final status")
> > Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
>
> Applied to mmc/master.
>

Thanks for taking care of this. Quick question: does it mean that this
patch will find its way to v2019.10? Because this patch is a bug fix
to me (it actually fixes AVB, which doesn't work at all right now).

Thanks!

> Thanks,
> Peng.
Peng Fan Aug. 30, 2019, 1:11 a.m. UTC | #6
> Subject: Re: [PATCH 1/2] mmc: Fix timeout values passed to mmc_wait_dat0()
> 
> Hi Peng,
> 
> On Tue, Aug 27, 2019 at 10:40 AM Peng Fan <peng.fan@nxp.com> wrote:
> >
> > > Subject: [PATCH 1/2] mmc: Fix timeout values passed to
> > > mmc_wait_dat0()
> > >
> > > mmc_wait_dat0() expects timeout argument to be in usec units. But
> > > some overlying functions operate on timeout in msec units. Convert
> > > timeout from msec to usec when passing it to mmc_wait_dat0().
> > >
> > > This fixes 'avb' commands on BeagleBoard X15, because next chain was
> > > failing:
> > >
> > >     get_partition() -> mmc_switch_part() -> __mmc_switch() ->
> > >     mmc_wait_dat0()
> > >
> > > when passing incorrect timeout from __mmc_switch() to
> mmc_wait_dat0().
> > >
> > > Fixes: bb98b8c5c06a ("mmc: During a switch, poll on dat0 if
> > > available and check the final status")
> > > Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
> >
> > Applied to mmc/master.
> >
> 
> Thanks for taking care of this. Quick question: does it mean that this patch will
> find its way to v2019.10? Because this patch is a bug fix to me (it actually fixes
> AVB, which doesn't work at all right now).

Yes. It will land in 2019.10, I'll send pull request to Tom later.

Regards,
Peng.

> 
> Thanks!
> 
> > Thanks,
> > Peng.
diff mbox series

Patch

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index eecc7d687e..e247730ff2 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -235,7 +235,7 @@  int mmc_poll_for_busy(struct mmc *mmc, int timeout)
 	unsigned int status;
 	int err;
 
-	err = mmc_wait_dat0(mmc, 1, timeout);
+	err = mmc_wait_dat0(mmc, 1, timeout * 1000);
 	if (err != -ENOSYS)
 		return err;
 
@@ -778,7 +778,7 @@  static int __mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value,
 	start = get_timer(0);
 
 	/* poll dat0 for rdy/buys status */
-	ret = mmc_wait_dat0(mmc, 1, timeout);
+	ret = mmc_wait_dat0(mmc, 1, timeout * 1000);
 	if (ret && ret != -ENOSYS)
 		return ret;