Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp2510843ima; Sun, 3 Feb 2019 00:53:42 -0800 (PST) X-Google-Smtp-Source: ALg8bN6hCSMIz9D9oKUJHLOdC5/9g0AQR+9rOn1J5OmPmmEsm+vWwHPEMo8hT2PO20ehKK8/Y4LN X-Received: by 2002:a17:902:6e0f:: with SMTP id u15mr46222326plk.175.1549184022250; Sun, 03 Feb 2019 00:53:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549184022; cv=none; d=google.com; s=arc-20160816; b=XsDf2oWwFkuSwmMjNgd97FqgjwZ7NVRyd1nM7vn93hy8JPqk0gGQ9ipJ8uPg0X8ct2 jJ0SJq2JAHoXWuUBvMVqM3JZDo1aU9Hnom5YHoVL8/WNefY6Fa9rm4AvmieSP6GeLNAx uqpnpCyijF1Vpof6FYFR1J3/MP6meBc8H1jY0KGi2JHagr2jx4BMkLtxY9awY8BQnj+k kCCeD/q7J5PDxnPQJXDV3U1dA2v47Duh67w/KAcgqpgn/Iw33z1mDOuO7wCUp0TVnKOK yCH+0m5tRP6wIJ618cFsf7YR2XK7MAArz5rVmdlUFKIAAe5PLDpKJ+XabP5QiYnh9Kz8 aHpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=1KLk7FUJl0OOKSqsswAFcSywT/IE0PXhbx9E68iNfP0=; b=U+Oo0Y9ABFmArcU1WnTZENagWXZ9/lQ9/1aVgvnCw9Yys0wtQ6uj2lmAPv97eNJLSu FqUyOcjb6TnQDCII7enftBLPxERdNuY9lNcHzFPr2jHPZKmJWbE3AwTwgsJQ0N6DS8UF C8sNpIGtQLMpV2Q4bSrB7FWvI0oCzk0d3DGc2qHQnHwd+GDcSGgEhmyO7K1du3nWo9P9 SyGJGsMt87x36Fl6sDxjKxzu5uoS4BC76ioZlcYBKhoej8+4ETgD+q/cxYgZQlvP0lq+ qfkNz4i1PIXvzD8dmnylEJxqGxTRDHFY1Os7oraJOd5L7PCnKPz39spZOwaOCbiFI7XL QKxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=oGf4Bz8c; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j5si12817749pfg.254.2019.02.03.00.53.26; Sun, 03 Feb 2019 00:53:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=oGf4Bz8c; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727786AbfBCIv3 (ORCPT + 99 others); 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 */ -- 1.9.1