From patchwork Tue May 19 23:11:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Cooper X-Patchwork-Id: 6441071 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 236DA9F318 for ; Tue, 19 May 2015 23:12:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 52902203DF for ; Tue, 19 May 2015 23:12:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 65995203E9 for ; Tue, 19 May 2015 23:12:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751509AbbESXMT (ORCPT ); Tue, 19 May 2015 19:12:19 -0400 Received: from mail-gw3-out.broadcom.com ([216.31.210.64]:6591 "EHLO mail-gw3-out.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752176AbbESXMS (ORCPT ); Tue, 19 May 2015 19:12:18 -0400 X-IronPort-AV: E=Sophos;i="5.13,460,1427785200"; d="scan'208";a="65160069" Received: from irvexchcas08.broadcom.com (HELO IRVEXCHCAS08.corp.ad.broadcom.com) ([10.9.208.57]) by mail-gw3-out.broadcom.com with ESMTP; 19 May 2015 16:22:06 -0700 Received: from IRVEXCHSMTP3.corp.ad.broadcom.com (10.9.207.53) by IRVEXCHCAS08.corp.ad.broadcom.com (10.9.208.57) with Microsoft SMTP Server (TLS) id 14.3.235.1; Tue, 19 May 2015 16:12:10 -0700 Received: from mail-irva-13.broadcom.com (10.10.10.20) by IRVEXCHSMTP3.corp.ad.broadcom.com (10.9.207.53) with Microsoft SMTP Server id 14.3.235.1; Tue, 19 May 2015 16:12:10 -0700 Received: from stbsrv-and-3.and.broadcom.com (unknown [10.28.16.21]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id F3D6540FE5; Tue, 19 May 2015 16:10:27 -0700 (PDT) From: Al Cooper To: , , CC: Al Cooper Subject: [PATCH V3 7/8] mmc: lock: Change MMC init to handle locked cards. Date: Tue, 19 May 2015 19:11:13 -0400 Message-ID: <1432077074-8422-8-git-send-email-alcooperx@gmail.com> X-Mailer: git-send-email 1.9.0.138.g2de3478 In-Reply-To: <1432077074-8422-1-git-send-email-alcooperx@gmail.com> References: <1432077074-8422-1-git-send-email-alcooperx@gmail.com> MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP - 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" which will prevent the block layer from reading the partition table. - 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 restarted which will now read the partition table. Signed-off-by: Al Cooper --- 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 8e94eb8..2c953c5 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -768,10 +768,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 */ @@ -831,6 +858,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, }; @@ -1279,6 +1307,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, int err; u32 cid[4]; u32 rocr; + u32 status; BUG_ON(!host); WARN_ON(!host->claimed); @@ -1568,6 +1597,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;