From patchwork Sun Feb 3 08:50:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 10794589 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EC0F1922 for ; Sun, 3 Feb 2019 08:51:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDB662B92E for ; Sun, 3 Feb 2019 08:51:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1C092C53D; Sun, 3 Feb 2019 08:51:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7668A2B92E for ; Sun, 3 Feb 2019 08:51:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727494AbfBCIvB (ORCPT ); Sun, 3 Feb 2019 03:51:01 -0500 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:15410 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727368AbfBCIvB (ORCPT ); Sun, 3 Feb 2019 03:51:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1549183861; x=1580719861; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Vx2WNxuKIv+Lg2L8oPKMd0BLI1DEP0XstOGQcRLuzuQ=; b=RHfQ/pZzmgwsUzr3ClYPJZc5igRkCgPVctjt1Xv/gOQQf6j5NoH4jtta OXVO8HazYowWMScRoUfuKV2qASU/zRyTrFQUgx3a+LkUHhnNa/3+7sNFg aOnnaMxIASyeGMbBMtZwO18eV5mSREWtQ7vaQ3XfgzCJXufguoTvvHH7u 24ORpNkq88zg6gCnuNh5A0AEvz6yZ7baVu+GHP1LpIBtBAmNgyFN+mUci /A72Gvos+0/UDyARZp9glF7oLWqNR5Epl8zqdqXzyNAbBu3R/UwEfKaDT nOuICSGG3diQ9Z8yuqycVb7j8xB0p/YVjTKuaCHjCbF+Fpuvq195j07Ky Q==; X-IronPort-AV: E=Sophos;i="5.56,555,1539619200"; d="scan'208";a="105387540" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Feb 2019 16:51:01 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP; 03 Feb 2019 00:31:52 -0800 Received: from kfae422988.sdcorp.global.sandisk.com ([10.0.230.227]) by uls-op-cesaip01.wdc.com with ESMTP; 03 Feb 2019 00:50:58 -0800 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Wolfram Sang , Adrian Hunter , Jaehoon Chung , Shawn Lin , Avi Shchislowski , Alex Lemberg , linux-kernel@vger.kernel.org, Avri Altman Subject: [PATCH 1/3] mmc: core: Calculate the discard arg only once Date: Sun, 3 Feb 2019 10:50:26 +0200 Message-Id: <1549183828-17316-2-git-send-email-avri.altman@wdc.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1549183828-17316-1-git-send-email-avri.altman@wdc.com> References: <1549183828-17316-1-git-send-email-avri.altman@wdc.com> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The discard arg is a read-only ext_csd parameter - set it once on card init. Signed-off-by: Avri Altman --- drivers/mmc/core/block.c | 12 +++--------- drivers/mmc/core/mmc.c | 8 ++++++++ include/linux/mmc/card.h | 2 ++ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index b08fb91..3502f2c 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -1124,7 +1124,7 @@ static void mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req) { struct mmc_blk_data *md = mq->blkdata; struct mmc_card *card = md->queue.card; - unsigned int from, nr, arg; + unsigned int from, nr; int err = 0, type = MMC_BLK_DISCARD; blk_status_t status = BLK_STS_OK; @@ -1136,24 +1136,18 @@ static void mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req) from = blk_rq_pos(req); nr = blk_rq_sectors(req); - if (mmc_can_discard(card)) - arg = MMC_DISCARD_ARG; - else if (mmc_can_trim(card)) - arg = MMC_TRIM_ARG; - else - arg = MMC_ERASE_ARG; do { err = 0; if (card->quirks & MMC_QUIRK_INAND_CMD38) { err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, INAND_CMD38_ARG_EXT_CSD, - arg == MMC_TRIM_ARG ? + card->discard_arg == MMC_TRIM_ARG ? INAND_CMD38_ARG_TRIM : INAND_CMD38_ARG_ERASE, 0); } if (!err) - err = mmc_erase(card, from, nr, arg); + err = mmc_erase(card, from, nr, card->discard_arg); } while (err == -EIO && !mmc_blk_reset(md, card->host, type)); if (err) status = BLK_STS_IOERR; diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index da892a5..120739c 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -1743,6 +1743,14 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, card->ext_csd.power_off_notification = EXT_CSD_POWER_ON; } + /* set discard_arg */ + if (mmc_can_discard(card)) + card->discard_arg = MMC_DISCARD_ARG; + else if (mmc_can_trim(card)) + card->discard_arg = MMC_TRIM_ARG; + else + card->discard_arg = MMC_ERASE_ARG; + /* * Select timing interface */ diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index de73778..447648b 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -308,6 +308,8 @@ struct mmc_card { unsigned int nr_parts; unsigned int bouncesz; /* Bounce buffer size */ + + unsigned int discard_arg; /* discard args */ }; static inline bool mmc_large_sector(struct mmc_card *card) From patchwork Sun Feb 3 08:50:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 10794591 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 68039746 for ; Sun, 3 Feb 2019 08:51:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 582972B92E for ; Sun, 3 Feb 2019 08:51:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B3F22C53D; Sun, 3 Feb 2019 08:51:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB8D52B92E for ; Sun, 3 Feb 2019 08:51:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727362AbfBCIvU (ORCPT ); Sun, 3 Feb 2019 03:51:20 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:10972 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727323AbfBCIvU (ORCPT ); Sun, 3 Feb 2019 03:51:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1549183879; x=1580719879; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=uvIHv4YRB8ADXpT53jyv+XRLLwWBOTOF3+b4NWRgMFQ=; b=TQndOTfv/M0Zc03Rf7V+61D62qREJnjNs401K/690hft8QmXQuZVOjbm DHEjmwwbCIt8cDK6kaZNIH0RvMtuciuhoNidiUJ6D5KNjsrH/2lajTBqn FyG7UvC6uwgOzfqDr6gBNGgPIzXzA0nLzTZhSYQ6bE8soAFRzgCO+Qcoa y9kkdUq+m91Ie4ewtWfwUwmQv/3kwDA9fW+I/1C4EHk0knjFfW2/ggmJi c1wOHgHGjx/cz6x4xt+704roQygaGFmEb6BPx6xdl2EPEaO1SWMDphALv 2RhFBgAu6alREO75NR5iiikv7eoKEg3ausLTRfeWAMhoNgnSUcGVtf6CO g==; X-IronPort-AV: E=Sophos;i="5.56,555,1539619200"; d="scan'208";a="102183788" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 03 Feb 2019 16:51:19 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP; 03 Feb 2019 00:30:10 -0800 Received: from kfae422988.sdcorp.global.sandisk.com ([10.0.230.227]) by uls-op-cesaip01.wdc.com with ESMTP; 03 Feb 2019 00:51:16 -0800 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Wolfram Sang , Adrian Hunter , Jaehoon Chung , Shawn Lin , Avi Shchislowski , Alex Lemberg , linux-kernel@vger.kernel.org, Avri Altman Subject: [PATCH 2/3] mmc: core: Indicate SD specs higher than 4.0 Date: Sun, 3 Feb 2019 10:50:27 +0200 Message-Id: <1549183828-17316-3-git-send-email-avri.altman@wdc.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1549183828-17316-1-git-send-email-avri.altman@wdc.com> References: <1549183828-17316-1-git-send-email-avri.altman@wdc.com> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP SD specs version 4.x and 5.x have a dedicated slices in the SCR register. Higher versions will rely on a combination of the existing fields. Signed-off-by: Avri Altman --- drivers/mmc/core/sd.c | 5 +++++ include/linux/mmc/card.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index d0d9f90..44f4cbc 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -209,6 +209,11 @@ static int mmc_decode_scr(struct mmc_card *card) /* Check if Physical Layer Spec v3.0 is supported */ scr->sda_spec3 = UNSTUFF_BITS(resp, 47, 1); + if (scr->sda_spec3) { + scr->sda_spec4 = UNSTUFF_BITS(resp, 42, 1); + scr->sda_specx = UNSTUFF_BITS(resp, 38, 4); + } + if (UNSTUFF_BITS(resp, 55, 1)) card->erased_byte = 0xFF; else diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index 447648b..919e644 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -133,6 +133,8 @@ struct mmc_ext_csd { struct sd_scr { unsigned char sda_vsn; unsigned char sda_spec3; + unsigned char sda_spec4; + unsigned char sda_specx; unsigned char bus_widths; #define SD_SCR_BUS_WIDTH_1 (1<<0) #define SD_SCR_BUS_WIDTH_4 (1<<2) From patchwork Sun Feb 3 08:50:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 10794593 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 628FF922 for ; Sun, 3 Feb 2019 08:51:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 533452B92E for ; Sun, 3 Feb 2019 08:51:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 450C12C53D; Sun, 3 Feb 2019 08:51:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1C812B92E for ; Sun, 3 Feb 2019 08:51:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727770AbfBCIv3 (ORCPT ); Sun, 3 Feb 2019 03:51:29 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:10981 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727323AbfBCIv2 (ORCPT ); Sun, 3 Feb 2019 03:51:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1549183888; x=1580719888; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=yUbASFQeD3pBbuYlzD8fvQKYvtLT2drGOgj67Fk70Ss=; b=oGf4Bz8ciekYF22Q4OO5G4/SgUlAIt1QWqOBjIWcoVKnqB5WN55nT8k/ IIN8gYXoK10llYzhlm40QECS5clqgos07WqwztT0l4WxTwVEJLV2oo/rR ssSevWF3YZIeRoh8FfbMfAReX/809/iQ1ixtMlYy2CbvO9mhQvsl0JKvZ eG7cN9mcVlaSgS5VXqTY5PTn49FIcfp0LvQfUgVuTvmPQVw4swSxmxBHO 72LUzBHMRtfr4Fxj5S8Op5xG1xoU1tIMU2cPyUa7Oseni1h/5xqWcE/jH TPB/aku8xXXauZLK3BXcTweQyFOeMMoV4n5T3BOGZQUH2LBB0gDGybGid A==; X-IronPort-AV: E=Sophos;i="5.56,555,1539619200"; d="scan'208";a="102183791" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 03 Feb 2019 16:51:28 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP; 03 Feb 2019 00:30:19 -0800 Received: from kfae422988.sdcorp.global.sandisk.com ([10.0.230.227]) by uls-op-cesaip01.wdc.com with ESMTP; 03 Feb 2019 00:51:25 -0800 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Wolfram Sang , Adrian Hunter , Jaehoon Chung , Shawn Lin , Avi Shchislowski , Alex Lemberg , linux-kernel@vger.kernel.org, Avri Altman Subject: [PATCH 3/3] mmc: core: Add discard support to sd Date: Sun, 3 Feb 2019 10:50:28 +0200 Message-Id: <1549183828-17316-4-git-send-email-avri.altman@wdc.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1549183828-17316-1-git-send-email-avri.altman@wdc.com> References: <1549183828-17316-1-git-send-email-avri.altman@wdc.com> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP SD spec v5.1 adds discard support. The flows and commands are similar to mmc, so just set the discard arg in CMD38. Actually, there is no need to check for the spec version like we are doing, as it is assured that the reserved bits in earlier versions are null. Do that anyway to document the spec version that introduce it. Signed-off-by: Avri Altman --- drivers/mmc/core/core.c | 6 +++++- drivers/mmc/core/sd.c | 10 ++++++++++ include/linux/mmc/sd.h | 6 ++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 5bd58b9..c495935 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -2181,7 +2181,10 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr, if (!card->erase_size) return -EOPNOTSUPP; - if (mmc_card_sd(card) && arg != MMC_ERASE_ARG) + if (mmc_card_sd(card) && arg == SD_DISCARD_ARG) + goto skip_arg_testing; + + if (mmc_card_sd(card) && arg != SD_ERASE_ARG) return -EOPNOTSUPP; if ((arg & MMC_SECURE_ARGS) && @@ -2200,6 +2203,7 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr, if (arg == MMC_ERASE_ARG) nr = mmc_align_erase_size(card, &from, &to, nr); +skip_arg_testing: if (nr == 0) return 0; diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 44f4cbc..b554a17 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -231,6 +231,8 @@ static int mmc_read_ssr(struct mmc_card *card) { unsigned int au, es, et, eo; __be32 *raw_ssr; + u32 resp[4] = {}; + u8 discard_support; int i; if (!(card->csd.cmdclass & CCC_APP_SPEC)) { @@ -276,6 +278,14 @@ static int mmc_read_ssr(struct mmc_card *card) } } + /* + * starting SD5.1 discard is supported if DISCARD_SUPPORT (b313) is set + */ + resp[3] = card->raw_ssr[6]; + discard_support = UNSTUFF_BITS(resp, 313 - 288, 1); + card->discard_arg = (card->scr.sda_specx && discard_support) ? + SD_DISCARD_ARG : SD_ERASE_ARG; + return 0; } diff --git a/include/linux/mmc/sd.h b/include/linux/mmc/sd.h index 1ebcf9b..ec94a5a 100644 --- a/include/linux/mmc/sd.h +++ b/include/linux/mmc/sd.h @@ -91,4 +91,10 @@ #define SD_SWITCH_ACCESS_DEF 0 #define SD_SWITCH_ACCESS_HS 1 +/* + * Erase/discard + */ +#define SD_ERASE_ARG 0x00000000 +#define SD_DISCARD_ARG 0x00000001 + #endif /* LINUX_MMC_SD_H */