Skip to contentSkip to conversation

mmc: sd: Add a variable to check a faulty device

PATCH In review Seunghui Lee 5 participants 14 messages Feb 13, 2024 – Mar 1, 2024 1 message not in the archive MMC, SD and SDIO

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CGME20240213051332epcas1p1f45d02dc34d1b95ea5608ab779d6b6cc@epcas1p1.samsung.com

#1 lore raw

PATCH 1/1 mmc: sd: Add a variable to check a faulty device

In mobile devices, suspend/resume situations are frequent. In the case of a defective SD card in which initialization fails, unnecessary initialization time is consumed for each resume. A field is needed to check that SD card initialization has failed on the host. It could be used to remove unnecessary initialization.

---
 drivers/mmc/core/sd.c        | 12 +++++++++++-
 drivers/mmc/core/slot-gpio.c |  1 +
 include/linux/mmc/host.h     |  1 +
 3 files changed, 13 insertions(+), 1 deletion(-)
drivers/mmc/core/sd.c +11 -1
index c3e554344c99..f0eb3864dc24 100644
@@ -1410,6 +1410,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
 	bool v18_fixup_failed = false;
 
 	WARN_ON(!host->claimed);
+	host->init_failed = false;
 retry:
 	err = mmc_sd_get_cid(host, ocr, cid, &rocr);
 	if (err)
@@ -1752,6 +1753,8 @@ static int _mmc_sd_resume(struct mmc_host *host)
 
 	mmc_power_up(host, host->card->ocr);
 	err = mmc_sd_init_card(host, host->card->ocr, host->card);
+	if (err)
+		host->init_failed = true;
 	mmc_card_clr_suspended(host->card);
 
 out:
@@ -1803,8 +1806,12 @@ static int mmc_sd_runtime_resume(struct mmc_host *host)
 
 static int mmc_sd_hw_reset(struct mmc_host *host)
 {
+	int err;
 	mmc_power_cycle(host, host->card->ocr);
-	return mmc_sd_init_card(host, host->card->ocr, host->card);
+	err = mmc_sd_init_card(host, host->card->ocr, host->card);
+	if (err)
+		host->init_failed = true;
+	return err;
 }
 
 static const struct mmc_bus_ops mmc_sd_ops = {
@@ -1891,5 +1898,8 @@ int mmc_attach_sd(struct mmc_host *host)
 	pr_err("%s: error %d whilst initialising SD card\n",
 		mmc_hostname(host), err);
 
+	if (err)
+		host->init_failed = true;
+
 	return err;
 }
drivers/mmc/core/slot-gpio.c +1 -0
index 2a2d949a9344..93d081c7dd53 100644
@@ -33,6 +33,7 @@ static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id)
 	struct mmc_gpio *ctx = host->slot.handler_priv;
 
 	host->trigger_card_event = true;
+	host->init_failed = false;
 	mmc_detect_change(host, msecs_to_jiffies(ctx->cd_debounce_delay_ms));
 
 	return IRQ_HANDLED;
include/linux/mmc/host.h +1 -0
index 2f445c651742..1d75cfdbf981 100644
@@ -467,6 +467,7 @@ struct mmc_host {
 	struct timer_list	retune_timer;	/* for periodic re-tuning */
 
 	bool			trigger_card_event; /* card_event necessary */
+	bool			init_failed;	/* check if failed to initialize */
 
 	struct mmc_card		*card;		/* device attached to this host */
 
Signature · 1 line
2.29.0
#2 lore raw
Quoted 5 lines

In mobile devices, suspend/resume situations are frequent.
In the case of a defective SD card in which initialization fails, unnecessary initialization time is consumed for each resume.
A field is needed to check that SD card initialization has failed on the host. It could be used to remove unnecessary initialization.

I don't see where you are using this new init_failed field?
Maybe instead, elaborate the logic to free_card: to detect a broken sd. e.g. instead of just if (!oldcard), if (!oldcard || ! mmc_sd_alive(host)) or something.

Thanks,
Avri

Quoted 79 lines
---
 drivers/mmc/core/sd.c        | 12 +++++++++++-
 drivers/mmc/core/slot-gpio.c |  1 +
 include/linux/mmc/host.h     |  1 +
 3 files changed, 13 insertions(+), 1 deletion(-)
drivers/mmc/core/sd.c index renamed from drivers/mmc/core/sd.c +0 -0

c3e554344c99..f0eb3864dc24 100644

drivers/mmc/core/sd.c +1 -0
@@ -1410,6 +1410,7 @@ static int mmc_sd_init_card(struct mmc_host *host,
 u32 ocr,
        bool v18_fixup_failed = false;
 
        WARN_ON(!host->claimed);
+       host->init_failed = false;
 retry:
        err = mmc_sd_get_cid(host, ocr, cid, &rocr);

if (err)

drivers/mmc/core/sd.c +7 -1
@@ -1752,6 +1753,8 @@ static int _mmc_sd_resume(struct mmc_host *host)
 
        mmc_power_up(host, host->card->ocr);
        err = mmc_sd_init_card(host, host->card->ocr, host->card);
+       if (err)
+               host->init_failed = true;
        mmc_card_clr_suspended(host->card);
 
 out:
@@ -1803,8 +1806,12 @@ static int mmc_sd_runtime_resume(struct
 mmc_host *host)
 
 static int mmc_sd_hw_reset(struct mmc_host *host)  {
+       int err;
        mmc_power_cycle(host, host->card->ocr);
-       return mmc_sd_init_card(host, host->card->ocr, host->card);
+       err = mmc_sd_init_card(host, host->card->ocr, host->card);
+       if (err)
+               host->init_failed = true;
+       return err;
 }
 
 static const struct mmc_bus_ops mmc_sd_ops = { @@ -1891,5 +1898,8 @@ int

mmc_attach_sd(struct mmc_host *host)
pr_err("%s: error %d whilst initialising SD card\n",
mmc_hostname(host), err);

drivers/mmc/core/sd.c +3 -0
+       if (err)
+               host->init_failed = true;
+
        return err;
 }
drivers/mmc/core/slot-gpio.c index renamed from drivers/mmc/core/slot-gpio.c +0 -0

2a2d949a9344..93d081c7dd53 100644

drivers/mmc/core/slot-gpio.c +1 -0
@@ -33,6 +33,7 @@ static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id)
        struct mmc_gpio *ctx = host->slot.handler_priv;
 
        host->trigger_card_event = true;
+       host->init_failed = false;
        mmc_detect_change(host, msecs_to_jiffies(ctx->cd_debounce_delay_ms));
 
        return IRQ_HANDLED;
include/linux/mmc/host.h index renamed from include/linux/mmc/host.h +0 -0

2f445c651742..1d75cfdbf981 100644

include/linux/mmc/host.h +1 -1
@@ -467,6 +467,7 @@ struct mmc_host {
        struct timer_list       retune_timer;   /* for periodic re-tuning */
 
        bool                    trigger_card_event; /* card_event necessary */
+       bool                    init_failed;    /* check if failed to initialize */
 
        struct mmc_card         *card;          /* device attached to this host */
 
--

2.29.0

author
#3 lore raw
Quoted 18 lines

-----Original Message-----
From: Avri Altman <[email protected]>
Sent: Tuesday, February 13, 2024 5:42 PM
To: Seunghui Lee <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH] mmc: sd: Add a variable to check a faulty device

Quoted 5 lines

In mobile devices, suspend/resume situations are frequent. In the case of a defective SD card in which initialization fails, unnecessary initialization time is consumed for each resume. A field is needed to check that SD card initialization has failed on the host. It could be used to remove unnecessary initialization.

Quoted 8 lines

I don't see where you are using this new init_failed field? Maybe instead, elaborate the logic to free_card: to detect a broken sd. e.g. instead of just if (!oldcard), if (!oldcard || ! mmc_sd_alive(host)) or something.

Thanks,
Avri

Thank you for your suggestion.
I'm going to use it in mmc_rescan as below.

e.g.

drivers/mmc/core/core.c +1 -1
@@ -2210,7 +2210,7 @@ void mmc_rescan(struct work_struct *work)
                container_of(work, struct mmc_host, detect.work);
        int i;
 
-       if (host->rescan_disable)
+       if (host->rescan_disable || host->init_failed)
                return;
Quoted 85 lines

drivers/mmc/core/slot-gpio.c static irqreturn_t mmc_gpio_cd_irqt(int irq, void

Quoted 60 lines
---
 drivers/mmc/core/sd.c        | 12 +++++++++++-
 drivers/mmc/core/slot-gpio.c |  1 +
 include/linux/mmc/host.h     |  1 +
 3 files changed, 13 insertions(+), 1 deletion(-)
drivers/mmc/core/sd.c index renamed from drivers/mmc/core/sd.c +0 -0

c3e554344c99..f0eb3864dc24 100644

drivers/mmc/core/sd.c +1 -0
@@ -1410,6 +1410,7 @@ static int mmc_sd_init_card(struct mmc_host
 *host,
 u32 ocr,
        bool v18_fixup_failed = false;
 
        WARN_ON(!host->claimed);
+       host->init_failed = false;
 retry:
        err = mmc_sd_get_cid(host, ocr, cid, &rocr);
        if (err)
drivers/mmc/core/sd.c +7 -1
@@ -1752,6 +1753,8 @@ static int _mmc_sd_resume(struct mmc_host *host)
 
        mmc_power_up(host, host->card->ocr);
        err = mmc_sd_init_card(host, host->card->ocr, host->card);
+       if (err)
+               host->init_failed = true;
        mmc_card_clr_suspended(host->card);
 
 out:
@@ -1803,8 +1806,12 @@ static int mmc_sd_runtime_resume(struct
 mmc_host *host)
 
 static int mmc_sd_hw_reset(struct mmc_host *host)  {
+       int err;
        mmc_power_cycle(host, host->card->ocr);
-       return mmc_sd_init_card(host, host->card->ocr, host->card);
+       err = mmc_sd_init_card(host, host->card->ocr, host->card);
+       if (err)
+               host->init_failed = true;
+       return err;
 }
 
 static const struct mmc_bus_ops mmc_sd_ops = { @@ -1891,5 +1898,8 @@

int mmc_attach_sd(struct mmc_host *host)
pr_err("%s: error %d whilst initialising SD card\n",
mmc_hostname(host), err);

drivers/mmc/core/sd.c +3 -0
+       if (err)
+               host->init_failed = true;
+
        return err;
 }
(quoted diff) +0 -0

b/drivers/mmc/core/slot-gpio.c index
2a2d949a9344..93d081c7dd53 100644

drivers/mmc/core/slot-gpio.c +0 -0
@@ -33,6 +33,7 @@ static irqreturn_t mmc_gpio_cd_irqt(int irq, void

*dev_id)

Quoted 13 lines
drivers/mmc/core/slot-gpio.c +1 -0
        struct mmc_gpio *ctx = host->slot.handler_priv;
 
        host->trigger_card_event = true;
+       host->init_failed = false;
        mmc_detect_change(host,
 msecs_to_jiffies(ctx->cd_debounce_delay_ms));
 
        return IRQ_HANDLED;
include/linux/mmc/host.h index renamed from include/linux/mmc/host.h +0 -0

2f445c651742..1d75cfdbf981 100644

include/linux/mmc/host.h struct mmc_host { · line 470

Quoted 4 lines
include/linux/mmc/host.h +1 -0
@@ -467,6 +467,7 @@ struct mmc_host {
        struct timer_list       retune_timer;   /* for periodic re-tuning */
 
        bool                    trigger_card_event; /* card_event necessary */
+       bool                    init_failed;    /* check if failed to

initialize */

include/linux/mmc/host.h struct mmc_host { · line 471

Quoted 2 lines
include/linux/mmc/host.h +0 -0
        struct mmc_card         *card;          /* device attached to this host

*/

Quoted 3 lines
include/linux/mmc/host.h +0 -1
--

2.29.0

#4 lore raw
Quoted 34 lines · 이승희
Quoted 18 lines

-----Original Message-----
From: Avri Altman <[email protected]>
Sent: Tuesday, February 13, 2024 5:42 PM
To: Seunghui Lee <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH] mmc: sd: Add a variable to check a faulty device

Quoted 5 lines

In mobile devices, suspend/resume situations are frequent. In the case of a defective SD card in which initialization fails, unnecessary initialization time is consumed for each resume. A field is needed to check that SD card initialization has failed on the host. It could be used to remove unnecessary initialization.

Quoted 8 lines

I don't see where you are using this new init_failed field? Maybe instead, elaborate the logic to free_card: to detect a broken sd. e.g. instead of just if (!oldcard), if (!oldcard || ! mmc_sd_alive(host)) or something.

Thanks,
Avri

Thank you for your suggestion.
I'm going to use it in mmc_rescan as below.

e.g.

drivers/mmc/core/core.c void mmc_rescan(struct work_struct *work) · line 2214

Quoted 6 lines
drivers/mmc/core/core.c +1 -1
@@ -2210,7 +2210,7 @@ void mmc_rescan(struct work_struct *work)
                container_of(work, struct mmc_host, detect.work);
        int i;
 
-       if (host->rescan_disable)
+       if (host->rescan_disable || host->init_failed)
                return;

I've seen SD cards that fail the first initialization attempt for both 'valid' reasons (e.g. weird insertion timing) and things like out-of-spec initialization time from the card, outright disabling these on the first fail is a bit too much IMO.

Kind Regards,
Christian

author
#5 lore raw
Quoted 60 lines

-----Original Message-----
From: Christian Loehle <[email protected]>
Sent: Tuesday, February 13, 2024 10:35 PM
To: 이승희 <[email protected]>; 'Avri Altman' <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] mmc: sd: Add a variable to check a faulty device

Quoted 36 lines · 이승희
Quoted 19 lines

-----Original Message-----
From: Avri Altman <[email protected]>
Sent: Tuesday, February 13, 2024 5:42 PM
To: Seunghui Lee <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH] mmc: sd: Add a variable to check a faulty device

Quoted 5 lines

In mobile devices, suspend/resume situations are frequent. In the case of a defective SD card in which initialization fails, unnecessary initialization time is consumed for each resume. A field is needed to check that SD card initialization has failed on the host. It could be used to remove unnecessary initialization.

Quoted 8 lines

I don't see where you are using this new init_failed field? Maybe instead, elaborate the logic to free_card: to detect a broken sd. e.g. instead of just if (!oldcard), if (!oldcard || ! mmc_sd_alive(host)) or something.

Thanks,
Avri

Thank you for your suggestion.
I'm going to use it in mmc_rescan as below.

e.g.

drivers/mmc/core/core.c index renamed from drivers/mmc/core/core.c +0 -0

a8c17b4cd737..461cd75dc7ab 100644

drivers/mmc/core/core.c void mmc_rescan(struct work_struct *work) · line 2214

Quoted 6 lines
drivers/mmc/core/core.c +1 -1
@@ -2210,7 +2210,7 @@ void mmc_rescan(struct work_struct *work)
                container_of(work, struct mmc_host, detect.work);
        int i;
 
-       if (host->rescan_disable)
+       if (host->rescan_disable || host->init_failed)
                return;

I've seen SD cards that fail the first initialization attempt for both 'valid' reasons (e.g. weird insertion timing) and things like out-of-spec initialization time from the card, outright disabling these on the first fail is a bit too much IMO.

Quoted 2 lines

Kind Regards,
Christian

I agree with you. It's a bit too much.
It's just simple example.

Anyway, It's difficult to distinguish between NO card and a faulty card. That's why I'd like to merge this.
It helps that we check if it's a faulty card or not in a dump.

#6 lore raw
In reply to Seunghui Lee
Quoted 6 lines · Seunghui Lee

In mobile devices, suspend/resume situations are frequent. In the case of a defective SD card in which initialization fails, unnecessary initialization time is consumed for each resume. A field is needed to check that SD card initialization has failed on the host. It could be used to remove unnecessary initialization.

It's not clear to me, under what circumstance you want to optimize for.

Is the SD card ever getting properly initialized during boot?

Kind regards
Uffe

Quoted 79 lines
---
 drivers/mmc/core/sd.c        | 12 +++++++++++-
 drivers/mmc/core/slot-gpio.c |  1 +
 include/linux/mmc/host.h     |  1 +
 3 files changed, 13 insertions(+), 1 deletion(-)
drivers/mmc/core/sd.c +11 -1
index c3e554344c99..f0eb3864dc24 100644
@@ -1410,6 +1410,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
        bool v18_fixup_failed = false;
 
        WARN_ON(!host->claimed);
+       host->init_failed = false;
 retry:
        err = mmc_sd_get_cid(host, ocr, cid, &rocr);
        if (err)
@@ -1752,6 +1753,8 @@ static int _mmc_sd_resume(struct mmc_host *host)
 
        mmc_power_up(host, host->card->ocr);
        err = mmc_sd_init_card(host, host->card->ocr, host->card);
+       if (err)
+               host->init_failed = true;
        mmc_card_clr_suspended(host->card);
 
 out:
@@ -1803,8 +1806,12 @@ static int mmc_sd_runtime_resume(struct mmc_host *host)
 
 static int mmc_sd_hw_reset(struct mmc_host *host)
 {
+       int err;
        mmc_power_cycle(host, host->card->ocr);
-       return mmc_sd_init_card(host, host->card->ocr, host->card);
+       err = mmc_sd_init_card(host, host->card->ocr, host->card);
+       if (err)
+               host->init_failed = true;
+       return err;
 }
 
 static const struct mmc_bus_ops mmc_sd_ops = {
@@ -1891,5 +1898,8 @@ int mmc_attach_sd(struct mmc_host *host)
        pr_err("%s: error %d whilst initialising SD card\n",
                mmc_hostname(host), err);
 
+       if (err)
+               host->init_failed = true;
+
        return err;
 }
drivers/mmc/core/slot-gpio.c +1 -0
index 2a2d949a9344..93d081c7dd53 100644
@@ -33,6 +33,7 @@ static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id)
        struct mmc_gpio *ctx = host->slot.handler_priv;
 
        host->trigger_card_event = true;
+       host->init_failed = false;
        mmc_detect_change(host, msecs_to_jiffies(ctx->cd_debounce_delay_ms));
 
        return IRQ_HANDLED;
include/linux/mmc/host.h +1 -1
index 2f445c651742..1d75cfdbf981 100644
@@ -467,6 +467,7 @@ struct mmc_host {
        struct timer_list       retune_timer;   /* for periodic re-tuning */
 
        bool                    trigger_card_event; /* card_event necessary */
+       bool                    init_failed;    /* check if failed to initialize */
 
        struct mmc_card         *card;          /* device attached to this host */
 
--

2.29.0

author
#7 lore raw
Quoted 19 lines

-----Original Message-----
From: Ulf Hansson <[email protected]>
Sent: Wednesday, February 14, 2024 8:27 PM
To: Seunghui Lee <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] mmc: sd: Add a variable to check a faulty device

Quoted 6 lines · Seunghui Lee

In mobile devices, suspend/resume situations are frequent. In the case of a defective SD card in which initialization fails, unnecessary initialization time is consumed for each resume. A field is needed to check that SD card initialization has failed on the host. It could be used to remove unnecessary initialization.

Quoted 7 lines

It's not clear to me, under what circumstance you want to optimize for.

Is the SD card ever getting properly initialized during boot?

Kind regards
Uffe

We receive a lot of reports about SD card issues in the market.
There was no problem with the first time at the time of use, and there are many cases where people recognize that it is not recognized later on. In most cases, this is a problem with the SD card itself.

SD card users cannot determine whether or not an SD card is a problem, so they should be guided in this regard.
It is necessary to distinguish whether the SD card is inserted but unrecognized or the SD card itself is not inserted, and if there is a field that can check for initialization failure, it will facilitate guidance, so we considered the patch.

The variable's usage is expected to be used through the sysfs node in the vendor module.

Quoted 84 lines

drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host *host,

Quoted 13 lines
---
 drivers/mmc/core/sd.c        | 12 +++++++++++-
 drivers/mmc/core/slot-gpio.c |  1 +
 include/linux/mmc/host.h     |  1 +
 3 files changed, 13 insertions(+), 1 deletion(-)
drivers/mmc/core/sd.c index renamed from drivers/mmc/core/sd.c +0 -0

c3e554344c99..f0eb3864dc24 100644

drivers/mmc/core/sd.c +0 -0
@@ -1410,6 +1410,7 @@ static int mmc_sd_init_card(struct mmc_host *host,

u32 ocr,

drivers/mmc/core/slot-gpio.c static irqreturn_t mmc_gpio_cd_irqt(int irq, void

Quoted 44 lines
drivers/mmc/core/sd.c +8 -1
        bool v18_fixup_failed = false;
 
        WARN_ON(!host->claimed);
+       host->init_failed = false;
 retry:
        err = mmc_sd_get_cid(host, ocr, cid, &rocr);
        if (err)
@@ -1752,6 +1753,8 @@ static int _mmc_sd_resume(struct mmc_host *host)
 
        mmc_power_up(host, host->card->ocr);
        err = mmc_sd_init_card(host, host->card->ocr, host->card);
+       if (err)
+               host->init_failed = true;
        mmc_card_clr_suspended(host->card);
 
 out:
@@ -1803,8 +1806,12 @@ static int mmc_sd_runtime_resume(struct
 mmc_host *host)
 
 static int mmc_sd_hw_reset(struct mmc_host *host)  {
+       int err;
        mmc_power_cycle(host, host->card->ocr);
-       return mmc_sd_init_card(host, host->card->ocr, host->card);
+       err = mmc_sd_init_card(host, host->card->ocr, host->card);
+       if (err)
+               host->init_failed = true;
+       return err;
 }
 
 static const struct mmc_bus_ops mmc_sd_ops = { @@ -1891,5 +1898,8 @@

int mmc_attach_sd(struct mmc_host *host)
pr_err("%s: error %d whilst initialising SD card\n",
mmc_hostname(host), err);

drivers/mmc/core/sd.c +3 -0
+       if (err)
+               host->init_failed = true;
+
        return err;
 }
(quoted diff) +0 -0

b/drivers/mmc/core/slot-gpio.c index 2a2d949a9344..93d081c7dd53 100644

drivers/mmc/core/slot-gpio.c +0 -0
@@ -33,6 +33,7 @@ static irqreturn_t mmc_gpio_cd_irqt(int irq, void

*dev_id)

Quoted 13 lines
drivers/mmc/core/slot-gpio.c +1 -0
        struct mmc_gpio *ctx = host->slot.handler_priv;
 
        host->trigger_card_event = true;
+       host->init_failed = false;
        mmc_detect_change(host,
 msecs_to_jiffies(ctx->cd_debounce_delay_ms));
 
        return IRQ_HANDLED;
include/linux/mmc/host.h index renamed from include/linux/mmc/host.h +0 -0

2f445c651742..1d75cfdbf981 100644

include/linux/mmc/host.h struct mmc_host { · line 470

Quoted 4 lines
include/linux/mmc/host.h +1 -0
@@ -467,6 +467,7 @@ struct mmc_host {
        struct timer_list       retune_timer;   /* for periodic re-tuning */
 
        bool                    trigger_card_event; /* card_event necessary */
+       bool                    init_failed;    /* check if failed to

initialize */

include/linux/mmc/host.h struct mmc_host { · line 471

Quoted 2 lines
include/linux/mmc/host.h +0 -0
        struct mmc_card         *card;          /* device attached to this host

*/

Quoted 4 lines
include/linux/mmc/host.h +0 -1
--

2.29.0

#8 lore raw
Quoted 26 lines · 이승희
Quoted 19 lines

-----Original Message-----
From: Ulf Hansson <[email protected]>
Sent: Wednesday, February 14, 2024 8:27 PM
To: Seunghui Lee <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] mmc: sd: Add a variable to check a faulty device

Quoted 6 lines · Seunghui Lee

In mobile devices, suspend/resume situations are frequent. In the case of a defective SD card in which initialization fails, unnecessary initialization time is consumed for each resume. A field is needed to check that SD card initialization has failed on the host. It could be used to remove unnecessary initialization.

Quoted 7 lines

It's not clear to me, under what circumstance you want to optimize for.

Is the SD card ever getting properly initialized during boot?

Kind regards
Uffe

Quoted 7 lines

We receive a lot of reports about SD card issues in the market.
There was no problem with the first time at the time of use, and there are many cases where people recognize that it is not recognized later on. In most cases, this is a problem with the SD card itself.

SD card users cannot determine whether or not an SD card is a problem, so they should be guided in this regard.
It is necessary to distinguish whether the SD card is inserted but unrecognized or the SD card itself is not inserted, and if there is a field that can check for initialization failure, it will facilitate guidance, so we considered the patch.

The variable's usage is expected to be used through the sysfs node in the vendor module.

What "vendor module"? You need to include all of the needed code here please.

thanks,

greg k-h

author
#9 lore raw
Quoted 54 lines

-----Original Message-----
From: Greg KH <[email protected]>
Sent: Thursday, February 15, 2024 5:07 PM
To: 이승희 <[email protected]>
Cc: 'Ulf Hansson' <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] mmc: sd: Add a variable to check a faulty device

Quoted 14 lines · 이승희
Quoted 14 lines

-----Original Message-----
From: Ulf Hansson <[email protected]>
Sent: Wednesday, February 14, 2024 8:27 PM
To: Seunghui Lee <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] mmc: sd: Add a variable to check a faulty device

On Tue, 13 Feb 2024 at 06:13, Seunghui Lee <[email protected]>

Quoted 9 lines · wrote:
Quoted 9 lines
Quoted 6 lines

In mobile devices, suspend/resume situations are frequent. In the case of a defective SD card in which initialization fails, unnecessary initialization time is consumed for each resume. A field is needed to check that SD card initialization has failed on the host. It could be used to remove unnecessary initialization.

It's not clear to me, under what circumstance you want to optimize for.

Quoted 7 lines
Quoted 5 lines

Is the SD card ever getting properly initialized during boot?

Kind regards
Uffe

We receive a lot of reports about SD card issues in the market. There was no problem with the first time at the time of use, and there

are many cases where people recognize that it is not recognized later on. In most cases, this is a problem with the SD card itself.

Quoted 2 lines

SD card users cannot determine whether or not an SD card is a problem,

so they should be guided in this regard.

Quoted 1 line

It is necessary to distinguish whether the SD card is inserted but

unrecognized or the SD card itself is not inserted, and if there is a field that can check for initialization failure, it will facilitate guidance, so we considered the patch.

Quoted 2 lines

The variable's usage is expected to be used through the sysfs node in

Quoted 8 lines

the vendor module.

What "vendor module"? You need to include all of the needed code here please.

thanks,

greg k-h

This only purpose of this variable is to identify a faulty card on host side.

In the past, we can identify that the card is inserted or not with reading get_cd() function. But now, most mobile devices use hybrid type of SD card tray.
If the tray is inserted, the return value of get_cd is the same whatever the SD card is inserted or not. It can help us diagonose the status of a SD card as well.

Here is the example of usage.

static ssize_t status_show(struct device *dev,
struct device_attribute *attr, char *buf)

{
        struct mmc_host *host = dev_get_drvdata(dev);
        struct mmc_card *card = host->card;
        char *status = NULL;

        if (card)
                status = mmc_card_readonly(card) ? "PERMWP" : "NORMAL";
        else
                status = host->init_failed ? "INITFAIL" : "NOCARD";

        return sysfs_emit(buf, "%s\n", status);
}

As for the sysfs node, it should keep the path of node with or without the SD card. That's why I mention the vendor module.

If I need to update the commit's comment, I'll fix it.
If someone has the better idea(e.g. code, comment), please suggest it.

Thank you for reviewing this.
Seunghui Lee.

#10 lore raw
Quoted 10 lines · 이승희
Quoted 10 lines

-----Original Message-----
From: Greg KH <[email protected]>
Sent: Thursday, February 15, 2024 5:07 PM
To: 이승희 <[email protected]>
Cc: 'Ulf Hansson' <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] mmc: sd: Add a variable to check a faulty device

Does this really belong in the body of the email? You might want a nicer email client :)

Quoted 21 lines
Quoted 9 lines
Quoted 1 line

The variable's usage is expected to be used through the sysfs node in

the vendor module.

What "vendor module"? You need to include all of the needed code here please.

thanks,

greg k-h

This only purpose of this variable is to identify a faulty card on host side.

In the past, we can identify that the card is inserted or not with reading get_cd() function. But now, most mobile devices use hybrid type of SD card tray.
If the tray is inserted, the return value of get_cd is the same whatever the SD card is inserted or not. It can help us diagonose the status of a SD card as well.

Here is the example of usage.

static ssize_t status_show(struct device *dev,
struct device_attribute *attr, char *buf)

Quoted 12 lines
{
        struct mmc_host *host = dev_get_drvdata(dev);
        struct mmc_card *card = host->card;
        char *status = NULL;

        if (card)
                status = mmc_card_readonly(card) ? "PERMWP" : "NORMAL";
        else
                status = host->init_failed ? "INITFAIL" : "NOCARD";

        return sysfs_emit(buf, "%s\n", status);
}

What will userspace do with this information?

And why isn't this part of the patch you submitted?

Quoted 2 lines

As for the sysfs node, it should keep the path of node with or without the SD card. That's why I mention the vendor module.

What vendor module? What do you mean by vendor module? You know we can't add code to the kernel that is only used by code that is NOT in our kernel tree. You don't want us to take stuff like that, so why is it being proposed here?

confused,

greg k-h

author
#11 lore raw
Quoted 8 lines

-----Original Message-----

Quoted 2 lines · 이승희
Quoted 2 lines

Subject: Re: [PATCH] mmc: sd: Add a variable to check a faulty device

Does this really belong in the body of the email? You might want a nicer email client :)

It was caused by unfamiliarity with upstream. Sorry for the inconvenience.

Quoted 44 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

The variable's usage is expected to be used through the sysfs node in

the vendor module.

Quoted 8 lines
Quoted 6 lines

What "vendor module"? You need to include all of the needed code here please.

thanks,

greg k-h

This only purpose of this variable is to identify a faulty card on host

side.

Quoted 2 lines

In the past, we can identify that the card is inserted or not with

reading get_cd() function.

Quoted 2 lines

But now, most mobile devices use hybrid type of SD card tray. If the tray is inserted, the return value of get_cd is the same whatever

the SD card is inserted or not.

Quoted 5 lines

It can help us diagonose the status of a SD card as well.

Here is the example of usage.

static ssize_t status_show(struct device *dev,

Quoted 11 lines
                struct device_attribute *attr, char *buf) {
        struct mmc_host *host = dev_get_drvdata(dev);
        struct mmc_card *card = host->card;
        char *status = NULL;

        if (card)
                status = mmc_card_readonly(card) ? "PERMWP" : "NORMAL";
        else
                status = host->init_failed ? "INITFAIL" : "NOCARD";

        return sysfs_emit(buf, "%s\n", status); }

What will userspace do with this information?

And why isn't this part of the patch you submitted?

Quoted 1 line

As for the sysfs node, it should keep the path of node with or without

the SD card.

Quoted 1 line

That's why I mention the vendor module.

Quoted 8 lines

What vendor module? What do you mean by vendor module? You know we can't add code to the kernel that is only used by code that is NOT in our kernel tree. You don't want us to take stuff like that, so why is it being proposed here?

confused,

greg k-h

We need to inform users that there is a problem with the SD card.
There is a diagnostic tool in the customer service app,
Adding a sysfs node is under consideration so that the tool can diagnose the SD card.
To do this, a node capable of diagnosing an SD card is needed regardless of whether an SD card is present or not.

Since I understand that the proposed sysfs node is difficult to apply to the kernel, no separate commit was posted. So, I created this PR because I needed a variable to identify the faulty device.

I will consider this part again.
And if you have any other good ideas, please feel free to suggest them.

Thank you for your review.
Seunghui Lee.

#12 lore raw
In reply to 이승희
Quoted 22 lines · 이승희
Quoted 22 lines

-----Original Message-----
From: Ulf Hansson <[email protected]>
Sent: Wednesday, February 14, 2024 8:27 PM
To: Seunghui Lee <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] mmc: sd: Add a variable to check a faulty device

Quoted 6 lines · Seunghui Lee

In mobile devices, suspend/resume situations are frequent. In the case of a defective SD card in which initialization fails, unnecessary initialization time is consumed for each resume. A field is needed to check that SD card initialization has failed on the host. It could be used to remove unnecessary initialization.

It's not clear to me, under what circumstance you want to optimize for.

Quoted 7 lines
Quoted 5 lines

Is the SD card ever getting properly initialized during boot?

Kind regards
Uffe

We receive a lot of reports about SD card issues in the market.
There was no problem with the first time at the time of use, and there are many cases where people recognize that it is not recognized later on. In most cases, this is a problem with the SD card itself.

Right. Thanks for clarifying.

A follow up question from me is then, do you know more exactly *why* the SD cards encounter problems?

In the past people have told me that powering on/off an SD card during system suspend/resume, too frequently, could damage the card. For non-removable cards, the card stays powered-off even after a system resume, but instead gets powered-on (and re-initialized) when there is a new request for it.

In other words, if the problem is related to too frequent powering on/off the card, my advice would be to test with having the card set non-removable (the DT property for this is "non-removable"), to see if that can help. If that solves the problem, we can work towards another common solution instead.

Quoted 5 lines

SD card users cannot determine whether or not an SD card is a problem, so they should be guided in this regard.
It is necessary to distinguish whether the SD card is inserted but unrecognized or the SD card itself is not inserted, and if there is a field that can check for initialization failure, it will facilitate guidance, so we considered the patch.

The variable's usage is expected to be used through the sysfs node in the vendor module.

As Greg said, please provide the complete code.

Although, I want to stress already at this point, I don't see a solution with sysfs being the correct thing to do here. The kernel should be able to manage this problem itself.

[...]

Kind regards
Uffe

author
#13 lore raw
Quoted 33 lines

-----Original Message-----

Quoted 1 line
Quoted 1 line

On Tue, 13 Feb 2024 at 06:13, Seunghui Lee <[email protected]>

Quoted 9 lines · wrote:
Quoted 9 lines
Quoted 6 lines

In mobile devices, suspend/resume situations are frequent. In the case of a defective SD card in which initialization fails, unnecessary initialization time is consumed for each resume. A field is needed to check that SD card initialization has failed on the host. It could be used to remove unnecessary initialization.

It's not clear to me, under what circumstance you want to optimize for.

Quoted 7 lines
Quoted 5 lines

Is the SD card ever getting properly initialized during boot?

Kind regards
Uffe

We receive a lot of reports about SD card issues in the market. There was no problem with the first time at the time of use, and there

are many cases where people recognize that it is not recognized later on. In most cases, this is a problem with the SD card itself.

Right. Thanks for clarifying.

A follow up question from me is then, do you know more exactly *why* the SD cards encounter problems?

In the past people have told me that powering on/off an SD card during system suspend/resume, too frequently, could damage the card. For non- removable cards, the card stays powered-off even after a system resume, but instead gets powered-on (and re-initialized) when there is a new request for it.

Quoted 6 lines

In other words, if the problem is related to too frequent powering on/off the card, my advice would be to test with having the card set non- removable (the DT property for this is "non-removable"), to see if that can help. If that solves the problem, we can work towards another common solution instead.

I understand your focus on finding the root cause of the problem.
However, unlike internal storage, there is a limit to analyzing cards that have problems in the market. This is because there are many different SD card manufacturers and many manufacturers leave it to OEMs.

For deferred resume, a responsiveness problem occurs on the user side on mobile devices. The response time of the initializing SD card initialization in the application seems to be slow. Currently, it seems to be a good structure for the first initialization at runtime resume.

Regarding non-removable,
We will test if we are given an opportunity to further analyze the cards occurring in the market.
However, SD card detection is also used as a wakeup source and must be inserted/removed so I'll consider it for testing purposes.

Thank you for the good suggestions though.

Quoted 13 lines
Quoted 2 lines

SD card users cannot determine whether or not an SD card is a problem,

so they should be guided in this regard.

Quoted 1 line

It is necessary to distinguish whether the SD card is inserted but

unrecognized or the SD card itself is not inserted, and if there is a field that can check for initialization failure, it will facilitate guidance, so we considered the patch.

Quoted 2 lines

The variable's usage is expected to be used through the sysfs node in

the vendor module.

As Greg said, please provide the complete code.

Quoted 8 lines

Although, I want to stress already at this point, I don't see a solution with sysfs being the correct thing to do here. The kernel should be able to manage this problem itself.

[...]

Kind regards
Uffe

I understand it and reconsider this commit.
Thank you for reviewing this.

Seunghui Lee.

#14 lore raw
Quoted 41 lines · 이승희
Quoted 34 lines

-----Original Message-----

Quoted 1 line
Quoted 1 line

On Tue, 13 Feb 2024 at 06:13, Seunghui Lee <[email protected]>

Quoted 9 lines · wrote:
Quoted 9 lines
Quoted 6 lines

In mobile devices, suspend/resume situations are frequent. In the case of a defective SD card in which initialization fails, unnecessary initialization time is consumed for each resume. A field is needed to check that SD card initialization has failed on the host. It could be used to remove unnecessary initialization.

It's not clear to me, under what circumstance you want to optimize for.

Quoted 7 lines
Quoted 5 lines

Is the SD card ever getting properly initialized during boot?

Kind regards
Uffe

We receive a lot of reports about SD card issues in the market. There was no problem with the first time at the time of use, and there

are many cases where people recognize that it is not recognized later on. In most cases, this is a problem with the SD card itself.

Right. Thanks for clarifying.

A follow up question from me is then, do you know more exactly *why* the SD cards encounter problems?

In the past people have told me that powering on/off an SD card during system suspend/resume, too frequently, could damage the card. For non- removable cards, the card stays powered-off even after a system resume, but instead gets powered-on (and re-initialized) when there is a new request for it.

Quoted 6 lines

In other words, if the problem is related to too frequent powering on/off the card, my advice would be to test with having the card set non- removable (the DT property for this is "non-removable"), to see if that can help. If that solves the problem, we can work towards another common solution instead.

Quoted 3 lines

I understand your focus on finding the root cause of the problem.
However, unlike internal storage, there is a limit to analyzing cards that have problems in the market. This is because there are many different SD card manufacturers and many manufacturers leave it to OEMs.

I understand that this isn't an easy task, but for sure it should be doable. There are plenty of less robust SD cards out there, let's just try to find one and see if we can break it. :-)

Quoted 4 lines

For deferred resume, a responsiveness problem occurs on the user side on mobile devices. The response time of the initializing SD card initialization in the application seems to be slow. Currently, it seems to be a good structure for the first initialization at runtime resume.

You are correct - an initial latency for the *first* I/O request will be added. On the other hand, if the SD card remains unused after a system resume, there should be some energy to save, as the card would then remain powered-off.

Moreover, if we also can avoid breaking the SD card, I'm sure it would be worth it.

Quoted 4 lines

Regarding non-removable,
We will test if we are given an opportunity to further analyze the cards occurring in the market.
However, SD card detection is also used as a wakeup source and must be inserted/removed so I'll consider it for testing purposes.

Yes, I understand that part. A proper solution needs to take care of removable cards, of course. The suggestion to set the slot as non-removable, was just to try to understand if that would solve the problem of breaking SD cards.

If the card-detect irq, can be configured as a wakeup source, I think we should be able to distinguish - if we need to do a power-on (re-init) of the SD card during system resume or if we can avoid it.

I try to get some time to put together a patch for this, no promises for when, but I will keep you posted.

[...]

Kind regards
Uffe