Skip to content

Commit 07d2872

Browse files
avri-altman-sndkstorulf
authored andcommitted
mmc: core: Add SD card quirk for broken discard
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]>
1 parent 833477f commit 07d2872

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

drivers/mmc/core/block.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,8 +1140,12 @@ static void mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
11401140
{
11411141
struct mmc_blk_data *md = mq->blkdata;
11421142
struct mmc_card *card = md->queue.card;
1143+
unsigned int arg = card->erase_arg;
11431144

1144-
mmc_blk_issue_erase_rq(mq, req, MMC_BLK_DISCARD, card->erase_arg);
1145+
if (mmc_card_broken_sd_discard(card))
1146+
arg = SD_ERASE_ARG;
1147+
1148+
mmc_blk_issue_erase_rq(mq, req, MMC_BLK_DISCARD, arg);
11451149
}
11461150

11471151
static void mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,

drivers/mmc/core/card.h

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

7575
#define CID_MANFID_SANDISK 0x2
76+
#define CID_MANFID_SANDISK_SD 0x3
7677
#define CID_MANFID_ATP 0x9
7778
#define CID_MANFID_TOSHIBA 0x11
7879
#define CID_MANFID_MICRON 0x13
@@ -258,4 +259,9 @@ static inline int mmc_card_broken_hpi(const struct mmc_card *c)
258259
return c->quirks & MMC_QUIRK_BROKEN_HPI;
259260
}
260261

262+
static inline int mmc_card_broken_sd_discard(const struct mmc_card *c)
263+
{
264+
return c->quirks & MMC_QUIRK_BROKEN_SD_DISCARD;
265+
}
266+
261267
#endif

drivers/mmc/core/quirks.h

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

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

include/linux/mmc/card.h

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

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

0 commit comments

Comments
 (0)