From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752595AbcIBIft (ORCPT ); Fri, 2 Sep 2016 04:35:49 -0400 Received: from lucky1.263xmail.com ([211.157.147.132]:53484 "EHLO lucky1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752312AbcIBIfl (ORCPT ); Fri, 2 Sep 2016 04:35:41 -0400 X-263anti-spam: KSV:0; X-MAIL-GRAY: 1 X-MAIL-DELIVERY: 0 X-KSVirus-check: 0 X-ABS-CHECKED: 4 X-ADDR-CHECKED: 0 X-RL-SENDER: shawn.lin@rock-chips.com X-FST-TO: linus.walleij@linaro.org X-SENDER-IP: 103.29.142.67 X-LOGIN-NAME: shawn.lin@rock-chips.com X-UNIQUE-TAG: <28d4a413625840375e2d89c2149e7ac6> X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 Subject: Re: [PATCH v3] mmc: core: Optimize the mmc erase size alignment To: Baolin Wang , ulf.hansson@linaro.org References: <9de99671750430d7d80a8f351c0ec7a7088c9b00.1472635587.git.baolin.wang@linaro.org> Cc: shawn.lin@rock-chips.com, adrian.hunter@intel.com, rmk+kernel@arm.linux.org.uk, dianders@chromium.org, heiko@sntech.de, david@protonic.nl, hdegoede@redhat.com, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, broonie@kernel.org, linus.walleij@linaro.org From: Shawn Lin Message-ID: <363fc241-8220-2706-778c-706aec076d49@rock-chips.com> Date: Fri, 2 Sep 2016 16:34:43 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <9de99671750430d7d80a8f351c0ec7a7088c9b00.1472635587.git.baolin.wang@linaro.org> Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Baolin, On 2016/8/31 17:32, Baolin Wang wrote: > Before issuing mmc_erase() function, users always have checked if it can > erase with mmc_can_erase/trim/discard() function, thus remove the redundant > erase checking in mmc_erase() function. > > This patch also optimizes the erase start/end sector alignment with It implies you could split this patch into two for dealing with diff things. :) Otherwise, you could add my test tag, Tested-by: Shawn Lin > round_up()/round_down() function, when erase command is MMC_ERASE_ARG. > > Signed-off-by: Baolin Wang > --- > Changes since v2: > - Add nr checking and other optimization in mmc_erase() function. > > Changes since v1: > - Add the alignment if card->erase_size is not power of 2. > --- > drivers/mmc/core/core.c | 82 ++++++++++++++++++++++++++++++----------------- > 1 file changed, 53 insertions(+), 29 deletions(-) > > diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c > index e55cde6..52156d4 100644 > --- a/drivers/mmc/core/core.c > +++ b/drivers/mmc/core/core.c > @@ -2202,6 +2202,51 @@ out: > return err; > } > > +static unsigned int mmc_align_erase_size(struct mmc_card *card, > + unsigned int *from, > + unsigned int *to, > + unsigned int nr) > +{ > + unsigned int from_new = *from, nr_new = nr, rem; > + > + if (is_power_of_2(card->erase_size)) { > + unsigned int temp = from_new; > + > + from_new = round_up(temp, card->erase_size); > + rem = from_new - temp; > + > + if (nr_new > rem) > + nr_new -= rem; > + else > + return 0; > + > + nr_new = round_down(nr_new, card->erase_size); > + } else { > + rem = from_new % card->erase_size; > + if (rem) { > + rem = card->erase_size - rem; > + from_new += rem; > + if (nr_new > rem) > + nr_new -= rem; > + else > + return 0; > + } > + > + rem = nr_new % card->erase_size; > + if (rem) > + nr_new -= rem; > + } > + > + if (nr_new == 0) > + return 0; > + > + /* 'from' and 'to' are inclusive */ > + *to = from_new + nr_new - 1; > + *from = from_new; > + > + return nr_new; > +} > + > /** > * mmc_erase - erase sectors. > * @card: card to erase > @@ -2217,13 +2262,6 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr, > unsigned int rem, to = from + nr; > int err; > > - if (!(card->host->caps & MMC_CAP_ERASE) || > - !(card->csd.cmdclass & CCC_ERASE)) > - return -EOPNOTSUPP; > - > - if (!card->erase_size) > - return -EOPNOTSUPP; > - > if (mmc_card_sd(card) && arg != MMC_ERASE_ARG) > return -EOPNOTSUPP; > > @@ -2240,31 +2278,17 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr, > return -EINVAL; > } > > - if (arg == MMC_ERASE_ARG) { > - rem = from % card->erase_size; > - if (rem) { > - rem = card->erase_size - rem; > - from += rem; > - if (nr > rem) > - nr -= rem; > - else > - return 0; > - } > - rem = nr % card->erase_size; > - if (rem) > - nr -= rem; > - } > - > if (nr == 0) > return 0; > > - to = from + nr; > - > - if (to <= from) > - return -EINVAL; > - > - /* 'from' and 'to' are inclusive */ > - to -= 1; > + if (arg == MMC_ERASE_ARG) { > + nr = mmc_align_erase_size(card, &from, &to, nr); > + if (nr == 0) > + return 0; > + } else { > + /* 'from' and 'to' are inclusive */ > + to -= 1; > + } > > /* > * Special case where only one erase-group fits in the timeout budget: > -- Best Regards Shawn Lin