Skip to contentSkip to conversation

mmc: core: allow detection of locked cards

PATCH Superseded [email protected] 1 participant 2 messages May 23, 2024 MMC, SD and SDIO

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mmc: core: allow detection of locked cards

From: Daniel Kucera <[email protected]>

Locked card will not reply to SEND_SCR or SD_STATUS commands so it was failing to initialize previously. When skipped, the card will get initialized and CMD42 can be sent using ioctl to unlock the card or remove password protection. Until unlocked, all read/write calls will timeout.

---
 drivers/mmc/core/sd.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/mmc/core/sd.c +13 -1
index 1c8148cdd..0eebfea02 100644
@@ -928,8 +928,20 @@ int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card,
 	bool reinit)
 {
 	int err;
+	u32 card_status;
 
-	if (!reinit) {
+	err = mmc_send_status(card, &card_status);
+	if (err){
+		pr_err("%s: unable to get card status\n",
+			mmc_hostname(host));
+			return err;
+	}
+
+	if (card_status & R1_CARD_IS_LOCKED){
+		pr_warn("%s: card is locked\n", mmc_hostname(host));
+	}
+
+	if (!reinit && !(card_status & R1_CARD_IS_LOCKED)) {
 		/*
 		 * Fetch SCR from card.
 		 */
Signature · 1 line
2.34.1
#1 lore raw
Quoted 39 lines · On 2024-05-23 13:13, [email protected] wrote:

From: Daniel Kucera <[email protected]>

Locked card will not reply to SEND_SCR or SD_STATUS commands so it was failing to initialize previously. When skipped, the card will get initialized and CMD42 can be sent using ioctl to unlock the card or remove password protection. Until unlocked, all read/write calls will timeout.

---
 drivers/mmc/core/sd.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/mmc/core/sd.c +13 -1
index 1c8148cdd..0eebfea02 100644
@@ -928,8 +928,20 @@ int mmc_sd_setup_card(struct mmc_host *host,
 struct mmc_card *card,
 	bool reinit)
 {
 	int err;
+	u32 card_status;
 
-	if (!reinit) {
+	err = mmc_send_status(card, &card_status);
+	if (err){
+		pr_err("%s: unable to get card status\n",
+			mmc_hostname(host));
+			return err;
+	}
+
+	if (card_status & R1_CARD_IS_LOCKED){
+		pr_warn("%s: card is locked\n", mmc_hostname(host));
+	}
+
+	if (!reinit && !(card_status & R1_CARD_IS_LOCKED)) {
 		/*
 		 * Fetch SCR from card.
Quoted 1 line

*/

Please forget this one, it doesn't work.