Subject: [PATCH 1/1] mmc: Some microSD cards are not recognized by PCIxx12 SDA controller

From: Jos? M. Fern?ndez <[email protected]>

My working laptop is a Toshiba Tecra M5 with Core2 Duo T7400 and 2GB of
memory. Since I'm using it I have found that some microSD cards (using
their size adapter) are not recognized when they are inserted in the
Tecra M5 SD slot. Now I own one of those cards (a Transcend 2GB
MM8GR02GUACU-PA), which works well with Windows XP and Toshiba drivers.
Looking for a fix I have done some web research about similar laptop
models, and following the clues I found next HTML page:

http://list.drzeus.cx/pipermail/sdhci-devel/2007-December/002089.html

about a kernel patch related to the SD controller in my laptop, which
involves a change on a mmc_delay call on controller startup. The
lspci -vv description for the SD controller is:

06:0b.3 SD Host controller: Texas Instruments PCIxx12 SDA Standard Compliant SD Host Controller (prog-if 01)
Subsystem: Toshiba America Info Systems Device 0001
Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
Latency: 64 (1750ns min, 1000ns max), Cache Line Size: 32 bytes
Interrupt: pin D routed to IRQ 23
Region 0: Memory at ff9ff700 (32-bit, non-prefetchable) [size=256]
Capabilities: [80] Power Management version 2
Flags: PMEClk- DSI- D1+ D2+ AuxCurrent=0mA PME(D0+,D1+,D2+,D3hot+,D3cold-)
Status: D0 PME-Enable- DSel=0 DScale=0 PME-
Kernel driver in use: sdhci-pci
Kernel modules: sdhci-pci

When I applied the proposed change from that patch on mmc_delay
after MMC_POWER_ON, kernel started recognizing the microSD card,
but with errors I have seen with other SD cards:

Feb 21 18:39:25 olympo mmc0: card claims to support voltages below the defined range. These will be ignored.
Feb 21 18:39:25 olympo mmc0: SDIO card claims to support the incompletely defined 'low voltage range'. This will be ignored.
Feb 21 18:39:25 olympo mmc0: error -110 whilst initialising SDIO card

So, I extrapolated the change and, by chance, I found the fix,
which consist on raising the mmc_delay from 2 to 10 both on MMC_POWER_UP
and MMC_POWER_ON. I have been using the kernel with this fix for some
weeks, with no problem.

I don't know whether this patch can break something in the behavior of other
SD controllers, but at least it works for my laptop.

Signed-off-by: Jos? M. Fern?ndez <[email protected]>

---

diff -Nrpu linux-2.6.28.5/drivers/mmc/core/core.c.orig linux-2.6.28.5/drivers/mmc/core/core.c
--- linux-2.6.28.5/drivers/mmc/core/core.c.orig 2009-03-10 01:30:19.000000000 +0100
+++ linux-2.6.28.5/drivers/mmc/core/core.c 2009-03-10 01:29:44.000000000 +0100
@@ -514,7 +514,7 @@ static void mmc_power_up(struct mmc_host
* This delay should be sufficient to allow the power supply
* to reach the minimum voltage.
*/
- mmc_delay(2);
+ mmc_delay(10);

host->ios.clock = host->f_min;
host->ios.power_mode = MMC_POWER_ON;
@@ -524,7 +524,7 @@ static void mmc_power_up(struct mmc_host
* This delay must be at least 74 clock sizes, or 1 ms, or the
* time required to reach a stable voltage.
*/
- mmc_delay(2);
+ mmc_delay(10);
}

static void mmc_power_off(struct mmc_host *host)


2009-03-24 20:18:08

by Pierre Ossman

[permalink] [raw]
Subject: Re: [PATCH 1/1] mmc: Some microSD cards are not recognized by PCIxx12 SDA controller

On Tue, 10 Mar 2009 02:21:21 +0100
José Marí­a Fernández González <[email protected]> wrote:

>
> I don't know whether this patch can break something in the behavior of other
> SD controllers, but at least it works for my laptop.
>

Should be fairly safe, it just slows things down.

> diff -Nrpu linux-2.6.28.5/drivers/mmc/core/core.c.orig linux-2.6.28.5/drivers/mmc/core/core.c
> --- linux-2.6.28.5/drivers/mmc/core/core.c.orig 2009-03-10 01:30:19.000000000 +0100
> +++ linux-2.6.28.5/drivers/mmc/core/core.c 2009-03-10 01:29:44.000000000 +0100
> @@ -514,7 +514,7 @@ static void mmc_power_up(struct mmc_host
> * This delay should be sufficient to allow the power supply
> * to reach the minimum voltage.
> */
> - mmc_delay(2);
> + mmc_delay(10);
>

A delay of 10 is just enough to trigger a sleep on most kernels
(HZ=100). Have you determined the lower bound of these two values?

--
-- Pierre Ossman

Linux kernel, MMC maintainer http://www.kernel.org
rdesktop, core developer http://www.rdesktop.org

WARNING: This correspondence is being monitored by the
Swedish government. Make sure your server uses encryption
for SMTP traffic and consider using PGP for end-to-end
encryption.


Attachments:
signature.asc (198.00 B)
Subject: Re: [PATCH 1/1] mmc: Some microSD cards are not recognized by PCIxx12 SDA controller

Pierre Ossman wrote:
> On Tue, 10 Mar 2009 02:21:21 +0100
>> diff -Nrpu linux-2.6.28.5/drivers/mmc/core/core.c.orig linux-2.6.28.5/drivers/mmc/core/core.c
>> --- linux-2.6.28.5/drivers/mmc/core/core.c.orig 2009-03-10 01:30:19.000000000 +0100
>> +++ linux-2.6.28.5/drivers/mmc/core/core.c 2009-03-10 01:29:44.000000000 +0100
>> @@ -514,7 +514,7 @@ static void mmc_power_up(struct mmc_host
>> * This delay should be sufficient to allow the power supply
>> * to reach the minimum voltage.
>> */
>> - mmc_delay(2);
>> + mmc_delay(10);
>>
>
> A delay of 10 is just enough to trigger a sleep on most kernels
> (HZ=100). Have you determined the lower bound of these two values?
>

Well, I have been using the patch in a kernel with HZ=300, tickless (CONFIG_NO_HZ) and desktop preemption (CONFIG_PREEMPT_VOLUNTARY), but I didn't determine the lower bound. As I explained in the patch at -mm tree, I took as base the patch:

http://list.drzeus.cx/pipermail/sdhci-devel/2007-December/002089.html

and I only extrapolated the need for a higher delay just after MMC_POWER_UP to this one and after MMC_POWER_ON. When I was looking for a fix for the problem I was suffering with my microSD card and laptop, I remember I found some e-mails from two years ago pointing out to some change in the scheduler which uncovered the problem.

As I'm going to install 2.6.29 today, I can test the patch with it and HZ=100.

2009-03-25 16:18:18

by Pierre Ossman

[permalink] [raw]
Subject: Re: [PATCH 1/1] mmc: Some microSD cards are not recognized by PCIxx12 SDA controller

On Wed, 25 Mar 2009 09:00:56 +0100
José Marí­a Fernández González <[email protected]> wrote:

>
> As I'm going to install 2.6.29 today, I can test the patch with it and HZ=100.

Please do. And try to determine where it breaks. I'd prefer if we don't
need to increase this yet again in a month because we were relying on
some scheduling latencies. :)

Rgds
--
-- Pierre Ossman

Linux kernel, MMC maintainer http://www.kernel.org
rdesktop, core developer http://www.rdesktop.org

WARNING: This correspondence is being monitored by the
Swedish government. Make sure your server uses encryption
for SMTP traffic and consider using PGP for end-to-end
encryption.


Attachments:
signature.asc (198.00 B)
Subject: Re: [PATCH 1/1] mmc: Some microSD cards are not recognized by PCIxx12 SDA controller

Pierre Ossman wrote:
> On Wed, 25 Mar 2009 09:00:56 +0100
> José Marí­a Fernández González <[email protected]> wrote:
>
>> As I'm going to install 2.6.29 today, I can test the patch with it and HZ=100.
>
> Please do. And try to determine where it breaks. I'd prefer if we don't
> need to increase this yet again in a month because we were relying on
> some scheduling latencies. :)
>
> Rgds

I have been testing the patch with kernel 2.6.29 and a couple of cards (the Transcend 2GB microSD and a EZ Memory 8GB SDHC) in a few cases:

* HZ=300 + tickless + desktop preemption
* HZ=100 + tickless + desktop preemption
* HZ=100 + desktop preemption
* HZ=100 + low latency desktop preemption
* HZ=1000 + tickless + desktop preemption

and it worked with no problem. I don't know if I have forgotten any obvious corner case. Perhaps I should have tested with no preemption...

Best Regards,
José María

2009-04-05 18:34:11

by Pierre Ossman

[permalink] [raw]
Subject: Re: [PATCH 1/1] mmc: Some microSD cards are not recognized by PCIxx12 SDA controller

On Thu, 26 Mar 2009 17:37:10 +0100
José Marí­a Fernández González <[email protected]> wrote:

> Pierre Ossman wrote:
> > On Wed, 25 Mar 2009 09:00:56 +0100
> > José Marí­a Fernández González <[email protected]> wrote:
> >
> >> As I'm going to install 2.6.29 today, I can test the patch with it and HZ=100.
> >
> > Please do. And try to determine where it breaks. I'd prefer if we don't
> > need to increase this yet again in a month because we were relying on
> > some scheduling latencies. :)
> >
> > Rgds
>
> I have been testing the patch with kernel 2.6.29 and a couple of cards (the Transcend 2GB microSD and a EZ Memory 8GB SDHC) in a few cases:
>
> * HZ=300 + tickless + desktop preemption
> * HZ=100 + tickless + desktop preemption
> * HZ=100 + desktop preemption
> * HZ=100 + low latency desktop preemption
> * HZ=1000 + tickless + desktop preemption
>
> and it worked with no problem. I don't know if I have forgotten any obvious corner case. Perhaps I should have tested with no preemption...
>

All of them will result in a sleep though. Preferably, I'd like to now
the minimum delay you need to get things working. Change from
mmc_delay() to mdelay() to make sure there aren't any sleeps (which
generally take quite some time to complete).

Rgds
--
-- Pierre Ossman

Linux kernel, MMC maintainer http://www.kernel.org
rdesktop, core developer http://www.rdesktop.org

WARNING: This correspondence is being monitored by the
Swedish government. Make sure your server uses encryption
for SMTP traffic and consider using PGP for end-to-end
encryption.


Attachments:
signature.asc (198.00 B)
Subject: Re: [PATCH 1/1] mmc: Some microSD cards are not recognized by PCIxx12 SDA controller

It is curious. I have concentrated my tests on 2.6.29 with HZ=100 and no preemption, and I have done next tests with my microSD card and laptop:

* mmc_delay(2) -> FAIL
* mdelay(2) -> FAIL
* mmc_delay(10) -> Works!
* mdelay(10) -> Works!

And by mistake I found that:

* msleep(2) -> Works!

Best Regards,
José María

Pierre Ossman wrote:
>
> All of them will result in a sleep though. Preferably, I'd like to now
> the minimum delay you need to get things working. Change from
> mmc_delay() to mdelay() to make sure there aren't any sleeps (which
> generally take quite some time to complete).
>
> Rgds

2009-04-10 21:36:08

by Pierre Ossman

[permalink] [raw]
Subject: Re: [PATCH 1/1] mmc: Some microSD cards are not recognized by PCIxx12 SDA controller

On Tue, 07 Apr 2009 01:30:28 +0200
José Marí­a Fernández González <[email protected]> wrote:

> It is curious. I have concentrated my tests on 2.6.29 with HZ=100 and no preemption, and I have done next tests with my microSD card and laptop:
>
> * mmc_delay(2) -> FAIL
> * mdelay(2) -> FAIL
> * mmc_delay(10) -> Works!
> * mdelay(10) -> Works!
>

Looks good. Although it would have been nice to also know exactly when
it starts working.

> And by mistake I found that:
>
> * msleep(2) -> Works!
>

This is the scheduling effect I was talking about. Basically you can
never get msleep() to delay shorter than 1/HZ seconds.

I'll queue up your patch.

Rgds
--
-- Pierre Ossman

Linux kernel, MMC maintainer http://www.kernel.org
rdesktop, core developer http://www.rdesktop.org
TigerVNC, core developer http://www.tigervnc.org

WARNING: This correspondence is being monitored by the
Swedish government. Make sure your server uses encryption
for SMTP traffic and consider using PGP for end-to-end
encryption.


Attachments:
signature.asc (198.00 B)