From patchwork Mon Aug 8 02:11:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyungmin Park X-Patchwork-Id: 1042932 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p782BKuw003013 for ; Mon, 8 Aug 2011 02:11:58 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752066Ab1HHCLk (ORCPT ); Sun, 7 Aug 2011 22:11:40 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:43703 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751248Ab1HHCLk (ORCPT ); Sun, 7 Aug 2011 22:11:40 -0400 Received: from epcpsbgm1.samsung.com (mailout4.samsung.com [203.254.224.34]) by mailout4.samsung.com (Oracle Communications Messaging Exchange Server 7u4-19.01 64bit (built Sep 7 2010)) with ESMTP id <0LPL00K047FC2EC0@mailout4.samsung.com> for linux-mmc@vger.kernel.org; Mon, 08 Aug 2011 11:11:38 +0900 (KST) X-AuditID: cbfee61a-b7cf0ae000006bc6-6f-4e3f45da8b50 Received: from epmmp1 ( [203.254.227.16]) by epcpsbgm1.samsung.com (MMPCPMTA) with SMTP id DB.E6.27590.AD54F3E4; Mon, 08 Aug 2011 11:11:38 +0900 (KST) Received: from TNRNDGASPAPP1.tn.corp.samsungelectronics.net ([165.213.149.150]) by mmp1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTPA id <0LPL00F2V7FE9T@mmp1.samsung.com> for linux-mmc@vger.kernel.org; Mon, 08 Aug 2011 11:11:38 +0900 (KST) Received: from july ([165.213.219.111]) by TNRNDGASPAPP1.tn.corp.samsungelectronics.net with Microsoft SMTPSVC(6.0.3790.4675); Mon, 08 Aug 2011 11:12:13 +0900 Received: by july (sSMTP sendmail emulation); Mon, 08 Aug 2011 11:11:33 +0900 Date: Mon, 08 Aug 2011 11:11:33 +0900 From: Kyungmin Park Subject: [PATCH 2/2] mmc: core: mmc sanitize feature support for v4.5 To: linux-mmc@vger.kernel.org, Chris Ball Cc: jh80.chung@samsung.com, arnd@arndb.de Message-id: <20110808021133.GA20325@july> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT Content-disposition: inline User-Agent: Mutt/1.5.17 (2007-11-01) X-OriginalArrivalTime: 08 Aug 2011 02:12:13.0562 (UTC) FILETIME=[96717DA0:01CC5570] X-Brightmail-Tracker: AAAAAA== Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 08 Aug 2011 02:11:59 +0000 (UTC) From: Kyungmin Park In the v4.5, there's no secure erase & trim support. Instead it supports the sanitize feature. From the Spec.: The Sanitize operation is a feature, in addition to TRIM and Erase that is used to remove data from the device. The use of the Sanitize operation requires the device to physically remove data from the unmapped user address space. A Sanitize operation is initiated by writing a value to the extended CSD[165] SANITIZE_START. While the device is performing the sanitize operation, the busy line is asserted. The device will continue the sanitize operation, with busy asserted, until one of the following events occurs: . Sanitize operation is complete. . An HPI is used to abort the operation . A power failure. . A hardware reset. After the sanitize operation is completed, no data should exist in the unmapped host address space. If the sanitize operation is interrupted, either by HPI, power failure or hardware reset, the state of the unmapped host address space cannot be guaranteed. The host must re-initiate the sanitize operation by writing to the SANITIZE_START[165] and allow the operation to complete to be sure that unmapped host address space is clear. Since the region being operated on is not accessible by the host, applications requiring this feature must work with individual device manufacturers to ensure this operation is performing properly and to understand the impact on device reliability. Signed-off-by: Kyungmin Park --- drivers/mmc/card/block.c | 9 ++++++++- drivers/mmc/card/queue.c | 2 +- drivers/mmc/core/core.c | 8 ++++++++ include/linux/mmc/core.h | 1 + include/linux/mmc/mmc.h | 2 ++ 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c index 9649997..d96a9b4 100644 --- a/drivers/mmc/card/block.c +++ b/drivers/mmc/card/block.c @@ -735,11 +735,18 @@ static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq, unsigned int from, nr, arg; int err = 0; - if (!mmc_can_secure_erase_trim(card)) { + if (!(mmc_can_secure_erase_trim(card) || mmc_can_sanitize(card))) { err = -EOPNOTSUPP; goto out; } + /* The sanitize operation is supported at v4.5 only */ + if (mmc_can_sanitize(card)) { + err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, + EXT_CSD_SANITIZE_START, 1, 0); + goto out; + } + from = blk_rq_pos(req); nr = blk_rq_sectors(req); diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c index 45fb362..d7f2f45 100644 --- a/drivers/mmc/card/queue.c +++ b/drivers/mmc/card/queue.c @@ -140,7 +140,7 @@ static void mmc_queue_setup_discard(struct request_queue *q, /* granularity must not be greater than max. discard */ if (card->pref_erase > max_discard) q->limits.discard_granularity = 0; - if (mmc_can_secure_erase_trim(card)) + if (mmc_can_secure_erase_trim(card) || mmc_can_sanitize(card)) queue_flag_set_unlocked(QUEUE_FLAG_SECDISCARD, q); } diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index c88fb57..d6232e0 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1604,6 +1604,14 @@ int mmc_can_discard(struct mmc_card *card) } EXPORT_SYMBOL(mmc_can_discard); +int mmc_can_sanitize(struct mmc_card *card) +{ + if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_SANITIZE) + return 1; + return 0; +} +EXPORT_SYMBOL(mmc_can_sanitize); + int mmc_can_secure_erase_trim(struct mmc_card *card) { if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN) diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h index 6118f10..f1e5773 100644 --- a/include/linux/mmc/core.h +++ b/include/linux/mmc/core.h @@ -158,6 +158,7 @@ extern int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr, extern int mmc_can_erase(struct mmc_card *card); extern int mmc_can_trim(struct mmc_card *card); extern int mmc_can_discard(struct mmc_card *card); +extern int mmc_can_sanitize(struct mmc_card *card); extern int mmc_can_secure_erase_trim(struct mmc_card *card); extern int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from, unsigned int nr); diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h index 5a794cb..b45628b 100644 --- a/include/linux/mmc/mmc.h +++ b/include/linux/mmc/mmc.h @@ -272,6 +272,7 @@ struct _mmc_csd { #define EXT_CSD_PARTITION_ATTRIBUTE 156 /* R/W */ #define EXT_CSD_PARTITION_SUPPORT 160 /* RO */ +#define EXT_CSD_SANITIZE_START 165 /* W */ #define EXT_CSD_WR_REL_PARAM 166 /* RO */ #define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */ #define EXT_CSD_PART_CONFIG 179 /* R/W */ @@ -327,6 +328,7 @@ struct _mmc_csd { #define EXT_CSD_SEC_ER_EN BIT(0) #define EXT_CSD_SEC_BD_BLK_EN BIT(2) #define EXT_CSD_SEC_GB_CL_EN BIT(4) +#define EXT_CSD_SEC_SANITIZE BIT(6) /* v4.5 only */ /* * MMC_SWITCH access modes