Skip to content

Commit

Permalink
mmc: core: Add SD card quirk for broken discard
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
avri-altman-sndk authored and gregkh committed Oct 29, 2022
1 parent 0ee2f05 commit b9d8cbe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion drivers/mmc/core/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,11 @@ static void mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
nr = blk_rq_sectors(req);

do {
unsigned int erase_arg = card->erase_arg;

if (mmc_card_broken_sd_discard(card))
erase_arg = SD_ERASE_ARG;

err = 0;
if (card->quirks & MMC_QUIRK_INAND_CMD38) {
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
Expand All @@ -1117,7 +1122,7 @@ static void mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
card->ext_csd.generic_cmd6_time);
}
if (!err)
err = mmc_erase(card, from, nr, card->erase_arg);
err = mmc_erase(card, from, nr, erase_arg);
} while (err == -EIO && !mmc_blk_reset(md, card->host, type));
if (err)
status = BLK_STS_IOERR;
Expand Down
6 changes: 6 additions & 0 deletions drivers/mmc/core/card.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ struct mmc_fixup {
#define EXT_CSD_REV_ANY (-1u)

#define CID_MANFID_SANDISK 0x2
#define CID_MANFID_SANDISK_SD 0x3
#define CID_MANFID_ATP 0x9
#define CID_MANFID_TOSHIBA 0x11
#define CID_MANFID_MICRON 0x13
Expand Down Expand Up @@ -222,4 +223,9 @@ static inline int mmc_card_broken_hpi(const struct mmc_card *c)
return c->quirks & MMC_QUIRK_BROKEN_HPI;
}

static inline int mmc_card_broken_sd_discard(const struct mmc_card *c)
{
return c->quirks & MMC_QUIRK_BROKEN_SD_DISCARD;
}

#endif
6 changes: 6 additions & 0 deletions drivers/mmc/core/quirks.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ static const struct mmc_fixup __maybe_unused mmc_blk_fixups[] = {
MMC_FIXUP("V10016", CID_MANFID_KINGSTON, CID_OEMID_ANY, add_quirk_mmc,
MMC_QUIRK_TRIM_BROKEN),

/*
* Some SD cards reports discard support while they don't
*/
MMC_FIXUP(CID_NAME_ANY, CID_MANFID_SANDISK_SD, 0x5344, add_quirk_sd,
MMC_QUIRK_BROKEN_SD_DISCARD),

END_FIXUP
};

Expand Down
1 change: 1 addition & 0 deletions include/linux/mmc/card.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ struct mmc_card {
#define MMC_QUIRK_BROKEN_IRQ_POLLING (1<<11) /* Polling SDIO_CCCR_INTx could create a fake interrupt */
#define MMC_QUIRK_TRIM_BROKEN (1<<12) /* Skip trim */
#define MMC_QUIRK_BROKEN_HPI (1<<13) /* Disable broken HPI support */
#define MMC_QUIRK_BROKEN_SD_DISCARD (1<<14) /* Disable broken SD discard support */

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

Expand Down

0 comments on commit b9d8cbe

Please sign in to comment.