Skip to contentSkip to conversation

mmc: update life time and rel write on sysfs read

PATCH In review Marc Mattmueller 3 participants 8 messages Mar 9, 2022 – Mar 15, 2022 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

cover mmc: update life time and rel write on sysfs read

This patchset adds the update of the ext_csd structure when reading the estimated life time, pre-eol info or reliable write setting from sysfs. Based on
https://www.spinics.net/lists/linux-mmc/msg56424.html

The reason for this patchset resides in devices running 24/7. The mmc estimated life time values, pre-eol info and reliable write setting values were only read at start-up and were not updated on sysfs read. Thus, these patches add the rel_param, rel_write_set to sysfs and perform an update of the EXT_CSD structure when reading form sysfs one of the values device_life_time_est_typ_a, device_life_time_est_typ_b, pre_eol_info or rel_write_set.

Marc Mattmueller (2):
mmc: core: update life time and pre eol info values on sysfs read
mmc: core: add reliable write setting to sysfs and update on read

 drivers/mmc/core/mmc.c   | 116 +++++++++++++++++++++++++++++++++++++--
 include/linux/mmc/card.h |   1 +
 include/linux/mmc/mmc.h  |   1 +
 3 files changed, 114 insertions(+), 4 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/2 mmc: core: update life time and pre eol info values on sysfs read

The mmc estimated life time values and pre-eol info values were only read at start-up and were not updated on sysfs read. Thus, added update of the ext_csd structure on sysfs read of device_life_time_est_typ_a, device_life_time_est_typ_b and pre_eol_info.

---
 drivers/mmc/core/mmc.c | 87 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 83 insertions(+), 4 deletions(-)
drivers/mmc/core/mmc.c +83 -4
index 43d1b9b2fa49..d9537c894e33 100644
@@ -357,6 +357,25 @@ static void mmc_manage_gp_partitions(struct mmc_card *card, u8 *ext_csd)
 /* Minimum partition switch timeout in milliseconds */
 #define MMC_MIN_PART_SWITCH_TIME	300
 
+/*
+ * Update extended CSD parameters changing during runtime.
+ */
+static int mmc_update_ext_csd_runtime_params(struct mmc_card *card, u8 *ext_csd)
+{
+	int err = 0;
+
+	/* eMMC v5 or later */
+	if (card->ext_csd.rev >= 7) {
+		card->ext_csd.pre_eol_info = ext_csd[EXT_CSD_PRE_EOL_INFO];
+		card->ext_csd.device_life_time_est_typ_a =
+			ext_csd[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A];
+		card->ext_csd.device_life_time_est_typ_b =
+			ext_csd[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B];
+	}
+
+	return err;
+}
+
 /*
  * Decode extended CSD.
  */
@@ -367,6 +386,16 @@ static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd)
 	struct device_node *np;
 	bool broken_hpi = false;
 
+	/*
+	 * After once having initialized the ext_csd structure, we want to
+	 * update only the changing parts. To check this the revistion is
+	 * taken.
+	 */
+	if (card->ext_csd.rev != 0) {
+		err = mmc_update_ext_csd_runtime_params(card, ext_csd);
+		goto out;
+	}
+
 	/* Version is coded in the CSD_STRUCTURE byte in the EXT_CSD register */
 	card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE];
 	if (card->csd.structure == 3) {
@@ -791,10 +820,6 @@ MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name);
 MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid);
 MMC_DEV_ATTR(prv, "0x%x\n", card->cid.prv);
 MMC_DEV_ATTR(rev, "0x%x\n", card->ext_csd.rev);
-MMC_DEV_ATTR(pre_eol_info, "0x%02x\n", card->ext_csd.pre_eol_info);
-MMC_DEV_ATTR(life_time, "0x%02x 0x%02x\n",
-	card->ext_csd.device_life_time_est_typ_a,
-	card->ext_csd.device_life_time_est_typ_b);
 MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial);
 MMC_DEV_ATTR(enhanced_area_offset, "%llu\n",
 		card->ext_csd.enhanced_area_offset);
@@ -807,6 +832,60 @@ 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);
 
+static int mmc_update_csd(struct mmc_card *card)
+{
+	int err = 0;
+
+	mmc_claim_host(card->host);
+	err = mmc_read_ext_csd(card);
+	mmc_release_host(card->host);
+	return err;
+}
+
+static ssize_t life_time_show(struct device *dev,
+			      struct device_attribute *attr,
+			      char *buf)
+{
+	int err = 0;
+	struct mmc_card *card = mmc_dev_to_card(dev);
+
+	/* before eMMC v5 */
+	if (card->ext_csd.rev < 7)
+		return sprintf(buf, "%s\n", "-");
+
+	/* eMMC v5 or later */
+	err = mmc_update_csd(card);
+	if (err)
+		return (ssize_t)err;
+
+	return sprintf(buf, "0x%02x 0x%02x\n",
+				card->ext_csd.device_life_time_est_typ_a,
+				card->ext_csd.device_life_time_est_typ_b);
+}
+
+static DEVICE_ATTR_RO(life_time);
+
+static ssize_t pre_eol_info_show(struct device *dev,
+				 struct device_attribute *attr,
+				 char *buf)
+{
+	int err = 0;
+	struct mmc_card *card = mmc_dev_to_card(dev);
+
+	/* before eMMC v5 */
+	if (card->ext_csd.rev < 7)
+		return sprintf(buf, "%s\n", "-");
+
+	/* eMMC v5 or later */
+	err = mmc_update_csd(card);
+	if (err)
+		return (ssize_t)err;
+
+	return sprintf(buf, "0x%02x\n", card->ext_csd.pre_eol_info);
+}
+
+static DEVICE_ATTR_RO(pre_eol_info);
+
 static ssize_t mmc_fwrev_show(struct device *dev,
 			      struct device_attribute *attr,
 			      char *buf)
Signature · 1 line
2.20.1
#2 lore raw

RE: [PATCH 1/2] mmc: core: update life time and pre eol info values on sysfs read

Quoted 5 lines

The mmc estimated life time values and pre-eol info values were only read at start-up and were not updated on sysfs read.
Thus, added update of the ext_csd structure on sysfs read of device_life_time_est_typ_a, device_life_time_est_typ_b and pre_eol_info.

I agree that a snapshot on init doesn't make much sense.
But you can read it using mmc-utils, why not just remove the useless entries?

Thanks,
Avri

Quoted 129 lines
---
 drivers/mmc/core/mmc.c | 87
++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 83 insertions(+), 4 deletions(-)
drivers/mmc/core/mmc.c index renamed from drivers/mmc/core/mmc.c +0 -0

43d1b9b2fa49..d9537c894e33 100644

drivers/mmc/core/mmc.c +4 -0
@@ -357,6 +357,25 @@ static void mmc_manage_gp_partitions(struct
 mmc_card *card, u8 *ext_csd)
 /* Minimum partition switch timeout in milliseconds */
 #define MMC_MIN_PART_SWITCH_TIME       300
 
+/*
+ * Update extended CSD parameters changing during runtime.
+ */
+static int mmc_update_ext_csd_runtime_params(struct mmc_card *card,

u8

drivers/mmc/core/mmc.c +25 -0
+*ext_csd) {
+       int err = 0;
+
+       /* eMMC v5 or later */
+       if (card->ext_csd.rev >= 7) {
+               card->ext_csd.pre_eol_info = ext_csd[EXT_CSD_PRE_EOL_INFO];
+               card->ext_csd.device_life_time_est_typ_a =
+                       ext_csd[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A];
+               card->ext_csd.device_life_time_est_typ_b =
+                       ext_csd[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B];
+       }
+
+       return err;
+}
+
 /*
  * Decode extended CSD.
  */
@@ -367,6 +386,16 @@ static int mmc_decode_ext_csd(struct mmc_card
 *card, u8 *ext_csd)
        struct device_node *np;
        bool broken_hpi = false;
 
+       /*
+        * After once having initialized the ext_csd structure, we want to
+        * update only the changing parts. To check this the revistion is
+        * taken.
+        */
+       if (card->ext_csd.rev != 0) {
+               err = mmc_update_ext_csd_runtime_params(card, ext_csd);
+               goto out;
+       }
+
        /* Version is coded in the CSD_STRUCTURE byte in the EXT_CSD register
 */
        card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE];
        if (card->csd.structure == 3) {
drivers/mmc/core/mmc.c +0 -0
@@ -791,10 +820,6 @@ MMC_DEV_ATTR(name, "%s\n", card-
 >cid.prod_name);  MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid);
 MMC_DEV_ATTR(prv, "0x%x\n", card->cid.prv);  MMC_DEV_ATTR(rev,
 "0x%x\n", card->ext_csd.rev); -MMC_DEV_ATTR(pre_eol_info, "0x%02x\n",

card->ext_csd.pre_eol_info); -MMC_DEV_ATTR(life_time, "0x%02x 0x%02x\n",

drivers/mmc/core/mmc.c +0 -2
-       card->ext_csd.device_life_time_est_typ_a,
-       card->ext_csd.device_life_time_est_typ_b);
 MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial);

MMC_DEV_ATTR(enhanced_area_offset, "%llu\n",

                card->ext_csd.enhanced_area_offset);
drivers/mmc/core/mmc.c +51 -1
@@ -807,6 +832,60 @@ 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);
 
+static int mmc_update_csd(struct mmc_card *card) {
+       int err = 0;
+
+       mmc_claim_host(card->host);
+       err = mmc_read_ext_csd(card);
+       mmc_release_host(card->host);
+       return err;
+}
+
+static ssize_t life_time_show(struct device *dev,
+                             struct device_attribute *attr,
+                             char *buf) {
+       int err = 0;
+       struct mmc_card *card = mmc_dev_to_card(dev);
+
+       /* before eMMC v5 */
+       if (card->ext_csd.rev < 7)
+               return sprintf(buf, "%s\n", "-");
+
+       /* eMMC v5 or later */
+       err = mmc_update_csd(card);
+       if (err)
+               return (ssize_t)err;
+
+       return sprintf(buf, "0x%02x 0x%02x\n",
+                               card->ext_csd.device_life_time_est_typ_a,
+
+card->ext_csd.device_life_time_est_typ_b);
+}
+
+static DEVICE_ATTR_RO(life_time);
+
+static ssize_t pre_eol_info_show(struct device *dev,
+                                struct device_attribute *attr,
+                                char *buf) {
+       int err = 0;
+       struct mmc_card *card = mmc_dev_to_card(dev);
+
+       /* before eMMC v5 */
+       if (card->ext_csd.rev < 7)
+               return sprintf(buf, "%s\n", "-");
+
+       /* eMMC v5 or later */
+       err = mmc_update_csd(card);
+       if (err)
+               return (ssize_t)err;
+
+       return sprintf(buf, "0x%02x\n", card->ext_csd.pre_eol_info); }
+
+static DEVICE_ATTR_RO(pre_eol_info);
+
 static ssize_t mmc_fwrev_show(struct device *dev,
                              struct device_attribute *attr,
                              char *buf)
--

2.20.1

#3 lore raw

PATCH 2/2 mmc: core: add reliable write setting to sysfs and update on read

In reply to Marc Mattmueller

The mmc reliable write setting (from ext_csd) was not available on the sysfs.
Thus, added rel_param and rel_write_set to sysfs and added the update of rel_write_set on sysfs read.

---
 drivers/mmc/core/mmc.c   | 29 +++++++++++++++++++++++++++++
 include/linux/mmc/card.h |  1 +
 include/linux/mmc/mmc.h  |  1 +
 3 files changed, 31 insertions(+)
drivers/mmc/core/mmc.c +29 -0
index d9537c894e33..a64d1ecb0de9 100644
@@ -364,6 +364,10 @@ static int mmc_update_ext_csd_runtime_params(struct mmc_card *card, u8 *ext_csd)
 {
 	int err = 0;
 
+	/* eMMC v4.41 or later */
+	if (card->ext_csd.rev >= 5)
+		card->ext_csd.rel_wr_set = ext_csd[EXT_CSD_WR_REL_SET];
+
 	/* eMMC v5 or later */
 	if (card->ext_csd.rev >= 7) {
 		card->ext_csd.pre_eol_info = ext_csd[EXT_CSD_PRE_EOL_INFO];
@@ -587,6 +591,7 @@ static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd)
 		}
 
 		card->ext_csd.rel_param = ext_csd[EXT_CSD_WR_REL_PARAM];
+		card->ext_csd.rel_wr_set = ext_csd[EXT_CSD_WR_REL_SET];
 		card->ext_csd.rst_n_function = ext_csd[EXT_CSD_RST_N_FUNCTION];
 
 		/*
@@ -820,6 +825,7 @@ MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name);
 MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid);
 MMC_DEV_ATTR(prv, "0x%x\n", card->cid.prv);
 MMC_DEV_ATTR(rev, "0x%x\n", card->ext_csd.rev);
+MMC_DEV_ATTR(rel_param, "0x%02x\n", card->ext_csd.rel_param);
 MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial);
 MMC_DEV_ATTR(enhanced_area_offset, "%llu\n",
 		card->ext_csd.enhanced_area_offset);
@@ -886,6 +892,27 @@ static ssize_t pre_eol_info_show(struct device *dev,
 
 static DEVICE_ATTR_RO(pre_eol_info);
 
+static ssize_t rel_write_set_show(struct device *dev,
+				  struct device_attribute *attr,
+				  char *buf)
+{
+	int err = 0;
+	struct mmc_card *card = mmc_dev_to_card(dev);
+
+	/* before eMMC v4.41 */
+	if (card->ext_csd.rev < 5)
+		return sprintf(buf, "%s\n", "-");
+
+	/* eMMC v4.41 or later */
+	err = mmc_update_csd(card);
+	if (err)
+		return (ssize_t)err;
+
+	return sprintf(buf, "0x%02x\n", card->ext_csd.rel_wr_set);
+}
+
+static DEVICE_ATTR_RO(rel_write_set);
+
 static ssize_t mmc_fwrev_show(struct device *dev,
 			      struct device_attribute *attr,
 			      char *buf)
@@ -931,6 +958,8 @@ static struct attribute *mmc_std_attrs[] = {
 	&dev_attr_oemid.attr,
 	&dev_attr_prv.attr,
 	&dev_attr_rev.attr,
+	&dev_attr_rel_param.attr,
+	&dev_attr_rel_write_set.attr,
 	&dev_attr_pre_eol_info.attr,
 	&dev_attr_life_time.attr,
 	&dev_attr_serial.attr,
include/linux/mmc/card.h +1 -0
index 37f975875102..21c47893fcb4 100644
@@ -48,6 +48,7 @@ struct mmc_ext_csd {
 	u8			sec_feature_support;
 	u8			rel_sectors;
 	u8			rel_param;
+	u8			rel_wr_set;
 	bool			enhanced_rpmb_supported;
 	u8			part_config;
 	u8			cache_ctrl;
include/linux/mmc/mmc.h +1 -0
index d9a65c6a8816..42afd442a70a 100644
@@ -266,6 +266,7 @@ static inline bool mmc_ready_for_data(u32 status)
 #define EXT_CSD_BKOPS_START		164	/* W */
 #define EXT_CSD_SANITIZE_START		165     /* W */
 #define EXT_CSD_WR_REL_PARAM		166	/* RO */
+#define EXT_CSD_WR_REL_SET		167	/* R/W */
 #define EXT_CSD_RPMB_MULT		168	/* RO */
 #define EXT_CSD_FW_CONFIG		169	/* R/W */
 #define EXT_CSD_BOOT_WP			173	/* R/W */
Signature · 1 line
2.20.1
#4 lore raw

RE: [PATCH 2/2] mmc: core: add reliable write setting to sysfs and update on read

Quoted 4 lines

The mmc reliable write setting (from ext_csd) was not available on the sysfs. Thus, added rel_param and rel_write_set to sysfs and added the update of rel_write_set on sysfs read.

Here also - why adding ABI when its already available via mmc-utils?

Thanks,
Avri

Quoted 104 lines
---
 drivers/mmc/core/mmc.c   | 29 +++++++++++++++++++++++++++++
 include/linux/mmc/card.h |  1 +
 include/linux/mmc/mmc.h  |  1 +
 3 files changed, 31 insertions(+)
drivers/mmc/core/mmc.c index renamed from drivers/mmc/core/mmc.c +0 -0

d9537c894e33..a64d1ecb0de9 100644

drivers/mmc/core/mmc.c +0 -0
@@ -364,6 +364,10 @@ static int

mmc_update_ext_csd_runtime_params(struct mmc_card *card, u8

*ext_csd)  {
        int err = 0;
drivers/mmc/core/mmc.c +5 -0
+       /* eMMC v4.41 or later */
+       if (card->ext_csd.rev >= 5)
+               card->ext_csd.rel_wr_set = ext_csd[EXT_CSD_WR_REL_SET];
+
        /* eMMC v5 or later */
        if (card->ext_csd.rev >= 7) {
                card->ext_csd.pre_eol_info = ext_csd[EXT_CSD_PRE_EOL_INFO];
@@ -587,6 +591,7 @@ static int mmc_decode_ext_csd(struct mmc_card
 *card, u8 *ext_csd)
                }
 
                card->ext_csd.rel_param = ext_csd[EXT_CSD_WR_REL_PARAM];
+               card->ext_csd.rel_wr_set = ext_csd[EXT_CSD_WR_REL_SET];
                card->ext_csd.rst_n_function =
 ext_csd[EXT_CSD_RST_N_FUNCTION];
                /*
drivers/mmc/core/mmc.c +20 -0
@@ -820,6 +825,7 @@ MMC_DEV_ATTR(name, "%s\n", card-
 >cid.prod_name);  MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid);
 MMC_DEV_ATTR(prv, "0x%x\n", card->cid.prv);  MMC_DEV_ATTR(rev,
 "0x%x\n", card->ext_csd.rev);
+MMC_DEV_ATTR(rel_param, "0x%02x\n", card->ext_csd.rel_param);
 MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial);
 MMC_DEV_ATTR(enhanced_area_offset, "%llu\n",
                card->ext_csd.enhanced_area_offset);
@@ -886,6 +892,27 @@ static ssize_t pre_eol_info_show(struct device
 *dev,
 
 static DEVICE_ATTR_RO(pre_eol_info);
 
+static ssize_t rel_write_set_show(struct device *dev,
+                                 struct device_attribute *attr,
+                                 char *buf) {
+       int err = 0;
+       struct mmc_card *card = mmc_dev_to_card(dev);
+
+       /* before eMMC v4.41 */
+       if (card->ext_csd.rev < 5)
+               return sprintf(buf, "%s\n", "-");
+
+       /* eMMC v4.41 or later */
+       err = mmc_update_csd(card);
+       if (err)
+               return (ssize_t)err;
+
+       return sprintf(buf, "0x%02x\n", card->ext_csd.rel_wr_set); }
+
+static DEVICE_ATTR_RO(rel_write_set);
+
 static ssize_t mmc_fwrev_show(struct device *dev,
                              struct device_attribute *attr,
                              char *buf) @@ -931,6 +958,8 @@ static struct attribute
*mmc_std_attrs[] = {
        &dev_attr_oemid.attr,
        &dev_attr_prv.attr,
        &dev_attr_rev.attr,
drivers/mmc/core/mmc.c +2 -0
+       &dev_attr_rel_param.attr,
+       &dev_attr_rel_write_set.attr,
        &dev_attr_pre_eol_info.attr,
        &dev_attr_life_time.attr,
        &dev_attr_serial.attr,
include/linux/mmc/card.h index renamed from include/linux/mmc/card.h +0 -0

37f975875102..21c47893fcb4 100644

include/linux/mmc/card.h +1 -0
@@ -48,6 +48,7 @@ struct mmc_ext_csd {
        u8                      sec_feature_support;
        u8                      rel_sectors;
        u8                      rel_param;
+       u8                      rel_wr_set;
        bool                    enhanced_rpmb_supported;
        u8                      part_config;
        u8                      cache_ctrl;
include/linux/mmc/mmc.h index renamed from include/linux/mmc/mmc.h +0 -0

d9a65c6a8816..42afd442a70a 100644

include/linux/mmc/mmc.h +1 -1
@@ -266,6 +266,7 @@ static inline bool mmc_ready_for_data(u32 status)
 #define EXT_CSD_BKOPS_START            164     /* W */
 #define EXT_CSD_SANITIZE_START         165     /* W */
 #define EXT_CSD_WR_REL_PARAM           166     /* RO */
+#define EXT_CSD_WR_REL_SET             167     /* R/W */
 #define EXT_CSD_RPMB_MULT              168     /* RO */
 #define EXT_CSD_FW_CONFIG              169     /* R/W */
 #define EXT_CSD_BOOT_WP                        173     /* R/W */
--

2.20.1

#5 lore raw

Re: [PATCH 2/2] mmc: core: add reliable write setting to sysfs and update on read

Quoted 9 lines · Avri Altman
Quoted 5 lines

The mmc reliable write setting (from ext_csd) was not available on the sysfs. Thus, added rel_param and rel_write_set to sysfs and added the update of rel_write_set on sysfs read.

Here also - why adding ABI when its already available via mmc-utils?

Thanks,
Avri

FYI, I agree with Avri here. Please use mmc-utils.

In case the values in sysfs become confusing as they may be outdated at some point, perhaps we should consider dropping them?

Kind regards
Uffe

Quoted 106 lines
Quoted 105 lines
---
 drivers/mmc/core/mmc.c   | 29 +++++++++++++++++++++++++++++
 include/linux/mmc/card.h |  1 +
 include/linux/mmc/mmc.h  |  1 +
 3 files changed, 31 insertions(+)
drivers/mmc/core/mmc.c index renamed from drivers/mmc/core/mmc.c +0 -0

d9537c894e33..a64d1ecb0de9 100644

drivers/mmc/core/mmc.c +0 -0
@@ -364,6 +364,10 @@ static int

mmc_update_ext_csd_runtime_params(struct mmc_card *card, u8

*ext_csd)  {
        int err = 0;
drivers/mmc/core/mmc.c +5 -0
+       /* eMMC v4.41 or later */
+       if (card->ext_csd.rev >= 5)
+               card->ext_csd.rel_wr_set = ext_csd[EXT_CSD_WR_REL_SET];
+
        /* eMMC v5 or later */
        if (card->ext_csd.rev >= 7) {
                card->ext_csd.pre_eol_info = ext_csd[EXT_CSD_PRE_EOL_INFO];
@@ -587,6 +591,7 @@ static int mmc_decode_ext_csd(struct mmc_card
 *card, u8 *ext_csd)
                }
 
                card->ext_csd.rel_param = ext_csd[EXT_CSD_WR_REL_PARAM];
+               card->ext_csd.rel_wr_set = ext_csd[EXT_CSD_WR_REL_SET];
                card->ext_csd.rst_n_function =
 ext_csd[EXT_CSD_RST_N_FUNCTION];
                /*
drivers/mmc/core/mmc.c +20 -0
@@ -820,6 +825,7 @@ MMC_DEV_ATTR(name, "%s\n", card-
 >cid.prod_name);  MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid);
 MMC_DEV_ATTR(prv, "0x%x\n", card->cid.prv);  MMC_DEV_ATTR(rev,
 "0x%x\n", card->ext_csd.rev);
+MMC_DEV_ATTR(rel_param, "0x%02x\n", card->ext_csd.rel_param);
 MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial);
 MMC_DEV_ATTR(enhanced_area_offset, "%llu\n",
                card->ext_csd.enhanced_area_offset);
@@ -886,6 +892,27 @@ static ssize_t pre_eol_info_show(struct device
 *dev,
 
 static DEVICE_ATTR_RO(pre_eol_info);
 
+static ssize_t rel_write_set_show(struct device *dev,
+                                 struct device_attribute *attr,
+                                 char *buf) {
+       int err = 0;
+       struct mmc_card *card = mmc_dev_to_card(dev);
+
+       /* before eMMC v4.41 */
+       if (card->ext_csd.rev < 5)
+               return sprintf(buf, "%s\n", "-");
+
+       /* eMMC v4.41 or later */
+       err = mmc_update_csd(card);
+       if (err)
+               return (ssize_t)err;
+
+       return sprintf(buf, "0x%02x\n", card->ext_csd.rel_wr_set); }
+
+static DEVICE_ATTR_RO(rel_write_set);
+
 static ssize_t mmc_fwrev_show(struct device *dev,
                              struct device_attribute *attr,
                              char *buf) @@ -931,6 +958,8 @@ static struct attribute
*mmc_std_attrs[] = {
        &dev_attr_oemid.attr,
        &dev_attr_prv.attr,
        &dev_attr_rev.attr,
drivers/mmc/core/mmc.c +2 -0
+       &dev_attr_rel_param.attr,
+       &dev_attr_rel_write_set.attr,
        &dev_attr_pre_eol_info.attr,
        &dev_attr_life_time.attr,
        &dev_attr_serial.attr,
include/linux/mmc/card.h index renamed from include/linux/mmc/card.h +0 -0

37f975875102..21c47893fcb4 100644

include/linux/mmc/card.h +1 -0
@@ -48,6 +48,7 @@ struct mmc_ext_csd {
        u8                      sec_feature_support;
        u8                      rel_sectors;
        u8                      rel_param;
+       u8                      rel_wr_set;
        bool                    enhanced_rpmb_supported;
        u8                      part_config;
        u8                      cache_ctrl;
include/linux/mmc/mmc.h index renamed from include/linux/mmc/mmc.h +0 -0

d9a65c6a8816..42afd442a70a 100644

include/linux/mmc/mmc.h +1 -1
@@ -266,6 +266,7 @@ static inline bool mmc_ready_for_data(u32 status)
 #define EXT_CSD_BKOPS_START            164     /* W */
 #define EXT_CSD_SANITIZE_START         165     /* W */
 #define EXT_CSD_WR_REL_PARAM           166     /* RO */
+#define EXT_CSD_WR_REL_SET             167     /* R/W */
 #define EXT_CSD_RPMB_MULT              168     /* RO */
 #define EXT_CSD_FW_CONFIG              169     /* R/W */
 #define EXT_CSD_BOOT_WP                        173     /* R/W */
--

2.20.1

#6 lore raw

Re: [PATCH 2/2] mmc: core: add reliable write setting to sysfs and update on read

Quoted 14 lines · Ulf Hansson
Quoted 11 lines · Avri Altman
Quoted 6 lines

The mmc reliable write setting (from ext_csd) was not available on the sysfs.
Thus, added rel_param and rel_write_set to sysfs and added the update of
rel_write_set on sysfs read.

Here also - why adding ABI when its already available via mmc- utils?

Thanks,
Avri

Quoted 7 lines

FYI, I agree with Avri here. Please use mmc-utils.

In case the values in sysfs become confusing as they may be outdated at some point, perhaps we should consider dropping them?

Kind regards
Uffe

Hi,
yes I was confused about having the lifetime values available in the sysfs but without having an update over time. The reliable write values were some kind of logic for me to add them as well. That's why I was hesitating first to create a single patch for all these values but as it concerns two different topics I decided to create a patchset.

Nevertheless, if you propose to use the mmc-utils for the dynamic values, it is less confusing if you just keep only the static values and drop the dynamic ones.

Kind regards
Marc

Quoted 116 lines
Quoted 116 lines
Quoted 116 lines
---
 drivers/mmc/core/mmc.c   | 29 +++++++++++++++++++++++++++++
 include/linux/mmc/card.h |  1 +
 include/linux/mmc/mmc.h  |  1 +
 3 files changed, 31 insertions(+)
drivers/mmc/core/mmc.c +0 -0

index
d9537c894e33..a64d1ecb0de9 100644

drivers/mmc/core/mmc.c +0 -0
@@ -364,6 +364,10 @@ static int

mmc_update_ext_csd_runtime_params(struct mmc_card *card, u8

*ext_csd)  {
        int err = 0;
drivers/mmc/core/mmc.c +3 -0
+       /* eMMC v4.41 or later */
+       if (card->ext_csd.rev >= 5)
+               card->ext_csd.rel_wr_set =

ext_csd[EXT_CSD_WR_REL_SET];
+

        /* eMMC v5 or later */
        if (card->ext_csd.rev >= 7) {
                card->ext_csd.pre_eol_info =

ext_csd[EXT_CSD_PRE_EOL_INFO];

drivers/mmc/core/mmc.c +1 -0
@@ -587,6 +591,7 @@ static int mmc_decode_ext_csd(struct mmc_card
 *card, u8 *ext_csd)
                }
 
                card->ext_csd.rel_param =
 ext_csd[EXT_CSD_WR_REL_PARAM];
+               card->ext_csd.rel_wr_set =
 ext_csd[EXT_CSD_WR_REL_SET];
                card->ext_csd.rst_n_function =

ext_csd[EXT_CSD_RST_N_FUNCTION];

                /*
drivers/mmc/core/mmc.c +0 -0
@@ -820,6 +825,7 @@ MMC_DEV_ATTR(name, "%s\n", card-
Quoted 2 lines

cid.prod_name); MMC_DEV_ATTR(oemid, "0x%04x\n", card-

Quoted 1 line

cid.oemid);

MMC_DEV_ATTR(prv, "0x%x\n", card->cid.prv); MMC_DEV_ATTR(rev, "0x%x\n", card->ext_csd.rev); +MMC_DEV_ATTR(rel_param, "0x%02x\n", card->ext_csd.rel_param);
MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial);
MMC_DEV_ATTR(enhanced_area_offset, "%llu\n",

                card->ext_csd.enhanced_area_offset);
drivers/mmc/core/mmc.c +0 -0
@@ -886,6 +892,27 @@ static ssize_t pre_eol_info_show(struct

device
*dev,

static DEVICE_ATTR_RO(pre_eol_info);

drivers/mmc/core/mmc.c +16 -0
+static ssize_t rel_write_set_show(struct device *dev,
+                                 struct device_attribute *attr,
+                                 char *buf) {
+       int err = 0;
+       struct mmc_card *card = mmc_dev_to_card(dev);
+
+       /* before eMMC v4.41 */
+       if (card->ext_csd.rev < 5)
+               return sprintf(buf, "%s\n", "-");
+
+       /* eMMC v4.41 or later */
+       err = mmc_update_csd(card);
+       if (err)
+               return (ssize_t)err;
+
+       return sprintf(buf, "0x%02x\n", card-
Quoted 1 line

ext_csd.rel_wr_set); }

drivers/mmc/core/mmc.c +3 -0
+
+static DEVICE_ATTR_RO(rel_write_set);
+
 static ssize_t mmc_fwrev_show(struct device *dev,
                              struct device_attribute *attr,
                              char *buf) @@ -931,6 +958,8 @@

static struct attribute

*mmc_std_attrs[] = {
        &dev_attr_oemid.attr,
        &dev_attr_prv.attr,
        &dev_attr_rev.attr,
drivers/mmc/core/mmc.c +2 -0
+       &dev_attr_rel_param.attr,
+       &dev_attr_rel_write_set.attr,
        &dev_attr_pre_eol_info.attr,
        &dev_attr_life_time.attr,
        &dev_attr_serial.attr,
include/linux/mmc/card.h +0 -0

index
37f975875102..21c47893fcb4 100644

include/linux/mmc/card.h +1 -0
@@ -48,6 +48,7 @@ struct mmc_ext_csd {
        u8                      sec_feature_support;
        u8                      rel_sectors;
        u8                      rel_param;
+       u8                      rel_wr_set;
        bool                    enhanced_rpmb_supported;
        u8                      part_config;
        u8                      cache_ctrl;
include/linux/mmc/mmc.h +0 -0

index
d9a65c6a8816..42afd442a70a 100644

include/linux/mmc/mmc.h +1 -0
@@ -266,6 +266,7 @@ static inline bool mmc_ready_for_data(u32
 status)
 #define EXT_CSD_BKOPS_START            164     /* W */
 #define EXT_CSD_SANITIZE_START         165     /* W */
 #define EXT_CSD_WR_REL_PARAM           166     /* RO */
+#define EXT_CSD_WR_REL_SET             167     /* R/W */
 #define EXT_CSD_RPMB_MULT              168     /* RO */
 #define EXT_CSD_FW_CONFIG              169     /* R/W */

#define EXT_CSD_BOOT_WP 173 /* R/W */
--
2.20.1

#7 lore raw

Re: [PATCH 2/2] mmc: core: add reliable write setting to sysfs and update on read

Quoted 31 lines · Marc Mattmüller
Quoted 14 lines · Ulf Hansson
Quoted 11 lines · Avri Altman
Quoted 6 lines

The mmc reliable write setting (from ext_csd) was not available on the sysfs.
Thus, added rel_param and rel_write_set to sysfs and added the update of
rel_write_set on sysfs read.

Here also - why adding ABI when its already available via mmc- utils?

Thanks,
Avri

Quoted 7 lines

FYI, I agree with Avri here. Please use mmc-utils.

In case the values in sysfs become confusing as they may be outdated at some point, perhaps we should consider dropping them?

Kind regards
Uffe

Hi,
yes I was confused about having the lifetime values available in the sysfs but without having an update over time. The reliable write values were some kind of logic for me to add them as well. That's why I was hesitating first to create a single patch for all these values but as it concerns two different topics I decided to create a patchset.

Quoted 3 lines

Nevertheless, if you propose to use the mmc-utils for the dynamic values, it is less confusing if you just keep only the static values and drop the dynamic ones.

Okay, that sounds reasonable - and thanks for clarifying.

Kind regards
Uffe

Quoted 120 lines

Kind regards
Marc

Quoted 116 lines
Quoted 116 lines
Quoted 116 lines
---
 drivers/mmc/core/mmc.c   | 29 +++++++++++++++++++++++++++++
 include/linux/mmc/card.h |  1 +
 include/linux/mmc/mmc.h  |  1 +
 3 files changed, 31 insertions(+)
drivers/mmc/core/mmc.c +0 -0

index
d9537c894e33..a64d1ecb0de9 100644

drivers/mmc/core/mmc.c +0 -0
@@ -364,6 +364,10 @@ static int

mmc_update_ext_csd_runtime_params(struct mmc_card *card, u8

*ext_csd)  {
        int err = 0;
drivers/mmc/core/mmc.c +3 -0
+       /* eMMC v4.41 or later */
+       if (card->ext_csd.rev >= 5)
+               card->ext_csd.rel_wr_set =

ext_csd[EXT_CSD_WR_REL_SET];
+

        /* eMMC v5 or later */
        if (card->ext_csd.rev >= 7) {
                card->ext_csd.pre_eol_info =

ext_csd[EXT_CSD_PRE_EOL_INFO];

drivers/mmc/core/mmc.c +1 -0
@@ -587,6 +591,7 @@ static int mmc_decode_ext_csd(struct mmc_card
 *card, u8 *ext_csd)
                }
 
                card->ext_csd.rel_param =
 ext_csd[EXT_CSD_WR_REL_PARAM];
+               card->ext_csd.rel_wr_set =
 ext_csd[EXT_CSD_WR_REL_SET];
                card->ext_csd.rst_n_function =

ext_csd[EXT_CSD_RST_N_FUNCTION];

                /*
drivers/mmc/core/mmc.c +0 -0
@@ -820,6 +825,7 @@ MMC_DEV_ATTR(name, "%s\n", card-
Quoted 2 lines

cid.prod_name); MMC_DEV_ATTR(oemid, "0x%04x\n", card-

Quoted 1 line

cid.oemid);

MMC_DEV_ATTR(prv, "0x%x\n", card->cid.prv); MMC_DEV_ATTR(rev, "0x%x\n", card->ext_csd.rev); +MMC_DEV_ATTR(rel_param, "0x%02x\n", card->ext_csd.rel_param);
MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial);
MMC_DEV_ATTR(enhanced_area_offset, "%llu\n",

                card->ext_csd.enhanced_area_offset);
drivers/mmc/core/mmc.c +0 -0
@@ -886,6 +892,27 @@ static ssize_t pre_eol_info_show(struct

device
*dev,

static DEVICE_ATTR_RO(pre_eol_info);

drivers/mmc/core/mmc.c +16 -0
+static ssize_t rel_write_set_show(struct device *dev,
+                                 struct device_attribute *attr,
+                                 char *buf) {
+       int err = 0;
+       struct mmc_card *card = mmc_dev_to_card(dev);
+
+       /* before eMMC v4.41 */
+       if (card->ext_csd.rev < 5)
+               return sprintf(buf, "%s\n", "-");
+
+       /* eMMC v4.41 or later */
+       err = mmc_update_csd(card);
+       if (err)
+               return (ssize_t)err;
+
+       return sprintf(buf, "0x%02x\n", card-
Quoted 1 line

ext_csd.rel_wr_set); }

drivers/mmc/core/mmc.c +3 -0
+
+static DEVICE_ATTR_RO(rel_write_set);
+
 static ssize_t mmc_fwrev_show(struct device *dev,
                              struct device_attribute *attr,
                              char *buf) @@ -931,6 +958,8 @@

static struct attribute

*mmc_std_attrs[] = {
        &dev_attr_oemid.attr,
        &dev_attr_prv.attr,
        &dev_attr_rev.attr,
drivers/mmc/core/mmc.c +2 -0
+       &dev_attr_rel_param.attr,
+       &dev_attr_rel_write_set.attr,
        &dev_attr_pre_eol_info.attr,
        &dev_attr_life_time.attr,
        &dev_attr_serial.attr,
include/linux/mmc/card.h +0 -0

index
37f975875102..21c47893fcb4 100644

include/linux/mmc/card.h +1 -0
@@ -48,6 +48,7 @@ struct mmc_ext_csd {
        u8                      sec_feature_support;
        u8                      rel_sectors;
        u8                      rel_param;
+       u8                      rel_wr_set;
        bool                    enhanced_rpmb_supported;
        u8                      part_config;
        u8                      cache_ctrl;
include/linux/mmc/mmc.h +0 -0

index
d9a65c6a8816..42afd442a70a 100644

include/linux/mmc/mmc.h +1 -0
@@ -266,6 +266,7 @@ static inline bool mmc_ready_for_data(u32
 status)
 #define EXT_CSD_BKOPS_START            164     /* W */
 #define EXT_CSD_SANITIZE_START         165     /* W */
 #define EXT_CSD_WR_REL_PARAM           166     /* RO */
+#define EXT_CSD_WR_REL_SET             167     /* R/W */
 #define EXT_CSD_RPMB_MULT              168     /* RO */
 #define EXT_CSD_FW_CONFIG              169     /* R/W */

#define EXT_CSD_BOOT_WP 173 /* R/W */
--
2.20.1