DMA for Ricoh SD card reader on Lenovo laptops

If you have Lenovo laptop with Ricoh SD card reader like this:

lenovo greg # lspci -v |grep Ricoh
05:06.1 SD Host controller: Ricoh Co Ltd R5C822 SD/SDIO/MMC/MS/MSPro Host Adapter (rev 19)
05:06.2 System peripheral: Ricoh Co Ltd R5C592 Memory Stick Bus Host Adapter (rev 0a)
05:06.3 System peripheral: Ricoh Co Ltd xD-Picture Card Controller (rev 05)

You noticed that copying from SD card to disk takes much more time and cpu usage then on Windows. I tired to find out what is the reason. I’m use to that performance of my Linux box is better then windows. I found it that main problem is using by Ricoh PIO instead of DMA access. It causes high cpu usage and slow data transfer. You can probably check it:

greg@lenovo ~ $ dmesg |grep PIO
[ 4.885841] mmc0: SDHCI controller on PCI [0000:05:06.1] using PIO

How to solve it? Google, google, google…. I found this conversation. Ricoh readers support DMA but it is somehow disabled. Patch in conversation really works! I tried apply it by patch -p1 < but finally i modified 4 lines manually:

From: Vasily Khoruzhick

This card reader doesn't advertise, however DMA works well.
Probably windows SDHCI driver assumes that all readers support DMA
and thus we see that bug.

Signed-off-by: Vasily Khoruzhick
Tested-by: Maxim Levitsky
---
drivers/mmc/host/sdhci-pci.c | 7 +++----
1 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
index 5c3a176..12f5b09 100644
--- a/drivers/mmc/host/sdhci-pci.c
+++ b/drivers/mmc/host/sdhci-pci.c
@@ -80,9 +80,6 @@ struct sdhci_pci_chip {

static int ricoh_probe(struct sdhci_pci_chip *chip)
{
- if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
- chip->quirks |= SDHCI_QUIRK_CLOCK_BEFORE_RESET;
-
if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG ||
chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY)
chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET;
@@ -92,7 +89,9 @@ static int ricoh_probe(struct sdhci_pci_chip *chip)

static const struct sdhci_pci_fixes sdhci_ricoh = {
.probe = ricoh_probe,
- .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR,
+ .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
+ SDHCI_QUIRK_FORCE_DMA |
+ SDHCI_QUIRK_CLOCK_BEFORE_RESET,
};

static const struct sdhci_pci_fixes sdhci_ene_712 = {

After kernel recompiling we got:

greg@lenovo ~ $ dmesg |grep DMA
[ 4.883537] sdhci-pci 0000:05:06.1: Will use DMA mode even though HW doesn't fully claim to support it.
[ 4.885841] mmc0: SDHCI controller on PCI [0000:05:06.1] using DMA

SD cards are detected properly, transfer increased from 2 MB/s to 7-8 MB/s. CPU usage doesn’t change during copying operation.
That’s it!
Lets hope that patch will be merged to the kernel main stream soon.

UPDATE!
Since kernel 2.6.35 this patch is merged into master :).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s