mmc: core: sd: check card write-protect lock while resuming
PATCH 1/1 mmc: core: sd: check card write-protect lock while resuming
From: Minda Chen <[email protected]>
After suspending, unplug the sdcard, and set sd WP lock, insert it again, then resume the system. resume codes do not check the the sdcard write-proctect lock. now check it.
--- drivers/mmc/core/sd.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/mmc/core/sd.c +7 -0
@@ -910,6 +910,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,int err;u32 cid[4 ];u32 rocr =0 ; +bool oldro, ro;BUG_ON (!host);WARN_ON (!host->claimed);
@@ -922,6 +923,12 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,if (memcmp (cid, oldcard->raw_cid,sizeof (cid)) !=0 )return -ENOENT ; +if (host->ops->get_ro) { + ro = host->ops->get_ro (host) ? true : false; + oldro =mmc_card_readonly (oldcard) ? true : false; +if (oldro ^ ro) +return -ENOENT ; + } card = oldcard; }else {/*
Signature · 7 lines
2.0.4 Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom More information can be found at www.csr.com. Keep up to date with CSR on our technical blog, www.csr.com/blog, CSR people blog, www.csr.com/people, YouTube, www.youtube.com/user/CSRplc, Facebook, www.facebook.com/pages/CSR/191038434253534, or follow us on Twitter at www.twitter.com/CSR_plc. New for 2014, you can now access the wide range of products powered by aptX at www.aptx.com.
PATCH 1/1 mmc: core: sd: check card write-protect lock while resuming
Quoted 26 lines · Barry Song
From: Minda Chen <[email protected]>
After suspending, unplug the sdcard, and set sd WP lock, insert it again, then resume the system. resume codes do not check the the sdcard write-proctect lock. now check it.
Signed-off-by Minda Chen <[email protected]>Signed-off-by Barry Song <[email protected]>--- drivers/mmc/core/sd.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/mmc/core/sd.c +1
-0@@ -910,6 +910,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,int err;u32 cid[4 ];u32 rocr =0 ; +bool oldro, ro;BUG_ON (!host);WARN_ON (!host->claimed);
drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, · line 931
Quoted 9 lines
drivers/mmc/core/sd.c +6
-0@@ -922,6 +923,12 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,if (memcmp (cid, oldcard->raw_cid,sizeof (cid)) !=0 )return -ENOENT ; +if (host->ops->get_ro) { + ro = host->ops->get_ro (host) ? true : false; + oldro =mmc_card_readonly (oldcard) ? true : false; +if (oldro ^ ro) +return -ENOENT ; + }
Seems like this code belongs better in mmc_sd_setup_card(). Could you try moving it there.
Kind regards
Uffe
Quoted 11 lines
drivers/mmc/core/sd.c +0
-1card = oldcard; }else {/* -- 2.0.4
Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Keep up to date with CSR on our technical blog, www.csr.com/blog, CSR people blog, www.csr.com/people, YouTube, www.youtube.com/user/CSRplc, Facebook, www.facebook.com/pages/CSR/191038434253534, or follow us on Twitter at www.twitter.com/CSR_plc. New for 2014, you can now access the wide range of products powered by aptX at www.aptx.com.
PATCH 1/1 mmc: core: sd: check card write-protect lock while resuming
Quoted 47 lines
-----Original Message-----
From: Ulf Hansson [mailto:ulf.hansson at linaro.org]
Sent: Monday, August 18, 2014 7:58 PM
To: Barry Song
Cc: Chris Ball; linux-mmc; linux-arm-kernel at lists.infradead.org; DL-SHA- WorkGroupLinux; Minda Chen; Barry Song
Subject: Re: [PATCH] mmc: core: sd: check card write-protect lock while resumingdrivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host
Quoted 17 lines · Barry Song
From: Minda Chen <[email protected]>
After suspending, unplug the sdcard, and set sd WP lock, insert it again, then resume the system. resume codes do not check the the sdcard write-proctect lock. now check it.
Signed-off-by Minda Chen <[email protected]>Signed-off-by Barry Song <[email protected]>--- drivers/mmc/core/sd.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/mmc/core/sd.c index renamed from drivers/mmc/core/sd.c +0
-00c44510..890557a 100644
drivers/mmc/core/sd.c +0
-0@@ -910,6 +910,7 @@ static int mmc_sd_init_card(struct mmc_host*host, u32 ocr,
drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host
Quoted 8 lines
drivers/mmc/core/sd.c +1
-0int err;u32 cid[4 ];u32 rocr =0 ; +bool oldro, ro;BUG_ON (!host);WARN_ON (!host->claimed);@@ -922,6 +923,12 @@ static int mmc_sd_init_card(struct mmc_host*host, u32 ocr,
drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host · line 931
Quoted 9 lines
drivers/mmc/core/sd.c +6
-0if (memcmp (cid, oldcard->raw_cid,sizeof (cid)) !=0 )return -ENOENT ; +if (host->ops->get_ro) { + ro = host->ops->get_ro (host) ? true : false; + oldro =mmc_card_readonly (oldcard) ? true : false; +if (oldro ^ ro) +return -ENOENT ; + }
Quoted 2 lines
Seems like this code belongs better in
mmc_sd_setup_card(). Could you try moving it there.
[Barry Song]
Well. How about:
drivers/mmc/core/sd.c +21 -15
@@ -815,6 +815,7 @@ int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card, bool reinit) {int err; +int oldro, ro =-1 ;if (!reinit) {/*
@@ -861,23 +862,28 @@ int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card,/* * Check if read-only switch is active. */ -if (!reinit) { -int ro =-1 ; -if (host->ops->get_ro) { -mmc_host_clk_hold (card->host); - ro = host->ops->get_ro (host); -mmc_host_clk_release (card->host); - } +if (host->ops->get_ro) { +mmc_host_clk_hold (card->host); + ro = host->ops->get_ro (host); +mmc_host_clk_release (card->host); + } -if (ro <0 ) { -pr_warning ("%s: host does not " -"support reading read-only " -"switch. assuming write-enable.\n" , -mmc_hostname (host)); - }else if (ro >0 ) { -mmc_card_set_readonly (card); - } +if (ro <0 ) +pr_warning ("%s: host does not " +"support reading read-only " +"switch. assuming write-enable.\n" , +mmc_hostname (host)); + +if (!reinit && (ro >0 )) +mmc_card_set_readonly (card); +else if (reinit && (ro >=0 )) { +/* check if the write-protection lock is changed */ + oldro =mmc_card_readonly (card) ?1 :0 ; + ro = (ro >0 ) ?1 :0 ; + +if (oldro ^ ro) +return -ENOENT ; }return 0 ;
Quoted 7 lines
Kind regards
UffeQuoted 3 lines
drivers/mmc/core/sd.c +0
-0card = oldcard; }else {/*
-barry
Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Keep up to date with CSR on our technical blog, www.csr.com/blog, CSR people blog, www.csr.com/people, YouTube, www.youtube.com/user/CSRplc, Facebook, www.facebook.com/pages/CSR/191038434253534, or follow us on Twitter at www.twitter.com/CSR_plc. New for 2014, you can now access the wide range of products powered by aptX at www.aptx.com.
PATCH 1/1 mmc: core: sd: check card write-protect lock while resuming
Quoted 85 lines · Barry Song
Quoted 47 lines
-----Original Message-----
From: Ulf Hansson [mailto:ulf.hansson at linaro.org]
Sent: Monday, August 18, 2014 7:58 PM
To: Barry Song
Cc: Chris Ball; linux-mmc; linux-arm-kernel at lists.infradead.org; DL-SHA- WorkGroupLinux; Minda Chen; Barry Song
Subject: Re: [PATCH] mmc: core: sd: check card write-protect lock while resumingdrivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host
Quoted 17 lines · Barry Song
From: Minda Chen <[email protected]>
After suspending, unplug the sdcard, and set sd WP lock, insert it again, then resume the system. resume codes do not check the the sdcard write-proctect lock. now check it.
Signed-off-by Minda Chen <[email protected]>Signed-off-by Barry Song <[email protected]>--- drivers/mmc/core/sd.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/mmc/core/sd.c index renamed from drivers/mmc/core/sd.c +0
-00c44510..890557a 100644
drivers/mmc/core/sd.c +0
-0@@ -910,6 +910,7 @@ static int mmc_sd_init_card(struct mmc_host*host, u32 ocr,
drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host
Quoted 8 lines
drivers/mmc/core/sd.c +1
-0int err;u32 cid[4 ];u32 rocr =0 ; +bool oldro, ro;BUG_ON (!host);WARN_ON (!host->claimed);@@ -922,6 +923,12 @@ static int mmc_sd_init_card(struct mmc_host*host, u32 ocr,
drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host · line 931
Quoted 9 lines
drivers/mmc/core/sd.c +6
-0if (memcmp (cid, oldcard->raw_cid,sizeof (cid)) !=0 )return -ENOENT ; +if (host->ops->get_ro) { + ro = host->ops->get_ro (host) ? true : false; + oldro =mmc_card_readonly (oldcard) ? true : false; +if (oldro ^ ro) +return -ENOENT ; + }Quoted 2 lines
Seems like this code belongs better in
mmc_sd_setup_card(). Could you try moving it there.[Barry Song]
Well. How about:drivers/mmc/core/sd.c +6
-10@@ -815,6 +815,7 @@ int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card, bool reinit) {int err; +int oldro, ro =-1 ;if (!reinit) {/* @@ -861,23 +862,28 @@ int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card,/* * Check if read-only switch is active. */ -if (!reinit) { -int ro =-1 ; -if (host->ops->get_ro) { -mmc_host_clk_hold (card->host); - ro = host->ops->get_ro (host); -mmc_host_clk_release (card->host); - } +if (host->ops->get_ro) { +mmc_host_clk_hold (card->host); + ro = host->ops->get_ro (host); +mmc_host_clk_release (card->host); + } -if (ro <0 ) { -pr_warning ("%s: host does not " - "support reading read-only "
drivers/mmc/core/sd.c int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card, · line 876
Quoted 10 lines
drivers/mmc/core/sd.c +5
-5-"switch. assuming write-enable.\n" , - mmc_hostname(host)); - }else if (ro >0 ) { -mmc_card_set_readonly (card); - } +if (ro <0 ) +pr_warning ("%s: host does not " +"support reading read-only " +"switch. assuming write-enable.\n" , +mmc_hostname (host));
I don't wont this pr_warning to spam the log each resume. I suppose we could print it only for !reinit, right?
drivers/mmc/core/sd.c int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card, · line 886
Quoted 10 lines
drivers/mmc/core/sd.c +10
-0+ +if (!reinit && (ro >0 )) +mmc_card_set_readonly (card); +else if (reinit && (ro >=0 )) { +/* check if the write-protection lock is changed */ + oldro =mmc_card_readonly (card) ?1 :0 ; + ro = (ro >0 ) ?1 :0 ; + +if (oldro ^ ro) +return -ENOENT ;
This will have the effect of quickly returning an error to the mmc bus' ->suspend callback. That path are not able remove the card device, which I guess is what you would like to happen, right?
I am not completely sure, but I believe the card will still be operational after resuming. Moreover it will be using the initialization frequency and 1-bit bus width and thus performing poorly. This is definitely not what we want.
How did you test this patch? Can you confirm my theory above?
The card may only be removed from the mmc_rescan work, scheduled at PM_POST_SUSPEND phase. What I think you should do here, is to also set the card state into MMC_CARD_REMOVED, by invoking mmc_card_set_removed(). Thus the SD's bus_ops->detect callback will remove the card during this phase.
Kind regards
Uffe
A message that is not in the archive (sent off-list or not yet received): 7960C73727803F45B9F4D2B2441DA8AC0CE80220@SHAASIEXM01.ASIA.ROOT.PRI
2014-08-26 13:01 GMT+08:00 Minda Chen <[email protected]>:
Quoted 92 lines
-----Original Message-----
From: Ulf Hansson [mailto:[email protected]]
Sent: Friday, August 22, 2014 6:00 PM
To: Barry Song
Cc: Chris Ball; linux-mmc; [email protected]; Minda Chen; DL-SHA-WorkGroupLinux
Subject: Re: [PATCH] mmc: core: sd: check card write-protect lock while resumingQuoted 82 lines · Barry Song
Quoted 47 lines
-----Original Message-----
From: Ulf Hansson [mailto:[email protected]]
Sent: Monday, August 18, 2014 7:58 PM
To: Barry Song
Cc: Chris Ball; linux-mmc; [email protected]; DL-SHA- WorkGroupLinux; Minda Chen; Barry Song
Subject: Re: [PATCH] mmc: core: sd: check card write-protect lock while resumingdrivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host
Quoted 17 lines · Barry Song
From: Minda Chen <[email protected]>
After suspending, unplug the sdcard, and set sd WP lock, insert it again, then resume the system. resume codes do not check the the sdcard write-proctect lock. now check it.
Signed-off-by Minda Chen <[email protected]>Signed-off-by Barry Song <[email protected]>--- drivers/mmc/core/sd.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/mmc/core/sd.c index renamed from drivers/mmc/core/sd.c +0
-00c44510..890557a 100644
drivers/mmc/core/sd.c +0
-0@@ -910,6 +910,7 @@ static int mmc_sd_init_card(struct mmc_host*host, u32 ocr,
drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host
Quoted 8 lines
drivers/mmc/core/sd.c +1
-0int err;u32 cid[4 ];u32 rocr =0 ; +bool oldro, ro;BUG_ON (!host);WARN_ON (!host->claimed);@@ -922,6 +923,12 @@ static int mmc_sd_init_card(struct mmc_host*host, u32 ocr,
drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host · line 931
Quoted 9 lines
drivers/mmc/core/sd.c +6
-0if (memcmp (cid, oldcard->raw_cid,sizeof (cid)) !=0 )return -ENOENT ; +if (host->ops->get_ro) { + ro = host->ops->get_ro (host) ? true : false; + oldro =mmc_card_readonly (oldcard) ? true : false; +if (oldro ^ ro) +return -ENOENT ; + }Quoted 2 lines
Seems like this code belongs better in
mmc_sd_setup_card(). Could you try moving it there.[Barry Song]
Well. How about:drivers/mmc/core/sd.c index renamed from drivers/mmc/core/sd.c +0
-00c44510..643bc82d8 100644
drivers/mmc/core/sd.c +6
-7@@ -815,6 +815,7 @@ int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card, bool reinit) {int err; +int oldro, ro =-1 ;if (!reinit) {/* @@ -861,23 +862,28 @@ int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card,/* * Check if read-only switch is active. */ -if (!reinit) { -int ro =-1 ; -if (host->ops->get_ro) { -mmc_host_clk_hold (card->host); - ro = host->ops->get_ro (host); -mmc_host_clk_release (card->host); - } +if (host->ops->get_ro) { +mmc_host_clk_hold (card->host); + ro = host->ops->get_ro (host); +mmc_host_clk_release (card->host); + }
Quoted 17 lines
drivers/mmc/core/sd.c int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card, · line 876
Quoted 13 lines
drivers/mmc/core/sd.c +5
-8-if (ro <0 ) { -pr_warning ("%s: host does not " -"support reading read-only " -"switch. assuming write-enable.\n" , -mmc_hostname (host)); - }else if (ro >0 ) { -mmc_card_set_readonly (card); - } +if (ro <0 ) +pr_warning ("%s: host does not " +"support reading read-only " +"switch. assuming write-enable.\n" , +mmc_hostname (host));I don't wont this
pr_warningto spam the log each resume. I suppose we could print it only for !reinit, right?
ok
Quoted 13 lines
drivers/mmc/core/sd.c int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card, · line 886
Quoted 10 lines
drivers/mmc/core/sd.c +10
-0+ +if (!reinit && (ro >0 )) +mmc_card_set_readonly (card); +else if (reinit && (ro >=0 )) { +/* check if the write-protection lock is changed */ + oldro =mmc_card_readonly (card) ?1 :0 ; + ro = (ro >0 ) ?1 :0 ; + +if (oldro ^ ro) +return -ENOENT ;This will have the effect of quickly returning an error to the mmc bus' ->suspend callback. That path are not able remove the card device, which I guess is what you would like to happen, right?
Quoted 3 lines
I am not completely sure, but I believe the card will still be operational after resuming. Moreover it will be using the initialization frequency and 1-bit bus width and thus performing poorly. This is definitely not what we want.
How did you test this patch? Can you confirm my theory above?
Sorry, I didn't check it carefully.
Quoted 6 lines
The card may only be removed from the
mmc_rescanwork, scheduled atPM_POST_SUSPENDphase. What I think you should do here, is to also set the card state intoMMC_CARD_REMOVED, by invokingmmc_card_set_removed(). Thus the SD'sbus_ops->detectcallback will remove the card during this phase.Kind regards
Uffe
Quoted 6 lines
To report this email as spam click https://www.mailcontrol.com/sr/MZbqvYs5QwJvpeaetUwhCQ== .
Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Keep up to date with CSR on our technical blog, www.csr.com/blog, CSR people blog, www.csr.com/people, YouTube, www.youtube.com/user/CSRplc, Facebook, www.facebook.com/pages/CSR/191038434253534, or follow us on Twitter at www.twitter.com/CSR_plc. New for 2014, you can now access the wide range of products powered by aptX at www.aptx.com.
I have a suggestion.
Compared with first patch ,mmc_sd_setup_card function select card command (cmd7) is executed. So In mmc_rescan function the card can not be removed. How about reset the card in this case?
drivers/mmc/core/sd.c +0 -0
@@ -815,6 +815,7 @@ int mmc_sd_setup_card(struct mmc_host *host,
struct mmc_card *card,
bool reinit)
{
int err;+ int oldro, ro = -1;
if (!reinit) {
/*
@@ -858,18 +859,16 @@ int mmc_sd_setup_card(struct mmc_host *host,
struct mmc_card *card,
return err;
}+ if (host->ops->get_ro) {
+ mmc_host_clk_hold(card->host);
+ ro = host->ops->get_ro(host);
+ mmc_host_clk_release(card->host);
+ }
+
/*
* Check if read-only switch is active.
*/
if (!reinit) {
- int ro = -1;
-
- if (host->ops->get_ro) {
- mmc_host_clk_hold(card->host);
- ro = host->ops->get_ro(host);
- mmc_host_clk_release(card->host);- }
-
if (ro < 0) {
pr_warning("%s: host does not "
"support reading read-only "
@@ -878,6 +877,15 @@ int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card,
} else if (ro > 0) {
mmc_card_set_readonly(card);
}
+ } else if (reinit && (ro >= 0)) {
+ /* check if the write-protection lock is changed */
+ oldro = mmc_card_readonly(card) ? 1 : 0;
+ ro = (ro > 0) ? 1 : 0;+
+ if (oldro ^ ro) {
+ mmc_go_idle(host);
+ return -ENOENT;
+ }
}
return 0;Quoted 142 lines · minda chen
2014-08-26 13:01 GMT+08:00 Minda Chen <[email protected]>:
Quoted 92 lines
-----Original Message-----
From: Ulf Hansson [mailto:[email protected]]
Sent: Friday, August 22, 2014 6:00 PM
To: Barry Song
Cc: Chris Ball; linux-mmc; [email protected]; Minda Chen; DL-SHA-WorkGroupLinux
Subject: Re: [PATCH] mmc: core: sd: check card write-protect lock while resumingQuoted 82 lines · Barry Song
Quoted 47 lines
-----Original Message-----
From: Ulf Hansson [mailto:[email protected]]
Sent: Monday, August 18, 2014 7:58 PM
To: Barry Song
Cc: Chris Ball; linux-mmc; [email protected]; DL-SHA- WorkGroupLinux; Minda Chen; Barry Song
Subject: Re: [PATCH] mmc: core: sd: check card write-protect lock while resumingdrivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host
Quoted 17 lines · Barry Song
From: Minda Chen <[email protected]>
After suspending, unplug the sdcard, and set sd WP lock, insert it again, then resume the system. resume codes do not check the the sdcard write-proctect lock. now check it.
Signed-off-by Minda Chen <[email protected]>Signed-off-by Barry Song <[email protected]>--- drivers/mmc/core/sd.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/mmc/core/sd.c index renamed from drivers/mmc/core/sd.c +0
-00c44510..890557a 100644
drivers/mmc/core/sd.c +0
-0@@ -910,6 +910,7 @@ static int mmc_sd_init_card(struct mmc_host*host, u32 ocr,
drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host
Quoted 8 lines
drivers/mmc/core/sd.c +1
-0int err;u32 cid[4 ];u32 rocr =0 ; +bool oldro, ro;BUG_ON (!host);WARN_ON (!host->claimed);@@ -922,6 +923,12 @@ static int mmc_sd_init_card(struct mmc_host*host, u32 ocr,
drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host · line 931
Quoted 9 lines
drivers/mmc/core/sd.c +6
-0if (memcmp (cid, oldcard->raw_cid,sizeof (cid)) !=0 )return -ENOENT ; +if (host->ops->get_ro) { + ro = host->ops->get_ro (host) ? true : false; + oldro =mmc_card_readonly (oldcard) ? true : false; +if (oldro ^ ro) +return -ENOENT ; + }Quoted 2 lines
Seems like this code belongs better in
mmc_sd_setup_card(). Could you try moving it there.[Barry Song]
Well. How about:drivers/mmc/core/sd.c index renamed from drivers/mmc/core/sd.c +0
-00c44510..643bc82d8 100644
drivers/mmc/core/sd.c +6
-7@@ -815,6 +815,7 @@ int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card, bool reinit) {int err; +int oldro, ro =-1 ;if (!reinit) {/* @@ -861,23 +862,28 @@ int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card,/* * Check if read-only switch is active. */ -if (!reinit) { -int ro =-1 ; -if (host->ops->get_ro) { -mmc_host_clk_hold (card->host); - ro = host->ops->get_ro (host); -mmc_host_clk_release (card->host); - } +if (host->ops->get_ro) { +mmc_host_clk_hold (card->host); + ro = host->ops->get_ro (host); +mmc_host_clk_release (card->host); + }Quoted 17 lines
drivers/mmc/core/sd.c int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card, · line 876
Quoted 13 lines
drivers/mmc/core/sd.c +5
-8-if (ro <0 ) { -pr_warning ("%s: host does not " -"support reading read-only " -"switch. assuming write-enable.\n" , -mmc_hostname (host)); - }else if (ro >0 ) { -mmc_card_set_readonly (card); - } +if (ro <0 ) +pr_warning ("%s: host does not " +"support reading read-only " +"switch. assuming write-enable.\n" , +mmc_hostname (host));I don't wont this
pr_warningto spam the log each resume. I suppose we could print it only for !reinit, right?ok
Quoted 13 lines
drivers/mmc/core/sd.c int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card, · line 886
Quoted 10 lines
drivers/mmc/core/sd.c +10
-0+ +if (!reinit && (ro >0 )) +mmc_card_set_readonly (card); +else if (reinit && (ro >=0 )) { +/* check if the write-protection lock is changed */ + oldro =mmc_card_readonly (card) ?1 :0 ; + ro = (ro >0 ) ?1 :0 ; + +if (oldro ^ ro) +return -ENOENT ;This will have the effect of quickly returning an error to the mmc bus' ->suspend callback. That path are not able remove the card device, which I guess is what you would like to happen, right?
Quoted 3 lines
I am not completely sure, but I believe the card will still be operational after resuming. Moreover it will be using the initialization frequency and 1-bit bus width and thus performing poorly. This is definitely not what we want.
How did you test this patch? Can you confirm my theory above?
Sorry, I didn't check it carefully.
Quoted 6 lines
The card may only be removed from the
mmc_rescanwork, scheduled atPM_POST_SUSPENDphase. What I think you should do here, is to also set the card state intoMMC_CARD_REMOVED, by invokingmmc_card_set_removed(). Thus the SD'sbus_ops->detectcallback will remove the card during this phase.Kind regards
UffeQuoted 6 lines
To report this email as spam click https://www.mailcontrol.com/sr/MZbqvYs5QwJvpeaetUwhCQ== .
Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Keep up to date with CSR on our technical blog, www.csr.com/blog, CSR people blog, www.csr.com/people, YouTube, www.youtube.com/user/CSRplc, Facebook, www.facebook.com/pages/CSR/191038434253534, or follow us on Twitter at www.twitter.com/CSR_plc. New for 2014, you can now access the wide range of products powered by aptX at www.aptx.com.
Quoted 5 lines
I have a suggestion.
Compared with first patch ,mmc_sd_setup_card function select card command (cmd7) is executed. So In
mmc_rescanfunction the card can not be removed. How about reset the card in this case?
So, in principle that should have the same effect.
Maybe we should actually do _both_ what you suggest and set the card state to MMC_CARD_REMOVED, by invoking mmc_card_set_removed().
That will let mmc_rescan remove the card as soon as possible without sending additional cmds and if there shows up any blk requests from the block layer, these will for sure also fail.
What do you think? Can you test this carefully?
Kind regards
Uffe
Quoted 57 lines
drivers/mmc/core/sd.c +1
-0@@ -815,6 +815,7 @@ int mmc_sd_setup_card(struct mmc_host *host,struct mmc_card *card, bool reinit) { int err; +int oldro, ro =-1 ;if (!reinit) {/*drivers/mmc/core/sd.c +6
-8@@ -858,18 +859,16 @@ int mmc_sd_setup_card(struct mmc_host *host,struct mmc_card *card, return err; } +if (host->ops->get_ro) { +mmc_host_clk_hold (card->host); + ro = host->ops->get_ro (host); +mmc_host_clk_release (card->host); + } +/* * Check if read-only switch is active. */ if (!reinit) { -int ro =-1 ; - -if (host->ops->get_ro) { -mmc_host_clk_hold (card->host); - ro = host->ops->get_ro (host); -mmc_host_clk_release (card->host); - } -if (ro <0 ) { pr_warning("%s: host does not ""support reading read-only "
drivers/mmc/core/sd.c +9
-0@@ -878,6 +877,15 @@ int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card, }else if (ro >0 ) {mmc_card_set_readonly (card); } + }else if (reinit && (ro >=0 )) { +/* check if the write-protection lock is changed */ + oldro =mmc_card_readonly (card) ?1 :0 ; + ro = (ro >0 ) ?1 :0 ; + +if (oldro ^ ro) { +mmc_go_idle (host); +return -ENOENT ; + } }return 0;