Bug 142172 - gentoo-sources: Please add patch to mmc_block.c to support SD Card >1GB
Bug#: 142172 Product:  Gentoo Linux Version: 2006.0 Platform: All
OS/Version: Linux Status: RESOLVED Severity: enhancement Priority: P2
Resolution: FIXED Assigned To: dsd@gentoo.org Reported By: Jan.Schubert@GMX.li
Component: Core system
URL: 
Summary: gentoo-sources: Please add patch to mmc_block.c to support SD Card >1GB
Keywords:  
Status Whiteboard: 
Opened: 2006-07-30 05:12 0000
Description:   Opened: 2006-07-30 05:12 0000
To support SD Cards (or any other smart cards) bigger than 1GB there is a need
to patch drivers/mmc/mmc_block.c, see also
http://marc.theaimsgroup.com/?l=linux-kernel&m=114980773206129&w=2. The trikc
is to set the block size staticaly to 512 Byte (9 Bit) instead of reading it
from the card itself which results in my case in an error like "unable to set
block size to 1024".

Works fine for me and is included in other distros as well (seen in a forum,
don't remember which one, I had to reboot my box to test the patch :-):

--- a/drivers/mmc/mmc_block.c
+++ b/drivers/mmc/mmc_block.c
@@ -325,52 +325,11 @@ static struct mmc_blk_data *mmc_blk_allo
        md->read_only = mmc_blk_readonly(card);

        /*
-        * Figure out a workable block size.  MMC cards have:
-        *  - two block sizes, one for read and one for write.
-        *  - may support partial reads and/or writes
-        *    (allows block sizes smaller than specified)
+        * Both SD and MMC specifications state (although a bit
+        * unclearly in the MMC case) that a block size of 512
+        * bytes must always be supported by the card.
         */
-       md->block_bits = card->csd.read_blkbits;
-       if (card->csd.write_blkbits != card->csd.read_blkbits) {
-               if (card->csd.write_blkbits < card->csd.read_blkbits &&
-                   card->csd.read_partial) {
-                       /*
-                        * write block size is smaller than read block
-                        * size, but we support partial reads, so choose
-                        * the smaller write block size.
-                        */
-                       md->block_bits = card->csd.write_blkbits;
-               } else if (card->csd.write_blkbits > card->csd.read_blkbits &&
-                          card->csd.write_partial) {
-                       /*
-                        * read block size is smaller than write block
-                        * size, but we support partial writes.  Use read
-                        * block size.
-                        */
-               } else {
-                       /*
-                        * We don't support this configuration for writes.
-                        */
-                       printk(KERN_ERR "%s: unable to select block size for "
-                               "writing (rb%u wb%u rp%u wp%u)\n",
-                               mmc_card_id(card),
-                               1 << card->csd.read_blkbits,
-                               1 << card->csd.write_blkbits,
-                               card->csd.read_partial,
-                               card->csd.write_partial);
-                       md->read_only = 1;
-               }
-       }
-
-       /*
-        * Refuse to allow block sizes smaller than 512 bytes.
-        */
-       if (md->block_bits < 9) {
-               printk(KERN_ERR "%s: unable to support block size %u\n",
-                       mmc_card_id(card), 1 << md->block_bits);
-               ret = -EINVAL;
-               goto err_kfree;
-       }
+       md->block_bits = 9;

        md->disk = alloc_disk(1 << MMC_SHIFT);
        if (md->disk == NULL) {

------- Comment #1 From Jan Schubert 2006-08-21 13:49:41 0000 -------
still valid for gentoo-sources-2.6.17-r5 :-(

------- Comment #2 From Daniel Drake 2006-08-21 14:03:32 0000 -------
Indeed, see my reply on the thread you linked to:

http://marc.theaimsgroup.com/?l=linux-kernel&m=115546362627753&w=2

Perhaps you could email Pierre with the success report as a gentle reminder
about this patch :)

------- Comment #3 From Daniel Drake 2006-09-09 06:57:41 0000 -------
This is merged into a subsystem tree

------- Comment #4 From Daniel Drake 2006-09-09 19:37:30 0000 -------
Fixed in gentoo-sources-2.6.17-r8 (genpatches-2.6.17-10). Thanks for the patch.

------- Comment #5 From Jan Schubert 2006-09-17 11:23:28 0000 -------
Works fine, thx a lot :-)