Skip to contentSkip to conversation

mmc: dw_mmc: fix timeout calculate method

PATCH New Kever Yang 4 participants 11 messages Aug 14, 2019 – Sep 3, 2019

Subsystems (2)
lore
Share & tools
lore

Kever Yang

author
#0 lore raw

PATCH 1/1 mmc: dw_mmc: fix timeout calculate method

There are two cases not been considered:
- use uint for timeout, it will overflow when size bigger than 512KB for it *8*1000 at the beginning, but we may use size up to 32MB;
- The timeout is using clock speed for data rate, but the device may not have such high speed, eg. clock is 52MHz while the device write speed may be less than 10MB/s.

Fix them in this patch, the max timeout is about 6500 when size is 32MB after fix.

---

 drivers/mmc/dw_mmc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mmc/dw_mmc.c +3 -3
index 22f6c7eefd..2cb61ba184 100644
@@ -117,10 +117,10 @@ static int dwmci_fifo_ready(struct dwmci_host *host, u32 bit, u32 *len)
 
 static unsigned int dwmci_get_timeout(struct mmc *mmc, const unsigned int size)
 {
-	unsigned int timeout;
+	u64 timeout;
 
-	timeout = size * 8 * 1000;	/* counting in bits and msec */
-	timeout *= 2;			/* wait twice as long */
+	timeout = (u64)size * 8 * 1000;	/* counting in bits and msec */
+	timeout *= 10;			/* wait 10 times as long */
 	timeout /= mmc->clock;
 	timeout /= mmc->bus_width;
 	timeout /= mmc->ddr_mode ? 2 : 1;
Signature · 1 line
2.17.1
Applied
#1 lore raw

PATCH 1/1 mmc: dw_mmc: fix timeout calculate method

Quoted 9 lines

Subject: [PATCH] mmc: dw_mmc: fix timeout calculate method

There are two cases not been considered:
- use uint for timeout, it will overflow when size bigger than 512KB for it *8*1000 at the beginning, but we may use size up to 32MB;
- The timeout is using clock speed for data rate, but the device may not have such high speed, eg. clock is 52MHz while the device write speed may be less than 10MB/s.

Quoted 4 lines

Fix them in this patch, the max timeout is about 6500 when size is 32MB after fix.

Applied to mmc/master.

Thanks,
Peng.

#2 lore raw

PATCH 1/1 mmc: dw_mmc: fix timeout calculate method

Hi Kever,

Quoted 7 lines

-----Original Message-----
From: U-Boot <[email protected]> On Behalf Of Peng Fan
Sent: 2019年8月27日 15:40
To: Kever Yang <[email protected]>; u-boot at lists.denx.de
Cc: trini at konsulko.com
Subject: Re: [U-Boot] [PATCH] mmc: dw_mmc: fix timeout calculate method

Quoted 14 lines
Quoted 7 lines

Subject: [PATCH] mmc: dw_mmc: fix timeout calculate method

There are two cases not been considered:
- use uint for timeout, it will overflow when size bigger than 512KB for it *8*1000 at the beginning, but we may use size up to 32MB;
- The timeout is using clock speed for data rate, but the device may not have such high speed, eg. clock is 52MHz while the device write speed

may

Quoted 6 lines

be less than 10MB/s.

Fix them in this patch, the max timeout is about 6500 when size is 32MB after fix.

This patch breaks build, I need drop it.
See build:
https://travis-ci.org/MrVan/u-boot/jobs/577210464

Regards,
Peng.

Quoted 13 lines

Applied to mmc/master.

Thanks,
Peng.
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.d
enx.de%2Flistinfo%2Fu-boot&amp;data=02%7C01%7CPeng.Fan%40nxp.com %7Cec929026da5f42951b6108d72ac1c446%7C686ea1d3bc2b4c6fa92cd99c 5c301635%7C0%7C0%7C637024884027193189&amp;sdata=SPBna8IBqgpo9 %2F6ab1YO5sbpX6NGgkCowt0oLclRHEk%3D&amp;reserved=0

author
#3 lore raw

PATCH 1/1 mmc: dw_mmc: fix timeout calculate method

Add ARC maintainers.

Quoted 19 lines · Peng Fan

Hi Kever,

Quoted 17 lines

-----Original Message-----
From: U-Boot <[email protected]> On Behalf Of Peng Fan
Sent: 2019年8月27日 15:40
To: Kever Yang <[email protected]>; u-boot at lists.denx.de
Cc: trini at konsulko.com
Subject: Re: [U-Boot] [PATCH] mmc: dw_mmc: fix timeout calculate method

Quoted 7 lines

Subject: [PATCH] mmc: dw_mmc: fix timeout calculate method

There are two cases not been considered:
- use uint for timeout, it will overflow when size bigger than 512KB for it *8*1000 at the beginning, but we may use size up to 32MB;
- The timeout is using clock speed for data rate, but the device may not have such high speed, eg. clock is 52MHz while the device write speed

may

Quoted 2 lines

be less than 10MB/s.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

Fix them in this patch, the max timeout is about 6500 when size is 32MB after fix.

This patch breaks build, I need drop it.
See build:
https://travis-ci.org/MrVan/u-boot/jobs/577210464

The error happens only in ARC architecture, and seems like the arc compiler not support

64bit div?

Any idea on how to fix this?

Thanks,
- Kever

Quoted 16 lines

Regards,
Peng.

Quoted 12 lines

Applied to mmc/master.

Thanks,
Peng.
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.d
enx.de%2Flistinfo%2Fu-boot&amp;data=02%7C01%7CPeng.Fan%40nxp.com %7Cec929026da5f42951b6108d72ac1c446%7C686ea1d3bc2b4c6fa92cd99c 5c301635%7C0%7C0%7C637024884027193189&amp;sdata=SPBna8IBqgpo9 %2F6ab1YO5sbpX6NGgkCowt0oLclRHEk%3D&amp;reserved=0

#4 lore raw

PATCH 1/1 mmc: dw_mmc: fix timeout calculate method

Hi Kever,

Quoted 9 lines

-----Original Message-----
From: Kever Yang <[email protected]>
Sent: Thursday, August 29, 2019 10:17 AM
To: Peng Fan <[email protected]>; u-boot at lists.denx.de
Cc: trini at konsulko.com; Eugeniy.Paltsev at synopsys.com; Alexey Brodkin <[email protected]>; Simon Glass <[email protected]>
Subject: Re: [PATCH] mmc: dw_mmc: fix timeout calculate method

Add ARC maintainers.

Thanks for adding us in the loop.

Quoted 23 lines · Peng Fan
Quoted 22 lines

Hi Kever,

Quoted 20 lines

-----Original Message-----
From: U-Boot <[email protected]> On Behalf Of Peng Fan
Sent: 2019年8月27日 15:40
To: Kever Yang <[email protected]>; u-boot at lists.denx.de
Cc: trini at konsulko.com
Subject: Re: [U-Boot] [PATCH] mmc: dw_mmc: fix timeout calculate method

Quoted 7 lines

Subject: [PATCH] mmc: dw_mmc: fix timeout calculate method

There are two cases not been considered:
- use uint for timeout, it will overflow when size bigger than 512KB for it *8*1000 at the beginning, but we may use size up to 32MB;
- The timeout is using clock speed for data rate, but the device may not have such high speed, eg. clock is 52MHz while the device write speed

may

Quoted 5 lines

be less than 10MB/s.

Fix them in this patch, the max timeout is about 6500 when size is 32MB after fix.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

This patch breaks build, I need drop it.
See build:
https://travis-ci.org/MrVan/u-boot/jobs/577210464

The error happens only in ARC architecture, and seems like the arc compiler not support 64bit div?

It's not a compiler problem but a subtle issue with libgcc.
To be independent from toolchain type (and we have quite a few flavors like little- and big-endian, ARCv1 or ARCv2 etc) decision was made to move libgcc into U-Boot but given full libgcc is quite large only primitives required by up-to-date U-Boot were copied from GCC to U-Boot.

Quoted 1 line

Any idea on how to fix this?

Add missing primitives like __udivdi3() and their dependencies, see for example:
https://github.com/gcc-mirror/gcc/blob/master/libgcc/libgcc2.c#L1318.

And I'll happily do it myself but for some reason I cannot reproduce that problem locally. I use the same pre-built arc-2018.09 toolchain:
---------------------------->8-----------------------

# arc-linux-gcc -v
gcc version 8.2.1 20180814 (ARCv2 ISA Linux uClibc toolchain 2018.09)
---------------------------->8-----------------------

And may successfully build U-Boot for HSDK from
https://github.com/MrVan/u-boot/commits/mmc-8-28-2019:
---------------------------->8-----------------------

# git l
76c0bf2873 - (HEAD -> mrvan, github-mrvan/mmc-8-28-2019) ARM: dts: ast2500: Add SDHCI nodes (27 hours ago) <Eddie James>
07b000cd32 - configs: AST2500 EVB: Enable SD controller (27 hours ago) <Eddie James>
5f6a033f10 - mmc: Add Aspeed SD controller driver (27 hours ago) <Eddie James>
a6503eaa66 - clk: aspeed: Add support for SD clock (27 hours ago) <Eddie James>
c54e328452 - mmc: Rename timeout parameters for clarification (27 hours ago) <Sam Protsenko>
be949bb19c - mmc: Fix timeout values passed to mmc_wait_dat0() (27 hours ago) <Sam Protsenko>
49842f0edf - dm: mmc: remove unused U_BOOT_DRIVER(mmc) (27 hours ago) <Andy Yan>
7b91b47f8f - Prepare v2019.10-rc3 (27 hours ago) <Tom Rini>
---------------------------->8-----------------------

That way:
---------------------------->8----------------------- ./tools/buildman/buildman hsdk
boards.cfg is up to date. Nothing to do.
Building current source for 1 boards (1 thread, 48 jobs per thread)
arc: w+ hsdk
0 1 0 /1 hsdk
---------------------------->8-----------------------

What do I do wrong?

-Alexey

author
#5 lore raw

PATCH 1/1 mmc: dw_mmc: fix timeout calculate method

Hi Alexey,

Quoted 62 lines · Alexey Brodkin

Hi Kever,

Quoted 9 lines

-----Original Message-----
From: Kever Yang <[email protected]>
Sent: Thursday, August 29, 2019 10:17 AM
To: Peng Fan <[email protected]>; u-boot at lists.denx.de
Cc: trini at konsulko.com; Eugeniy.Paltsev at synopsys.com; Alexey Brodkin <[email protected]>; Simon Glass <[email protected]>
Subject: Re: [PATCH] mmc: dw_mmc: fix timeout calculate method

Add ARC maintainers.

Thanks for adding us in the loop.

Quoted 23 lines · Peng Fan
Quoted 22 lines

Hi Kever,

Quoted 20 lines

-----Original Message-----
From: U-Boot <[email protected]> On Behalf Of Peng Fan
Sent: 2019年8月27日 15:40
To: Kever Yang <[email protected]>; u-boot at lists.denx.de
Cc: trini at konsulko.com
Subject: Re: [U-Boot] [PATCH] mmc: dw_mmc: fix timeout calculate method

Quoted 7 lines

Subject: [PATCH] mmc: dw_mmc: fix timeout calculate method

There are two cases not been considered:
- use uint for timeout, it will overflow when size bigger than 512KB for

    it *8*1000 at the beginning, but we may use size up to 32MB;

- The timeout is using clock speed for data rate, but the device may not have such high speed, eg. clock is 52MHz while the device write speed

may

Quoted 5 lines

be less than 10MB/s.

Fix them in this patch, the max timeout is about 6500 when size is 32MB after fix.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

This patch breaks build, I need drop it.
See build:
https://travis-ci.org/MrVan/u-boot/jobs/577210464

The error happens only in ARC architecture, and seems like the arc compiler not support 64bit div?

It's not a compiler problem but a subtle issue with libgcc.
To be independent from toolchain type (and we have quite a few flavors like little- and big-endian, ARCv1 or ARCv2 etc) decision was made to move libgcc into U-Boot but given full libgcc is quite large only primitives required by up-to-date U-Boot were copied from GCC to U-Boot.

Quoted 1 line

Any idea on how to fix this?

Add missing primitives like __udivdi3() and their dependencies, see for example:
https://github.com/gcc-mirror/gcc/blob/master/libgcc/libgcc2.c#L1318.

And I'll happily do it myself but for some reason I cannot reproduce that problem locally. I use the same pre-built arc-2018.09 toolchain:
---------------------------->8-----------------------

# arc-linux-gcc -v
gcc version 8.2.1 20180814 (ARCv2 ISA Linux uClibc toolchain 2018.09)
---------------------------->8-----------------------

And may successfully build U-Boot for HSDK from
https://github.com/MrVan/u-boot/commits/mmc-8-28-2019:
---------------------------->8-----------------------

Quoted 10 lines
# git l
76c0bf2873 - (HEAD -> mrvan, github-mrvan/mmc-8-28-2019) ARM: dts: ast2500: Add SDHCI nodes (27 hours ago) <Eddie James>
07b000cd32 - configs: AST2500 EVB: Enable SD controller (27 hours ago) <Eddie James>
5f6a033f10 - mmc: Add Aspeed SD controller driver (27 hours ago) <Eddie James>
a6503eaa66 - clk: aspeed: Add support for SD clock (27 hours ago) <Eddie James>
c54e328452 - mmc: Rename timeout parameters for clarification (27 hours ago) <Sam Protsenko>
be949bb19c - mmc: Fix timeout values passed to mmc_wait_dat0() (27 hours ago) <Sam Protsenko>
49842f0edf - dm: mmc: remove unused U_BOOT_DRIVER(mmc) (27 hours ago) <Andy Yan>
7b91b47f8f - Prepare v2019.10-rc3 (27 hours ago) <Tom Rini>
---------------------------->8-----------------------

I think this tree does not including this patch, Peng drop it because of this issue,
so you need to apply this patch in your branch to reproduce the problem. I have send out V2 patch for this fix with only using 32bit variable instead of 64bit.

Thanks,
- Kever

Quoted 15 lines

That way:
---------------------------->8----------------------- ./tools/buildman/buildman hsdk
boards.cfg is up to date. Nothing to do.
Building current source for 1 boards (1 thread, 48 jobs per thread)
arc: w+ hsdk
0 1 0 /1 hsdk
---------------------------->8-----------------------

What do I do wrong?

-Alexey

#6 lore raw

PATCH 1/1 mmc: dw_mmc: fix timeout calculate method

Hi Kever,

[snip]

Quoted 4 lines

I think this tree does not including this patch, Peng drop it because of this issue,
so you need to apply this patch in your branch to reproduce the problem. I have send out V2 patch for this fix with only using 32bit variable

Could you please refer me to the problematic patch so I may try it?

-Alexey

author
#7 lore raw

PATCH 1/1 mmc: dw_mmc: fix timeout calculate method

Hi Alexey,

Quoted 9 lines · Alexey Brodkin

Hi Kever,

[snip]

Quoted 4 lines

I think this tree does not including this patch, Peng drop it because of this issue,
so you need to apply this patch in your branch to reproduce the problem. I have send out V2 patch for this fix with only using 32bit variable

Could you please refer me to the problematic patch so I may try it?

This is the patch with problem, and here is the link on patchwork:
https://patchwork.ozlabs.org/patch/1146845/

Thanks,
- Kever

Quoted 2 lines

-Alexey

#8 lore raw

PATCH 1/1 mmc: dw_mmc: fix timeout calculate method

Hi Kever,

Quoted 15 lines

-----Original Message-----
From: Kever Yang <kever.yang at rock-chips.com>
Sent: Monday, September 2, 2019 11:05 AM
To: Alexey Brodkin <abrodkin at synopsys.com>
Cc: trini at konsulko.com; Eugeniy.Paltsev at synopsys.com; Simon Glass <sjg at chromium.org>; Peng Fan <peng.fan at nxp.com>; u-boot at lists.denx.de
Subject: Re: [PATCH] mmc: dw_mmc: fix timeout calculate method

Hi Alexey,

Quoted 4 lines · Alexey Brodkin

Hi Kever,

[snip]

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

I think this tree does not including this patch, Peng drop it because of this issue,
so you need to apply this patch in your branch to reproduce the problem. I have send out V2 patch for this fix with only using 32bit variable

Could you please refer me to the problematic patch so I may try it?

This is the patch with problem, and here is the link on patchwork:
https://patchwork.ozlabs.org/patch/1146845/

Please find my fixes here:
https://patchwork.ozlabs.org/patch/1156541/
https://patchwork.ozlabs.org/patch/1156617/

Tom do we want https://patchwork.ozlabs.org/patch/1146845/ and fixes for it (see 2 items above) to become a part of upcoming v2019.10 release or it will be slated for the next one?

-Alexey

#9 lore raw

PATCH 1/1 mmc: dw_mmc: fix timeout calculate method

Quoted 26 lines · Alexey Brodkin

Hi Kever,

Quoted 15 lines

-----Original Message-----
From: Kever Yang <kever.yang at rock-chips.com>
Sent: Monday, September 2, 2019 11:05 AM
To: Alexey Brodkin <abrodkin at synopsys.com>
Cc: trini at konsulko.com; Eugeniy.Paltsev at synopsys.com; Simon Glass <sjg at chromium.org>; Peng Fan <peng.fan at nxp.com>; u-boot at lists.denx.de
Subject: Re: [PATCH] mmc: dw_mmc: fix timeout calculate method

Hi Alexey,

Quoted 4 lines · Alexey Brodkin

Hi Kever,

[snip]

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

I think this tree does not including this patch, Peng drop it because of this issue,
so you need to apply this patch in your branch to reproduce the problem. I have send out V2 patch for this fix with only using 32bit variable

Could you please refer me to the problematic patch so I may try it?

This is the patch with problem, and here is the link on patchwork:
https://patchwork.ozlabs.org/patch/1146845/

Quoted 7 lines

Please find my fixes here:
https://patchwork.ozlabs.org/patch/1156541/
https://patchwork.ozlabs.org/patch/1156617/

Tom do we want https://patchwork.ozlabs.org/patch/1146845/ and fixes for it (see 2 items above) to become a part of upcoming v2019.10 release or it will be slated for the next one?

I think we should aim to get all the fixes in for this release.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-snps-arc/attachments/20190902/fa7d4fa2/attachment.sig>
#10 lore raw

PATCH 1/1 mmc: dw_mmc: fix timeout calculate method

H Tom,

[snip]

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

This is the patch with problem, and here is the link on patchwork:
https://patchwork.ozlabs.org/patch/1146845/

Please find my fixes here:
https://patchwork.ozlabs.org/patch/1156541/
https://patchwork.ozlabs.org/patch/1156617/

Quoted 5 lines
Quoted 3 lines

Tom do we want https://patchwork.ozlabs.org/patch/1146845/ and fixes for it (see 2 items above) to become a part of upcoming v2019.10 release or it will be slated for the next one?

I think we should aim to get all the fixes in for this release.

Done, see https://lists.denx.de/pipermail/u-boot/2019-September/382628.html

-Alexey