From patchwork Wed Dec 18 22:27:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Warren X-Patchwork-Id: 3374171 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 535BAC0D4A for ; Wed, 18 Dec 2013 22:28:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 86EEF2052A for ; Wed, 18 Dec 2013 22:27:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A379E204EB for ; Wed, 18 Dec 2013 22:27:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751068Ab3LRW1w (ORCPT ); Wed, 18 Dec 2013 17:27:52 -0500 Received: from avon.wwwdotorg.org ([70.85.31.133]:45020 "EHLO avon.wwwdotorg.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750961Ab3LRW1v (ORCPT ); Wed, 18 Dec 2013 17:27:51 -0500 Received: from severn.wwwdotorg.org (unknown [192.168.65.5]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by avon.wwwdotorg.org (Postfix) with ESMTPS id A2E726317; Wed, 18 Dec 2013 15:27:50 -0700 (MST) Received: from swarren-lx1.nvidia.com (localhost [127.0.0.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by severn.wwwdotorg.org (Postfix) with ESMTPSA id F3332E45FB; Wed, 18 Dec 2013 15:27:33 -0700 (MST) From: Stephen Warren To: Chris Ball Cc: linux-mmc@vger.kernel.org, linux-tegra@vger.kernel.org, Stephen Warren , Adrian Hunter , Dong Aisheng , Ulf Hansson , Vladimir Zapolskiy Subject: [PATCH] mmc: core: don't return 1 for max_discard Date: Wed, 18 Dec 2013 15:27:43 -0700 Message-Id: <1387405663-14253-1-git-send-email-swarren@wwwdotorg.org> X-Mailer: git-send-email 1.8.1.5 X-NVConfidentiality: public X-Virus-Scanned: clamav-milter 0.97.8 at avon.wwwdotorg.org X-Virus-Status: Clean Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Stephen Warren In mmc_do_calc_max_discard(), if only a single erase block can be discarded within the host controller's timeout, don't allow discard operations at all. Previously, the code allowed sector-at-a-time discard (rather than erase-block-at-a-time), which was chronically slow. Without this patch, on the NVIDIA Tegra Cardhu board, the loops result in qty == 1, which is immediately returned. This causes discard to operate a single sector at a time, which is chronically slow. With this patch in place, discard operates a single erase block at a time, which is reasonably fast. Cc: Adrian Hunter Cc: Dong Aisheng Cc: Ulf Hansson Cc: Vladimir Zapolskiy Fixes: e056a1b5b67b "(mmc: queue: let host controllers specify maximum discard timeout") Signed-off-by: Stephen Warren --- drivers/mmc/core/core.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 57a2b403bf8e..eb952ca634ea 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -2150,8 +2150,25 @@ static unsigned int mmc_do_calc_max_discard(struct mmc_card *card, if (!qty) return 0; - if (qty == 1) - return 1; + /* + * Discard operations may not be aligned to an erase block. In an + * unaligned case, we need to issue 1 more discard operation to HW + * than strictly calculated by: + * sectors_to_erase / sectors_per_discard_operation + * + * To account for this in the timeout calculations, we assume we can + * actually discard one less erase block than fits into the HW + * timeout. This explains the --qty below. + * + * When only a single discard block operation fits into the timeout, + * disallow any discard operations at all. For example, discarding one + * sector at a time is so chronically slow as to be useless. However, + * make an exception for SD cards without an erase shift, since qty + * isn't multiplied up by an erase block size in the code below for + * that case. + */ + if (qty == 1 && !(!card->erase_shift && mmc_card_sd(card))) + return 0; /* Convert qty to sectors */ if (card->erase_shift)