Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4478944imc; Mon, 25 Feb 2019 05:44:07 -0800 (PST) X-Google-Smtp-Source: AHgI3IaXIwGqEDC97y5eVj0BsGmZxELRF+tkBACrtsurQg+RRvn0CvV+/MJXBFmqzkU5UPsNFd4w X-Received: by 2002:a63:8341:: with SMTP id h62mr19393751pge.254.1551102247849; Mon, 25 Feb 2019 05:44:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551102247; cv=none; d=google.com; s=arc-20160816; b=E56m+/kAcTCJ00n/2qXtdNUyv1rjceVA/Kn5F+1wcACzwdldSk5Muy9JsSSQ9Sx4bW E2iuhC/YFZn4+MPIzm6kiKSdIqkbdbuobVdpZz8KbJy7wnDh+mIiSvZqEgKBVuf/cCrW 4brqnsbFZk8AeMCdRAdB7zshxh0i9CkMUp7DAB0hQV9IM/RzbMt3PpfyRJ9/7YmKAUSK 5g7mM5lUBKxEA64UPopOK4TLOl5P97vXdCOl5rxFTWDoPU4wi2QMPaWlSbmfKB7Y6Rqo TslWLRLcV64gQO8NA1u4YRaXm2Jh0pr52G/QQBuSckvlgfPOQmgE4bvesI+yxhZGOpfM qPwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=xP/eylsEw/AILLQ+roIACxEMo/0EuKRwFzs92PrDQ7A=; b=WFS73xEE16h4+bsaQdTVT4RbQHF1hwQQ8K3mA0v8kSoJk9S4DECHKzg9vk0o4vcXVX 0WLOav7tQWMUACyzCUBPFM/Dl6asuzKdYQePb5E8FosbhpK+flM+eG9gB2wYukf89yfK pZ6L4Tpp3Jfb4XV+X77/Gl8zUA1eF8XoBuwjFEzakj+qZM2iYYKSBgrovZjS9+Bbt2mu pV+hDtmmPEIx16PXpW3cv8ltVLRweuRlg6z8hZIXbH07bOmFCde42UWZyBn+GMEH40Dp 1zfQYzMaYzSG3hnQ6EIjyqPL2M6rQMI5duC6PHbds3oXmDqEpgsuX6EPuNdp1S78nhPu MUCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JHNvN6Fe; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u11si9372518plr.227.2019.02.25.05.43.52; Mon, 25 Feb 2019 05:44:07 -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=pass header.i=@linaro.org header.s=google header.b=JHNvN6Fe; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727192AbfBYNnH (ORCPT + 99 others); Mon, 25 Feb 2019 08:43:07 -0500 Received: from mail-vk1-f196.google.com ([209.85.221.196]:36671 "EHLO mail-vk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726706AbfBYNnG (ORCPT ); Mon, 25 Feb 2019 08:43:06 -0500 Received: by mail-vk1-f196.google.com with SMTP id v131so2100791vkd.3 for ; Mon, 25 Feb 2019 05:43:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xP/eylsEw/AILLQ+roIACxEMo/0EuKRwFzs92PrDQ7A=; b=JHNvN6FeGigPCYS2A4L80xsIMVHUnLajxkjateAnqeogTJcIYavgAD13yYtFewuaYO KG8cWRMqpp4gAj6qGUrwE8ilxRXBVkemZ9UIpcAn9wupexnLKHMvZUopJZ0CCZTmLaaF hGHiaTZbBLUByySn7cPmd+PsjX8ZVuOhdbTwskCXtm3b1nTxX4Y5q9UeFwO7pXIyJTeC R7lw3E7fCiVKxhks4bPBq3EJcRdiTTb6hT6p3lNLGLdW/BLHm6vauIWBVgb9jsoEaeOo +crdckqF0P4iXHtgSEm8FX3V+DBoNVF4AyDwJh9A3Ec7RINFUr15YZrqEqpDc2J19btz dWhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xP/eylsEw/AILLQ+roIACxEMo/0EuKRwFzs92PrDQ7A=; b=FNBMPZE0IIpbvY39B4v3+LWnfDigberqscD/AaKHNdVwgUE0lDkicczAqz/zQ4xr4Z TyY50AapwqXfnvsDxX96cnnXCw6JMdwFpwhgpfAZxFwuD4BjdBqe7jROZMa1KWmMHqrC vk38eYc6FjnSEaBwYoKhx2dvgD/r6x/X7hJU6t1T/aHE/83n1c3TsOYsUFAt+gZbMWEj +qG3GjT8ajhRGMYWMeTCj3KuFsf/RPeQyn3fI8q/ts3xw+8Yz1Q0kBj2nDMGR0EHepv6 5nTwOPzQ1FAobUPFq2s+jVwDxpog7E2AFsrWBsW6o2q1abQ625Nh9bTGB6lhM/ZQ55Ml 2kJQ== X-Gm-Message-State: AHQUAuZy4QdwwBSSbYNGP7FMKbFlftH419r3E5Oard6A7drX+SqZHKbS xoE7KuiWyNbaHc6FLtURPdeg3tp6VEcoP8/GihhNfQ== X-Received: by 2002:a1f:a5d3:: with SMTP id o202mr9488422vke.40.1551102185582; Mon, 25 Feb 2019 05:43:05 -0800 (PST) MIME-Version: 1.0 References: <1549452487-17193-1-git-send-email-avri.altman@wdc.com> <1549452487-17193-4-git-send-email-avri.altman@wdc.com> In-Reply-To: <1549452487-17193-4-git-send-email-avri.altman@wdc.com> From: Ulf Hansson Date: Mon, 25 Feb 2019 14:42:29 +0100 Message-ID: Subject: Re: [PATCH v2 3/3] mmc: core: Add discard support to sd To: Avri Altman Cc: "linux-mmc@vger.kernel.org" , Wolfram Sang , Adrian Hunter , Jaehoon Chung , Shawn Lin , Avi Shchislowski , Alex Lemberg , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 6 Feb 2019 at 12:29, Avri Altman wrote: > > SD spec v5.1 adds discard support. The flows and commands are similar to > mmc, so just set the discard arg in CMD38. So this means that we from now on, if the SD card supports discard, we are going to use it in favor of erase. This is consistent with how we treat eMMC, so I think it makes sense. Could you perhaps fold in some information about this in the changelog, to make this clear on what this change means. You may also want to explain a little bit what the difference is from the SD card storage point of view. Like after an erase, it either 1 or 0s on the media, while after a discard it can be whatever. > > 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. The check is needed for other purposes, so please just drop this statement. > > Signed-off-by: Avri Altman > --- > drivers/mmc/core/core.c | 6 +++++- > drivers/mmc/core/sd.c | 10 +++++++++- > include/linux/mmc/sd.h | 1 + > 3 files changed, 15 insertions(+), 2 deletions(-) > > diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c > index de0f1a1..4d62f28 100644 > --- a/drivers/mmc/core/core.c > +++ b/drivers/mmc/core/core.c > @@ -2164,7 +2164,7 @@ static unsigned int mmc_align_erase_size(struct mmc_card *card, > * @card: card to erase > * @from: first sector to erase > * @nr: number of sectors to erase > - * @arg: erase command argument (SD supports only %SD_ERASE_ARG) > + * @arg: erase command argument > * > * Caller must claim host before calling this function. > */ > @@ -2181,6 +2181,9 @@ 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 == SD_DISCARD_ARG) > + goto skip_arg_testing; > + This isn't consistent with the rest of the code path in this function, please adopt to that. > if (mmc_card_sd(card) && arg != SD_ERASE_ARG) Couldn't you add a check for !SD_DISCARD_ARG here instead? > return -EOPNOTSUPP; > > @@ -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 c2db94d..2b4fc22 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,7 +278,13 @@ static int mmc_read_ssr(struct mmc_card *card) > } > } > > - card->erase_arg = SD_ERASE_ARG; > + /* > + * 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); Couldn't you just replace this with "discard_support = UNSTUFF_BITS(card->raw_ssr, 313 - 256, 1);" ? > + card->erase_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 1a6d10f..ec94a5a 100644 > --- a/include/linux/mmc/sd.h > +++ b/include/linux/mmc/sd.h > @@ -95,5 +95,6 @@ > * Erase/discard > */ > #define SD_ERASE_ARG 0x00000000 > +#define SD_DISCARD_ARG 0x00000001 > > #endif /* LINUX_MMC_SD_H */ > -- > 1.9.1 > Besides the above changes, there is more important thing I think you have left out to consider. With discard the operation should be completed by the card within 250ms, while for erase the timeout depends on the number of blocks to be erased. I am fine if we address that on top this change though, just want to point it out so we don't forget it. Kind regards Uffe