mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marc Mattmueller <marc.mattmueller@netmodule.com>
To: ulf.hansson@linaro.org, linux-mmc@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Marc Mattmueller <marc.mattmueller@netmodule.com>
Subject: [PATCH 1/2] mmc: core: update life time and pre eol info values on sysfs read
Date: Wed,  9 Mar 2022 11:40:20 +0100	[thread overview]
Message-ID: <5fe56c7fe12d48996ba557596b16b1cd0adca6a2.1646820083.git.marc.mattmueller@netmodule.com> (raw)
In-Reply-To: <cover.1646820083.git.marc.mattmueller@netmodule.com>

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.

Signed-off-by: Marc Mattmueller <marc.mattmueller@netmodule.com>
---
 drivers/mmc/core/mmc.c | 87 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 83 insertions(+), 4 deletions(-)

diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 43d1b9b2fa49..d9537c894e33 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -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)
-- 
2.20.1


  reply	other threads:[~2022-03-09 10:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-09 10:40 [PATCH 0/2] mmc: update life time and rel write " Marc Mattmueller
2022-03-09 10:40 ` Marc Mattmueller [this message]
2022-03-10 14:07   ` [PATCH 1/2] mmc: core: update life time and pre eol info values " Avri Altman
2022-03-09 10:40 ` [PATCH 2/2] mmc: core: add reliable write setting to sysfs and update on read Marc Mattmueller
2022-03-10 14:08   ` Avri Altman
2022-03-15  9:39     ` Ulf Hansson
2022-03-15 12:39       ` Marc Mattmüller
2022-03-15 13:41         ` Ulf Hansson

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=5fe56c7fe12d48996ba557596b16b1cd0adca6a2.1646820083.git.marc.mattmueller@netmodule.com \
    --to=marc.mattmueller@netmodule.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®