Skip to content

Commit b9d8cbe

Browse files
avri-altman-sndkgregkh
authored andcommitted
mmc: core: Add SD card quirk for broken discard
commit 07d2872 upstream. Some SD-cards from Sandisk that are SDA-6.0 compliant reports they supports discard, while they actually don't. This might cause mk2fs to fail while trying to format the card and revert it to a read-only mode. To fix this problem, let's add a card quirk (MMC_QUIRK_BROKEN_SD_DISCARD) to indicate that we shall fall-back to use the legacy erase command instead. Signed-off-by: Avri Altman <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] [Ulf: Updated the commit message] Signed-off-by: Ulf Hansson <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0ee2f05 commit b9d8cbe

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

drivers/mmc/core/block.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,11 @@ static void mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
11071107
nr = blk_rq_sectors(req);
11081108

11091109
do {
1110+
unsigned int erase_arg = card->erase_arg;
1111+
1112+
if (mmc_card_broken_sd_discard(card))
1113+
erase_arg = SD_ERASE_ARG;
1114+
11101115
err = 0;
11111116
if (card->quirks & MMC_QUIRK_INAND_CMD38) {
11121117
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
@@ -1117,7 +1122,7 @@ static void mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
11171122
card->ext_csd.generic_cmd6_time);
11181123
}
11191124
if (!err)
1120-
err = mmc_erase(card, from, nr, card->erase_arg);
1125+
err = mmc_erase(card, from, nr, erase_arg);
11211126
} while (err == -EIO && !mmc_blk_reset(md, card->host, type));
11221127
if (err)
11231128
status = BLK_STS_IOERR;

drivers/mmc/core/card.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct mmc_fixup {
7070
#define EXT_CSD_REV_ANY (-1u)
7171

7272
#define CID_MANFID_SANDISK 0x2
73+
#define CID_MANFID_SANDISK_SD 0x3
7374
#define CID_MANFID_ATP 0x9
7475
#define CID_MANFID_TOSHIBA 0x11
7576
#define CID_MANFID_MICRON 0x13
@@ -222,4 +223,9 @@ static inline int mmc_card_broken_hpi(const struct mmc_card *c)
222223
return c->quirks & MMC_QUIRK_BROKEN_HPI;
223224
}
224225

226+
static inline int mmc_card_broken_sd_discard(const struct mmc_card *c)
227+
{
228+
return c->quirks & MMC_QUIRK_BROKEN_SD_DISCARD;
229+
}
230+
225231
#endif

drivers/mmc/core/quirks.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ static const struct mmc_fixup __maybe_unused mmc_blk_fixups[] = {
9999
MMC_FIXUP("V10016", CID_MANFID_KINGSTON, CID_OEMID_ANY, add_quirk_mmc,
100100
MMC_QUIRK_TRIM_BROKEN),
101101

102+
/*
103+
* Some SD cards reports discard support while they don't
104+
*/
105+
MMC_FIXUP(CID_NAME_ANY, CID_MANFID_SANDISK_SD, 0x5344, add_quirk_sd,
106+
MMC_QUIRK_BROKEN_SD_DISCARD),
107+
102108
END_FIXUP
103109
};
104110

include/linux/mmc/card.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ struct mmc_card {
292292
#define MMC_QUIRK_BROKEN_IRQ_POLLING (1<<11) /* Polling SDIO_CCCR_INTx could create a fake interrupt */
293293
#define MMC_QUIRK_TRIM_BROKEN (1<<12) /* Skip trim */
294294
#define MMC_QUIRK_BROKEN_HPI (1<<13) /* Disable broken HPI support */
295+
#define MMC_QUIRK_BROKEN_SD_DISCARD (1<<14) /* Disable broken SD discard support */
295296

296297
bool reenable_cmdq; /* Re-enable Command Queue */
297298

0 commit comments

Comments
 (0)