From patchwork Tue Nov 1 17:05:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 690046 X-Patchwork-Delegate: cyrille.pitchen@atmel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3t7d3320nTz9t2T for ; Wed, 2 Nov 2016 04:07:57 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=IIwmR1ud; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c1cVt-0003Rz-58; Tue, 01 Nov 2016 17:06:17 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c1cVp-0003Fg-CA for linux-mtd@lists.infradead.org; Tue, 01 Nov 2016 17:06:14 +0000 Received: by mail-wm0-x242.google.com with SMTP id u144so4318156wmu.0 for ; Tue, 01 Nov 2016 10:05:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=KvK3nxshJKKB0XjRhdsc1I/foB03Pfo/UHglLWVcnpI=; b=IIwmR1udvLJATvgpCmnGJXBED4JbLuZZ6WwmQ23mkjCFsE821SOqdCsCpibBej3Oq6 QL1y0Fykb8pWpZsjqL936LLXL1QGuNr/2UPRfJpaXL37Lv3I9F7sDolOwlH9aQOaciwX Al1V+8btBiW5ZXV72mPxYZrwZ/Tzp68guAoWulsP2Lrl5/uuA7xUAy2/B9AIZja6v3Lj 38zDZoX8h6igJGziOBjrbNwmIsheF9yWiyxCX/61PsQCwXn46hALjg/GNtGNEfKY69x7 +wK5ZbPerAFN5PmOsEzlzMA5CkBOxHmZSGX03y2YYWNFWg5BKkLg5bhDwaEuWkHtOFVh dnxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=KvK3nxshJKKB0XjRhdsc1I/foB03Pfo/UHglLWVcnpI=; b=IPJNFCVc/4wAaJlNMXd5+jY7YDXMWiYoFKMZrqGuVj87ROZ/kgMFIMzIt3ebgP7P0u YuGXYWj4Pm2uJHxPp4FIDBzSpWAxmYABLBop/feG6LUIqtv9/3budQSSKv+nEvj/+TPx Aw1KLibDghYw+q/sNFnkGYMSQBoe7IlHuirbQw3usiWUQlP9th3RSkIs90ivN1oIAxK9 gdMWx1Vze3VHQnpFMUribPUc+1G6Sx+sbcy1pogVdcCbkVOb00LDn6M03ahZVCuJlvBf Lu5lLsQBdf3Bkyol7zuCNx2RyP8p6YSeYWHkOyX6ikUyLG60/surSoUzmv2deLENnmVe c56w== X-Gm-Message-State: ABUngvckasiWZLI9XbDAnGVEraAU/X80F2oM1x+1FD2xhsymoh8Qp/MRdHOf0lmGYupWqg== X-Received: by 10.28.48.203 with SMTP id w194mr2626310wmw.115.1478019950203; Tue, 01 Nov 2016 10:05:50 -0700 (PDT) Received: from ?IPv6:2003:62:5f43:4700:3c66:833f:e361:e84d? (p200300625F4347003C66833FE361E84D.dip0.t-ipconnect.de. [2003:62:5f43:4700:3c66:833f:e361:e84d]) by smtp.googlemail.com with ESMTPSA id 186sm31351136wmy.13.2016.11.01.10.05.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Nov 2016 10:05:49 -0700 (PDT) From: Heiner Kallweit Subject: [PATCH v2] mtd: spi-nor: add sleeping version of spi_nor_wait_till_ready for erase ops To: Cyrille Pitchen Message-ID: <3591c563-7a90-c060-f6f0-c61d35bbef0e@gmail.com> Date: Tue, 1 Nov 2016 18:05:36 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161101_100613_630081_200AFD6A X-CRM114-Status: GOOD ( 11.79 ) X-Spam-Score: -1.8 (-) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-1.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (hkallweit1[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (hkallweit1[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marek Vasut , Brian Norris , MTD Maling List Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Currently spi_nor_wait_till_ready in the poll loop permanently checks for the WIP flag to be reset. Erase ops typically take >100ms for sector erase and >10s for chip erase. Permanently polling for such longer time periods puts unnecessary load on the SPI subsystem (especially on systems w/o SPI DMA support or systems using bitbanging). Relax this by sleeping for a reasonable time between checking the WIP flag. Signed-off-by: Heiner Kallweit --- v2: - add defines for numeric constants - Don't introduce a third spi_nor_wait_till_ready_.. function. - add sanity check to ensure that sleep time <= timeout --- drivers/mtd/spi-nor/spi-nor.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index d0fc165..7c793a6 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -37,6 +38,10 @@ */ #define CHIP_ERASE_2MB_READY_WAIT_JIFFIES (40UL * HZ) +#define READY_WAIT_NO_SLEEP 0 +#define SECTOR_ERASE_READY_WAIT_SLEEP_MSECS 2 +#define CHIP_ERASE_READY_WAIT_SLEEP_MSECS 100 + #define SPI_NOR_MAX_ID_LEN 6 #define SPI_NOR_MAX_ADDR_WIDTH 4 @@ -252,11 +257,13 @@ static int spi_nor_ready(struct spi_nor *nor) * Returns non-zero if error. */ static int spi_nor_wait_till_ready_with_timeout(struct spi_nor *nor, - unsigned long timeout_jiffies) + unsigned long timeout_jiffies, + unsigned int sleep_msecs) { unsigned long deadline; int timeout = 0, ret; + sleep_msecs = min(sleep_msecs, jiffies_to_msecs(timeout_jiffies)); deadline = jiffies + timeout_jiffies; while (!timeout) { @@ -269,7 +276,13 @@ static int spi_nor_wait_till_ready_with_timeout(struct spi_nor *nor, if (ret) return 0; - cond_resched(); + if (!sleep_msecs) + cond_resched(); + else if (sleep_msecs < 50) + usleep_range(sleep_msecs * 1000 - 100, + sleep_msecs * 1000); + else + msleep(sleep_msecs); } dev_err(nor->dev, "flash operation timed out\n"); @@ -280,7 +293,8 @@ static int spi_nor_wait_till_ready_with_timeout(struct spi_nor *nor, static int spi_nor_wait_till_ready(struct spi_nor *nor) { return spi_nor_wait_till_ready_with_timeout(nor, - DEFAULT_READY_WAIT_JIFFIES); + DEFAULT_READY_WAIT_JIFFIES, + READY_WAIT_NO_SLEEP); } /* @@ -387,7 +401,8 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) timeout = max(CHIP_ERASE_2MB_READY_WAIT_JIFFIES, CHIP_ERASE_2MB_READY_WAIT_JIFFIES * (unsigned long)(mtd->size / SZ_2M)); - ret = spi_nor_wait_till_ready_with_timeout(nor, timeout); + ret = spi_nor_wait_till_ready_with_timeout(nor, timeout, + CHIP_ERASE_READY_WAIT_SLEEP_MSECS); if (ret) goto erase_err; @@ -408,7 +423,9 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) addr += mtd->erasesize; len -= mtd->erasesize; - ret = spi_nor_wait_till_ready(nor); + ret = spi_nor_wait_till_ready_with_timeout(nor, + DEFAULT_READY_WAIT_JIFFIES, + SECTOR_ERASE_READY_WAIT_SLEEP_MSECS); if (ret) goto erase_err; }