Skip to content

Commit b1c86a8

Browse files
Phil Elwellpopcornmix
authored andcommitted
mmc: Add MMC_QUIRK_ERASE_BROKEN for some cards
Some SD cards have been found that corrupt data when small blocks are erased. Add a quirk to indicate that ERASE should not be used, and set it for cards of that type. Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: Apply QUIRK_BROKEN_ERASE to other capacities Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: Add card_quirks module parameter, log quirks Use mmc_block.card_quirks to override the quirks for all SD or MMC cards. The value is a bitfield using the bit positions defined in include/linux/mmc/card.h. If the module parameter is placed in the kernel command line (or bootargs) stored on the card then, assuming the device only has one SD card interface, the override effectively becomes card-specific. Signed-off-by: Phil Elwell <phil@raspberrypi.org>
1 parent e948c6a commit b1c86a8

3 files changed

Lines changed: 41 additions & 4 deletions

File tree

‎drivers/mmc/card/block.c‎

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ enum {
135135
module_param(perdev_minors, int, 0444);
136136
MODULE_PARM_DESC(perdev_minors, "Minors numbers to allocate per device");
137137

138+
/*
139+
* Allow quirks to be overridden for the current card
140+
*/
141+
static char *card_quirks;
142+
module_param(card_quirks, charp, 0644);
143+
MODULE_PARM_DESC(card_quirks, "Force the use of the indicated quirks (a bitfield)");
144+
138145
static inline int mmc_blk_part_switch(struct mmc_card *card,
139146
struct mmc_blk_data *md);
140147
static int get_card_status(struct mmc_card *card, u32 *status, int retries);
@@ -2573,31 +2580,57 @@ static const struct mmc_fixup blk_fixups[] =
25732580
MMC_FIXUP("V10016", CID_MANFID_KINGSTON, CID_OEMID_ANY, add_quirk_mmc,
25742581
MMC_QUIRK_TRIM_BROKEN),
25752582

2583+
/*
2584+
* On some Kingston SD cards, multiple erases of less than 64
2585+
* sectors can cause corruption.
2586+
*/
2587+
MMC_FIXUP("SD16G", 0x41, 0x3432, add_quirk_mmc,
2588+
MMC_QUIRK_ERASE_BROKEN),
2589+
MMC_FIXUP("SD32G", 0x41, 0x3432, add_quirk_mmc,
2590+
MMC_QUIRK_ERASE_BROKEN),
2591+
MMC_FIXUP("SD64G", 0x41, 0x3432, add_quirk_mmc,
2592+
MMC_QUIRK_ERASE_BROKEN),
2593+
25762594
END_FIXUP
25772595
};
25782596

25792597
static int mmc_blk_probe(struct mmc_card *card)
25802598
{
25812599
struct mmc_blk_data *md, *part_md;
25822600
char cap_str[10];
2601+
char quirk_str[24];
25832602

25842603
/*
25852604
* Check that the card supports the command class(es) we need.
25862605
*/
25872606
if (!(card->csd.cmdclass & CCC_BLOCK_READ))
25882607
return -ENODEV;
25892608

2590-
mmc_fixup_device(card, blk_fixups);
2609+
if (card_quirks) {
2610+
unsigned long quirks;
2611+
if (kstrtoul(card_quirks, 0, &quirks) == 0)
2612+
card->quirks = (unsigned int)quirks;
2613+
else
2614+
pr_err("mmc_block: Invalid card_quirks parameter '%s'\n",
2615+
card_quirks);
2616+
}
2617+
else
2618+
mmc_fixup_device(card, blk_fixups);
25912619

25922620
md = mmc_blk_alloc(card);
25932621
if (IS_ERR(md))
25942622
return PTR_ERR(md);
25952623

25962624
string_get_size((u64)get_capacity(md->disk), 512, STRING_UNITS_2,
25972625
cap_str, sizeof(cap_str));
2598-
pr_info("%s: %s %s %s %s\n",
2626+
if (card->quirks)
2627+
snprintf(quirk_str, sizeof(quirk_str),
2628+
" (quirks 0x%08x)", card->quirks);
2629+
else
2630+
quirk_str[0] = '\0';
2631+
pr_info("%s: %s %s %s%s%s\n",
25992632
md->disk->disk_name, mmc_card_id(card), mmc_card_name(card),
2600-
cap_str, md->read_only ? "(ro)" : "");
2633+
cap_str, md->read_only ? " (ro)" : "", quirk_str);
26012634

26022635
if (mmc_blk_alloc_parts(card, md))
26032636
goto out;

‎drivers/mmc/core/core.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2409,7 +2409,8 @@ EXPORT_SYMBOL(mmc_erase);
24092409
int mmc_can_erase(struct mmc_card *card)
24102410
{
24112411
if ((card->host->caps & MMC_CAP_ERASE) &&
2412-
(card->csd.cmdclass & CCC_ERASE) && card->erase_size)
2412+
(card->csd.cmdclass & CCC_ERASE) && card->erase_size &&
2413+
!(card->quirks & MMC_QUIRK_ERASE_BROKEN))
24132414
return 1;
24142415
return 0;
24152416
}

‎include/linux/mmc/card.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ struct mmc_card {
283283
#define MMC_QUIRK_BROKEN_HPI (1<<13) /* Disable broken HPI support */
284284

285285

286+
#define MMC_QUIRK_ERASE_BROKEN (1<<31) /* Skip erase */
287+
288+
286289
unsigned int erase_size; /* erase size in sectors */
287290
unsigned int erase_shift; /* if erase unit is power 2 */
288291
unsigned int pref_erase; /* in sectors */

0 commit comments

Comments
 (0)