From patchwork Thu Apr 28 10:58:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 1214 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:50:13 -0000 Delivered-To: patches@linaro.org Received: by 10.224.2.73 with SMTP id 9cs142091qai; Thu, 28 Apr 2011 03:59:01 -0700 (PDT) Received: by 10.14.131.75 with SMTP id l51mr1426469eei.183.1303988340847; Thu, 28 Apr 2011 03:59:00 -0700 (PDT) Received: from eu1sys200aog109.obsmtp.com (eu1sys200aog109.obsmtp.com [207.126.144.127]) by mx.google.com with SMTP id y2si6069896eeh.9.2011.04.28.03.58.53 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 28 Apr 2011 03:59:00 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.127 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) client-ip=207.126.144.127; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.127 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) smtp.mail=linus.walleij@stericsson.com Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob109.postini.com ([207.126.147.11]) with SMTP ID DSNKTblIaieKxFsIo0cncj6hMYwz36YnpouN@postini.com; Thu, 28 Apr 2011 10:59:00 UTC Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id B2B0D171; Thu, 28 Apr 2011 10:58:46 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 2440B29E0; Thu, 28 Apr 2011 10:58:46 +0000 (GMT) Received: from exdcvycastm003.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm003", Issuer "exdcvycastm003" (not verified)) by relay2.stm.gmessaging.net (Postfix) with ESMTPS id 4375AA8074; Thu, 28 Apr 2011 12:58:41 +0200 (CEST) Received: from localhost.localdomain (10.230.100.153) by smtp.stericsson.com (10.230.100.1) with Microsoft SMTP Server (TLS) id 8.2.254.0; Thu, 28 Apr 2011 12:58:45 +0200 From: Linus Walleij To: , Chris Ball Cc: Lee Jones , Linus Walleij , Gary King , Ulf Hansson , Colin Cross , Andrei Warkentin Subject: [PATCH] RFC: mmc: subtract boot sectors from disk size on quirky cards Date: Thu, 28 Apr 2011 12:58:34 +0200 Message-ID: <1303988314-30316-1-git-send-email-linus.walleij@stericsson.com> X-Mailer: git-send-email 1.7.3.2 MIME-Version: 1.0 From: Linus Walleij The csd sector count reported by some problematic eMMC 4.3+ cards includes the boot partition size; subtract this from the size reported to the disk since the boot partition is inaccessible. Cc: Gary King Cc: Ulf Hansson Cc: Colin Cross Cc: Andrei Warkentin Signed-off-by: Linus Walleij --- GARY: can you provide the VID+PID numbers for the problematic card, so we can handle this properly? --- drivers/mmc/core/mmc.c | 13 +++++++++++++ drivers/mmc/core/quirks.c | 3 +++ include/linux/mmc/card.h | 1 + include/linux/mmc/mmc.h | 1 + 4 files changed, 18 insertions(+), 0 deletions(-) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 772d0d0..0833d15 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -255,6 +255,19 @@ static int mmc_read_ext_csd(struct mmc_card *card) /* Cards with density > 2GiB are sector addressed */ if (card->ext_csd.sectors > (2u * 1024 * 1024 * 1024) / 512) mmc_card_set_blockaddr(card); + + /* + * Some cards require that you remove the boot sectors from the + * total amount of sectors on the card. This is not defined + * by the spec so needs to be a per-card quirk. + */ + if (card->ext_csd.sectors && + (card->quirks & MMC_QUIRK_SUBTRACT_BOOTSECS)) { + unsigned boot_sectors; + /* size is in 128K chunks, i.e. 256 sectors each */ + boot_sectors = ext_csd[EXT_CSD_BOOT_SIZE_MULTI] * 256; + card->ext_csd.sectors -= boot_sectors; + } } switch (ext_csd[EXT_CSD_CARD_TYPE] & EXT_CSD_CARD_TYPE_MASK) { diff --git a/drivers/mmc/core/quirks.c b/drivers/mmc/core/quirks.c index 11118b74..fb1f528 100644 --- a/drivers/mmc/core/quirks.c +++ b/drivers/mmc/core/quirks.c @@ -64,6 +64,9 @@ static const struct mmc_fixup mmc_fixup_methods[] = { add_quirk_for_sdio_devices, MMC_QUIRK_BROKEN_CLK_GATING }, { SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271, remove_quirk, MMC_QUIRK_BROKEN_CLK_GATING }, + /* TODO: fill in problematic card VID/PID here */ + { 0x0000, 0x0000, + add_quirk, MMC_QUIRK_SUBTRACT_BOOTSECS }, { 0 } }; diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index adb4888..f860eea 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -125,6 +125,7 @@ struct mmc_card { #define MMC_QUIRK_NONSTD_SDIO (1<<2) /* non-standard SDIO card attached */ /* (missing CIA registers) */ #define MMC_QUIRK_BROKEN_CLK_GATING (1<<3) /* clock gating the sdio bus will make card fail */ +#define MMC_QUIRK_SUBTRACT_BOOTSECS (1<<4) /* remove any boot sectors from the sector allocation pool */ unsigned int erase_size; /* erase size in sectors */ unsigned int erase_shift; /* if erase unit is power 2 */ diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h index 264ba54..4516fc1 100644 --- a/include/linux/mmc/mmc.h +++ b/include/linux/mmc/mmc.h @@ -267,6 +267,7 @@ struct _mmc_csd { #define EXT_CSD_HC_WP_GRP_SIZE 221 /* RO */ #define EXT_CSD_ERASE_TIMEOUT_MULT 223 /* RO */ #define EXT_CSD_HC_ERASE_GRP_SIZE 224 /* RO */ +#define EXT_CSD_BOOT_SIZE_MULTI 226 /* RO */ #define EXT_CSD_SEC_TRIM_MULT 229 /* RO */ #define EXT_CSD_SEC_ERASE_MULT 230 /* RO */ #define EXT_CSD_SEC_FEATURE_SUPPORT 231 /* RO */