From: Al Cooper <alcooperx@gmail.com>
To: cjb@laptop.org, linux-mmc@vger.kernel.org
Cc: Al Cooper <alcooperx@gmail.com>
Subject: [PATCH V3 7/7] mmc: lock: Change MMC init to handle locked cards.
Date: Wed, 5 Mar 2014 18:44:52 -0500 [thread overview]
Message-ID: <1394063092-9048-8-git-send-email-alcooperx@gmail.com> (raw)
In-Reply-To: <1394063092-9048-1-git-send-email-alcooperx@gmail.com>
- Change mmc_init_card() to check for a locked card and, if found,
try to get a password using the kernel KEYS subsystem, unlock the card
and continue. Unlike SD cards, MMC cards support all initialization
commands when locked so the init sequence can be completed on a
locked card and the card can be used without further init after being
unlocked. If the unlock fails, the card state will be marked as "locked"
and the block layer will be prevented from coming up.
- Add sysfs attribute "unlock_retry" that will try again to unlock
the card. If the unlock succeeds, the cards "locked" state will be cleared
and the block layer will be allowed to come up.
Signed-off-by: Al Cooper <alcooperx@gmail.com>
---
drivers/mmc/core/mmc.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 44 insertions(+), 2 deletions(-)
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 3703cd1..240ff48 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -726,10 +726,37 @@ out:
return res;
}
-static DEVICE_ATTR(lock, S_IWUSR | S_IRUGO,
- mmc_lock_show, mmc_lock_store);
+static ssize_t mmc_unlock_retry_store(struct device *dev,
+ struct device_attribute *att,
+ const char *data, size_t len)
+{
+ struct mmc_card *card = mmc_dev_to_card(dev);
+ struct mmc_host *host = card->host;
+ int err;
+ BUG_ON(!card);
+ BUG_ON(!host);
+
+ mmc_claim_host(host);
+ if (!mmc_card_locked(card)) {
+ mmc_release_host(host);
+ return len;
+ }
+ err = mmc_unlock_card(card);
+ mmc_release_host(host);
+ if (err < 0)
+ return err;
+ device_release_driver(dev);
+ err = device_attach(dev);
+ if (err < 0)
+ return err;
+ return len;
+}
+static DEVICE_ATTR(lock, S_IWUSR | S_IRUGO,
+ mmc_lock_show, mmc_lock_store);
+static DEVICE_ATTR(unlock_retry, S_IWUSR,
+ NULL, mmc_unlock_retry_store);
#endif /* CONFIG_MMC_LOCK */
@@ -772,6 +799,7 @@ static struct attribute *mmc_std_attrs[] = {
&dev_attr_rel_sectors.attr,
#ifdef CONFIG_MMC_LOCK
&dev_attr_lock.attr,
+ &dev_attr_unlock_retry.attr,
#endif /* CONFIG_MMC_LOCK */
NULL,
};
@@ -958,6 +986,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
unsigned int max_dtr;
u32 rocr;
u8 *ext_csd = NULL;
+ u32 status;
BUG_ON(!host);
WARN_ON(!host->claimed);
@@ -1413,6 +1442,19 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
}
}
+ /* If card is locked, try to unlock it */
+ err = mmc_send_status(card, &status);
+ if (err)
+ goto free_card;
+ if (status & R1_CARD_IS_LOCKED) {
+ pr_info("%s: card is locked.\n", mmc_hostname(card->host));
+ err = mmc_unlock_card(card);
+ if (err != 0) {
+ pr_warn("%s: Card unlock failed.\n",
+ mmc_hostname(card->host));
+ }
+ }
+
if (!oldcard)
host->card = card;
--
1.8.1.3
prev parent reply other threads:[~2014-03-05 23:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-05 23:44 [PATCH V3 0/7] Add password protected lock/unlock support for SD/MMC Al Cooper
2014-03-05 23:44 ` [PATCH V3 1/7] mmc: lock: Use the kernel "KEYS" subsystem to get a card's password Al Cooper
2014-03-05 23:44 ` [PATCH V3 2/7] mmc: lock: Add low level LOCK_UNLOCK command Al Cooper
2014-03-05 23:44 ` [PATCH V3 3/7] mmc: lock: Add function to unlock a password locked card Al Cooper
2014-03-05 23:44 ` [PATCH V3 4/7] mmc: lock: Add card lock/unlock maintenance commands Al Cooper
2014-03-05 23:44 ` [PATCH V3 5/7] mmc: lock: Change SD init functionality to handle locked SD cards Al Cooper
2014-03-05 23:44 ` [PATCH V3 6/7] mmc: lock: Prevent block device from coming up for locked cards Al Cooper
2014-03-05 23:44 ` Al Cooper [this message]
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=1394063092-9048-8-git-send-email-alcooperx@gmail.com \
--to=alcooperx@gmail.com \
--cc=cjb@laptop.org \
--cc=linux-mmc@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).