From beffb5e21b03f78dc553112f6a4156a923fe965b Mon Sep 17 00:00:00 2001 From: Andres Rodriguez Date: Tue, 8 Nov 2022 17:32:25 -0500 Subject: [PATCH 21/21] mmc: core: add safe_trim_quirk attribute This attribute is intended to be used by userspace tools to identify if trimming a device is safe or not. It helps in cases where a userspace tool is aware of the necessity of the quirk and a user accidentally downgrades their kernel to a one that doesn't have support for the quirk. Signed-off-by: Andres Rodriguez (cherry picked from commit dfc5952c55f58d0e0863ccba0aa598fdae16ed14) Signed-off-by: Cristian Ciocaltea --- drivers/mmc/core/mmc.c | 2 ++ drivers/mmc/core/quirks.h | 2 ++ drivers/mmc/core/sd.c | 2 ++ include/linux/mmc/card.h | 1 + 4 files changed, 7 insertions(+) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 6a23be214543..d8cf810837e8 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -806,6 +806,7 @@ MMC_DEV_ATTR(rel_sectors, "%#x\n", card->ext_csd.rel_sectors); MMC_DEV_ATTR(ocr, "0x%08x\n", card->ocr); MMC_DEV_ATTR(rca, "0x%04x\n", card->rca); MMC_DEV_ATTR(cmdq_en, "%d\n", card->ext_csd.cmdq_en); +MMC_DEV_ATTR(safe_trim_quirk, "%d\n", card->safe_trim_quirk_version); static ssize_t mmc_fwrev_show(struct device *dev, struct device_attribute *attr, @@ -865,6 +866,7 @@ static struct attribute *mmc_std_attrs[] = { &dev_attr_rca.attr, &dev_attr_dsr.attr, &dev_attr_cmdq_en.attr, + &dev_attr_safe_trim_quirk.attr, NULL, }; ATTRIBUTE_GROUPS(mmc_std); diff --git a/drivers/mmc/core/quirks.h b/drivers/mmc/core/quirks.h index 89b512905be1..20c022419de1 100644 --- a/drivers/mmc/core/quirks.h +++ b/drivers/mmc/core/quirks.h @@ -254,4 +254,6 @@ static inline void mmc_fixup_device(struct mmc_card *card, dev_dbg(&card->dev, "calling %ps\n", f->vendor_fixup); f->vendor_fixup(card, f->data); } + + card->safe_trim_quirk_version = 1; } diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index cc757b850e79..2fe5d6c9fed7 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -710,6 +710,7 @@ MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid); MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial); MMC_DEV_ATTR(ocr, "0x%08x\n", card->ocr); MMC_DEV_ATTR(rca, "0x%04x\n", card->rca); +MMC_DEV_ATTR(safe_trim_quirk, "%d\n", card->safe_trim_quirk_version); static ssize_t mmc_dsr_show(struct device *dev, struct device_attribute *attr, @@ -772,6 +773,7 @@ static struct attribute *sd_std_attrs[] = { &dev_attr_ocr.attr, &dev_attr_rca.attr, &dev_attr_dsr.attr, + &dev_attr_safe_trim_quirk.attr, NULL, }; diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index 526fce581657..722812713ec0 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -309,6 +309,7 @@ struct mmc_card { unsigned int state; /* (our) card state */ unsigned int quirks; /* card quirks */ unsigned int quirk_max_rate; /* max rate set by quirks */ + unsigned int safe_trim_quirk_version; /* advertise if we have protection for cards which misbehave with trim */ #define MMC_QUIRK_LENIENT_FN0 (1<<0) /* allow SDIO FN0 writes outside of the VS CCCR range */ #define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1) /* use func->cur_blksize */ /* for byte mode */ -- 2.48.1