From: <light.hsieh@mediatek.com> To: <ulf.hansson@linaro.org> Cc: <linux-mediatek@lists.infradead.org>, <axboe@kernel.dk>, <linux-block@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <kuohong.wang@mediatek.com>, <stanley.chu@mediatek.com>, Light Hsieh <light.hsieh@mediatek.com> Subject: [PATCH v1 1/3] mmc: record wp_grp_size and boot_wp_status Date: Wed, 4 Mar 2020 10:51:12 +0800 [thread overview] Message-ID: <1583290274-5525-2-git-send-email-light.hsieh@mediatek.com> (raw) In-Reply-To: <1583290274-5525-1-git-send-email-light.hsieh@mediatek.com> From: Light Hsieh <light.hsieh@mediatek.com> 1. record wp_grp_size (write-protection group size) in struct mmc_csd and struct mmc_card. 2. record boot_wp_status (boot partition write-protection status) in struct mmc_ext_csd. Signed-off-by: Light Hsieh <light.hsieh@mediatek.com> --- drivers/mmc/core/mmc.c | 16 ++++++++++++++++ include/linux/mmc/card.h | 3 +++ include/linux/mmc/mmc.h | 1 + 3 files changed, 20 insertions(+) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index f6912de..77305c8 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -127,6 +127,16 @@ static void mmc_set_erase_size(struct mmc_card *card) mmc_init_erase(card); } +static void mmc_set_wp_grp_size(struct mmc_card *card) +{ + if (card->ext_csd.erase_group_def & 1) + card->wp_grp_size = card->ext_csd.hc_erase_size * + card->ext_csd.raw_hc_erase_gap_size; + else + card->wp_grp_size = card->csd.erase_size * + (card->csd.wp_grp_size + 1); +} + /* * Given a 128-bit response, decode to our card CSD structure. */ @@ -177,6 +187,7 @@ static int mmc_decode_csd(struct mmc_card *card) b = UNSTUFF_BITS(resp, 37, 5); csd->erase_size = (a + 1) * (b + 1); csd->erase_size <<= csd->write_blkbits - 9; + csd->wp_grp_size = UNSTUFF_BITS(resp, 32, 5); } return 0; @@ -496,6 +507,8 @@ static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd) card->ext_csd.boot_ro_lock = ext_csd[EXT_CSD_BOOT_WP]; card->ext_csd.boot_ro_lockable = true; + card->ext_csd.boot_wp_status = ext_csd[EXT_CSD_BOOT_WP_STATUS]; + /* Save power class values */ card->ext_csd.raw_pwr_cl_52_195 = ext_csd[EXT_CSD_PWR_CL_52_195]; @@ -769,6 +782,7 @@ static int mmc_compare_ext_csds(struct mmc_card *card, unsigned bus_width) card->raw_csd[2], card->raw_csd[3]); MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year); MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9); +MMC_DEV_ATTR(wp_grp_size, "%u\n", card->wp_grp_size << 9); MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9); MMC_DEV_ATTR(ffu_capable, "%d\n", card->ext_csd.ffu_capable); MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev); @@ -828,6 +842,7 @@ static ssize_t mmc_dsr_show(struct device *dev, &dev_attr_csd.attr, &dev_attr_date.attr, &dev_attr_erase_size.attr, + &dev_attr_wp_grp_size.attr, &dev_attr_preferred_erase_size.attr, &dev_attr_fwrev.attr, &dev_attr_ffu_capable.attr, @@ -1709,6 +1724,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, mmc_set_erase_size(card); } } + mmc_set_wp_grp_size(card); /* * Ensure eMMC user default partition is enabled diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index cf3780a..0139461 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -32,6 +32,7 @@ struct mmc_csd { unsigned int r2w_factor; unsigned int max_dtr; unsigned int erase_size; /* In sectors */ + unsigned int wp_grp_size; unsigned int read_blkbits; unsigned int write_blkbits; unsigned int capacity; @@ -94,6 +95,7 @@ struct mmc_ext_csd { u8 raw_exception_status; /* 54 */ u8 raw_partition_support; /* 160 */ u8 raw_rpmb_size_mult; /* 168 */ + u8 boot_wp_status; /* 174 */ u8 raw_erased_mem_count; /* 181 */ u8 strobe_support; /* 184 */ u8 raw_ext_csd_structure; /* 194 */ @@ -278,6 +280,7 @@ struct mmc_card { unsigned int eg_boundary; /* don't cross erase-group boundaries */ unsigned int erase_arg; /* erase / trim / discard */ u8 erased_byte; /* value of erased bytes */ + unsigned int wp_grp_size; /* write group size(sectors) */ u32 raw_cid[4]; /* raw card CID */ u32 raw_csd[4]; /* raw card CSD */ diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h index 897a87c..2c9d988 100644 --- a/include/linux/mmc/mmc.h +++ b/include/linux/mmc/mmc.h @@ -259,6 +259,7 @@ static inline bool mmc_op_multi(u32 opcode) #define EXT_CSD_RPMB_MULT 168 /* RO */ #define EXT_CSD_FW_CONFIG 169 /* R/W */ #define EXT_CSD_BOOT_WP 173 /* R/W */ +#define EXT_CSD_BOOT_WP_STATUS 174 /* RO */ #define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */ #define EXT_CSD_PART_CONFIG 179 /* R/W */ #define EXT_CSD_ERASED_MEM_CONT 181 /* RO */ -- 1.8.1.1.dirty
WARNING: multiple messages have this Message-ID (diff)
From: <light.hsieh@mediatek.com> To: <ulf.hansson@linaro.org> Cc: axboe@kernel.dk, kuohong.wang@mediatek.com, linux-kernel@vger.kernel.org, Light Hsieh <light.hsieh@mediatek.com>, linux-block@vger.kernel.org, linux-mediatek@lists.infradead.org, stanley.chu@mediatek.com Subject: [PATCH v1 1/3] mmc: record wp_grp_size and boot_wp_status Date: Wed, 4 Mar 2020 10:51:12 +0800 [thread overview] Message-ID: <1583290274-5525-2-git-send-email-light.hsieh@mediatek.com> (raw) In-Reply-To: <1583290274-5525-1-git-send-email-light.hsieh@mediatek.com> From: Light Hsieh <light.hsieh@mediatek.com> 1. record wp_grp_size (write-protection group size) in struct mmc_csd and struct mmc_card. 2. record boot_wp_status (boot partition write-protection status) in struct mmc_ext_csd. Signed-off-by: Light Hsieh <light.hsieh@mediatek.com> --- drivers/mmc/core/mmc.c | 16 ++++++++++++++++ include/linux/mmc/card.h | 3 +++ include/linux/mmc/mmc.h | 1 + 3 files changed, 20 insertions(+) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index f6912de..77305c8 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -127,6 +127,16 @@ static void mmc_set_erase_size(struct mmc_card *card) mmc_init_erase(card); } +static void mmc_set_wp_grp_size(struct mmc_card *card) +{ + if (card->ext_csd.erase_group_def & 1) + card->wp_grp_size = card->ext_csd.hc_erase_size * + card->ext_csd.raw_hc_erase_gap_size; + else + card->wp_grp_size = card->csd.erase_size * + (card->csd.wp_grp_size + 1); +} + /* * Given a 128-bit response, decode to our card CSD structure. */ @@ -177,6 +187,7 @@ static int mmc_decode_csd(struct mmc_card *card) b = UNSTUFF_BITS(resp, 37, 5); csd->erase_size = (a + 1) * (b + 1); csd->erase_size <<= csd->write_blkbits - 9; + csd->wp_grp_size = UNSTUFF_BITS(resp, 32, 5); } return 0; @@ -496,6 +507,8 @@ static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd) card->ext_csd.boot_ro_lock = ext_csd[EXT_CSD_BOOT_WP]; card->ext_csd.boot_ro_lockable = true; + card->ext_csd.boot_wp_status = ext_csd[EXT_CSD_BOOT_WP_STATUS]; + /* Save power class values */ card->ext_csd.raw_pwr_cl_52_195 = ext_csd[EXT_CSD_PWR_CL_52_195]; @@ -769,6 +782,7 @@ static int mmc_compare_ext_csds(struct mmc_card *card, unsigned bus_width) card->raw_csd[2], card->raw_csd[3]); MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year); MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9); +MMC_DEV_ATTR(wp_grp_size, "%u\n", card->wp_grp_size << 9); MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9); MMC_DEV_ATTR(ffu_capable, "%d\n", card->ext_csd.ffu_capable); MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev); @@ -828,6 +842,7 @@ static ssize_t mmc_dsr_show(struct device *dev, &dev_attr_csd.attr, &dev_attr_date.attr, &dev_attr_erase_size.attr, + &dev_attr_wp_grp_size.attr, &dev_attr_preferred_erase_size.attr, &dev_attr_fwrev.attr, &dev_attr_ffu_capable.attr, @@ -1709,6 +1724,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, mmc_set_erase_size(card); } } + mmc_set_wp_grp_size(card); /* * Ensure eMMC user default partition is enabled diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index cf3780a..0139461 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -32,6 +32,7 @@ struct mmc_csd { unsigned int r2w_factor; unsigned int max_dtr; unsigned int erase_size; /* In sectors */ + unsigned int wp_grp_size; unsigned int read_blkbits; unsigned int write_blkbits; unsigned int capacity; @@ -94,6 +95,7 @@ struct mmc_ext_csd { u8 raw_exception_status; /* 54 */ u8 raw_partition_support; /* 160 */ u8 raw_rpmb_size_mult; /* 168 */ + u8 boot_wp_status; /* 174 */ u8 raw_erased_mem_count; /* 181 */ u8 strobe_support; /* 184 */ u8 raw_ext_csd_structure; /* 194 */ @@ -278,6 +280,7 @@ struct mmc_card { unsigned int eg_boundary; /* don't cross erase-group boundaries */ unsigned int erase_arg; /* erase / trim / discard */ u8 erased_byte; /* value of erased bytes */ + unsigned int wp_grp_size; /* write group size(sectors) */ u32 raw_cid[4]; /* raw card CID */ u32 raw_csd[4]; /* raw card CSD */ diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h index 897a87c..2c9d988 100644 --- a/include/linux/mmc/mmc.h +++ b/include/linux/mmc/mmc.h @@ -259,6 +259,7 @@ static inline bool mmc_op_multi(u32 opcode) #define EXT_CSD_RPMB_MULT 168 /* RO */ #define EXT_CSD_FW_CONFIG 169 /* R/W */ #define EXT_CSD_BOOT_WP 173 /* R/W */ +#define EXT_CSD_BOOT_WP_STATUS 174 /* RO */ #define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */ #define EXT_CSD_PART_CONFIG 179 /* R/W */ #define EXT_CSD_ERASED_MEM_CONT 181 /* RO */ -- 1.8.1.1.dirty _______________________________________________ Linux-mediatek mailing list Linux-mediatek@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-mediatek
next prev parent reply other threads:[~2020-03-04 2:51 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-03-04 2:51 [PATCH v1 0/3] set ro attribute of block device according to write-protection status light.hsieh 2020-03-04 2:51 ` light.hsieh 2020-03-04 2:51 ` light.hsieh [this message] 2020-03-04 2:51 ` [PATCH v1 1/3] mmc: record wp_grp_size and boot_wp_status light.hsieh 2020-03-04 2:51 ` [PATCH v1 2/3] mmc: check write-protection status during BLKROSET ioctl light.hsieh 2020-03-04 2:51 ` light.hsieh 2020-03-04 2:51 ` [PATCH v1 3/3] block: set partition read/write policy according to write-protection status light.hsieh 2020-03-04 2:51 ` light.hsieh 2020-03-19 10:25 ` Christoph Hellwig 2020-03-19 10:25 ` Christoph Hellwig 2020-03-04 2:57 [PATCH v1 0/3] set ro attribute of block device " light.hsieh 2020-03-04 2:57 ` [PATCH v1 1/3] mmc: record wp_grp_size and boot_wp_status light.hsieh 2020-03-04 2:57 ` light.hsieh 2020-03-04 3:01 [PATCH v1 0/3] set ro attribute of block device according to write-protection status light.hsieh 2020-03-04 3:01 ` [PATCH v1 1/3] mmc: record wp_grp_size and boot_wp_status light.hsieh 2020-03-04 3:01 ` light.hsieh
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1583290274-5525-2-git-send-email-light.hsieh@mediatek.com \ --to=light.hsieh@mediatek.com \ --cc=axboe@kernel.dk \ --cc=kuohong.wang@mediatek.com \ --cc=linux-block@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mediatek@lists.infradead.org \ --cc=stanley.chu@mediatek.com \ --cc=ulf.hansson@linaro.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.