From patchwork Fri Sep 2 11:30:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 75295 Delivered-To: patches@linaro.org Received: by 10.140.29.8 with SMTP id a8csp814534qga; Fri, 2 Sep 2016 04:30:08 -0700 (PDT) X-Received: by 10.46.0.5 with SMTP id 5mr6548931lja.59.1472815808300; Fri, 02 Sep 2016 04:30:08 -0700 (PDT) Return-Path: Received: from mail-lf0-x22c.google.com (mail-lf0-x22c.google.com. [2a00:1450:4010:c07::22c]) by mx.google.com with ESMTPS id d76si5202482lfe.231.2016.09.02.04.30.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Sep 2016 04:30:08 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::22c as permitted sender) client-ip=2a00:1450:4010:c07::22c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::22c as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-lf0-x22c.google.com with SMTP id e198so47811919lfb.2 for ; Fri, 02 Sep 2016 04:30:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=yZWWeUPo0KYXg0LIW1awhLP2Wohoo/tguCIjDF0G1X4=; b=dR7IP1qegZ+KVBt3nPpcVegIE4ywiABzqlufK1LPeNyADrKpEnl4w/xtCuxgh08WrJ tfL5W72bBtz2nXTZwbDRkIheEEy+SG4iA057KZ3cm7/yGrfmEHtH4CFxEASoHmD+ONX+ U8RMO0k43s7LwApG8mDzM16D6GUyuRR7npm3s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=yZWWeUPo0KYXg0LIW1awhLP2Wohoo/tguCIjDF0G1X4=; b=jy+EwjiLyCSmBdSOmxuayGhMKdDgL1kBpw2gmk+tKCPDuNStXJjY0CUUxg5/RyFt2Z q7CdzxpIbH6Dxf7wCeJci+qS0XzFlJC4K3QD5JuSukbBewBNlAq54i910sKGz/1Hhosd DpnGGoxa6yKPAM66S4K4G/wlqbaHFp5bzGN/YlC2zV9N5umue8LB/l+cZp2DBnQskih1 eaQrj8iksd93pLpdmyPhPWdxkKeVA1crMCP8eOuhEDwDM1PBV2QpuAaWBbrVlONhgRff TS/Kzok5MQlMF/xJ8tqISu5jQXaXe1Q7c8oy2GMg9PJotKyXGcCMsOeH9XemhxgK2css LvDA== X-Gm-Message-State: AE9vXwPXYK8+44ADvkXGgSFNjLXg32SuUoNN6aFuNw1C9JmzZcudcVXoxnTgA6Ni9MA4DA+/jlI= X-Received: by 10.25.1.213 with SMTP id 204mr6755791lfb.114.1472815807830; Fri, 02 Sep 2016 04:30:07 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-155-4-130-67.na.cust.bahnhof.se. [155.4.130.67]) by smtp.gmail.com with ESMTPSA id n128sm2202216lfb.45.2016.09.02.04.30.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 02 Sep 2016 04:30:06 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Jaehoon Chung , Adrian Hunter , Baolin Wang , Shawn Lin Subject: [PATCH] mmc: core: Use a default maximum erase timeout Date: Fri, 2 Sep 2016 13:30:01 +0200 Message-Id: <1472815801-24932-1-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 In cases when the host->max_busy_timeout isn't specified, the calculated number of maximum discard sectors defaults to UINT_MAX. This may cause a too long timeout for a discard request. Avoid this by using a default maximum erase timeout of 60s, used when we calculate the maximum number of sectors that are allowed to be discarded per request. Do note that the minimum number of sectors to be discarded is still at least one "preferred erase size". Signed-off-by: Ulf Hansson --- drivers/mmc/core/core.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) -- 1.9.1 diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index e55cde6..59b452d 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -58,6 +58,9 @@ */ #define MMC_BKOPS_MAX_TIMEOUT (4 * 60 * 1000) /* max time to wait in ms */ +/* The max erase timeout, used when host->max_busy_timeout isn't specified */ +#define MMC_ERASE_TIMEOUT_MS (60 * 1000) /* 60 s */ + static const unsigned freqs[] = { 400000, 300000, 200000, 100000 }; /* @@ -2352,6 +2355,8 @@ static unsigned int mmc_do_calc_max_discard(struct mmc_card *card, struct mmc_host *host = card->host; unsigned int max_discard, x, y, qty = 0, max_qty, min_qty, timeout; unsigned int last_timeout = 0; + unsigned int max_busy_timeout = host->max_busy_timeout ? + host->max_busy_timeout : MMC_ERASE_TIMEOUT_MS; if (card->erase_shift) { max_qty = UINT_MAX >> card->erase_shift; @@ -2374,15 +2379,15 @@ static unsigned int mmc_do_calc_max_discard(struct mmc_card *card, * matter what size of 'host->max_busy_timeout', but if the * 'host->max_busy_timeout' is large enough for more discard sectors, * then we can continue to increase the max discard sectors until we - * get a balance value. + * get a balance value. In cases when the 'host->max_busy_timeout' + * isn't specified, use the default max erase timeout. */ do { y = 0; for (x = 1; x && x <= max_qty && max_qty - x >= qty; x <<= 1) { timeout = mmc_erase_timeout(card, arg, qty + x); - if (qty + x > min_qty && - timeout > host->max_busy_timeout) + if (qty + x > min_qty && timeout > max_busy_timeout) break; if (timeout < last_timeout) @@ -2427,9 +2432,6 @@ unsigned int mmc_calc_max_discard(struct mmc_card *card) struct mmc_host *host = card->host; unsigned int max_discard, max_trim; - if (!host->max_busy_timeout) - return UINT_MAX; - /* * Without erase_group_def set, MMC erase timeout depends on clock * frequence which can change. In that case, the best choice is @@ -2447,7 +2449,8 @@ unsigned int mmc_calc_max_discard(struct mmc_card *card) max_discard = 0; } pr_debug("%s: calculated max. discard sectors %u for timeout %u ms\n", - mmc_hostname(host), max_discard, host->max_busy_timeout); + mmc_hostname(host), max_discard, host->max_busy_timeout ? + host->max_busy_timeout : MMC_ERASE_TIMEOUT_MS); return max_discard; } EXPORT_SYMBOL(mmc_calc_max_discard);