From patchwork Fri Oct 5 18:32:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 189563 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (unknown [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 440C02C0079 for ; Sat, 6 Oct 2012 04:33:31 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TKCh8-0006Aq-Ud; Fri, 05 Oct 2012 18:32:19 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TKCh7-0006Al-92 for linux-mtd@merlin.infradead.org; Fri, 05 Oct 2012 18:32:17 +0000 Received: from quartz.orcorp.ca ([184.70.90.242]) by casper.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TKCh3-0001Dj-Qc for linux-mtd@lists.infradead.org; Fri, 05 Oct 2012 18:32:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=obsidianresearch.com; s=rsa1; h=Content-Type:MIME-Version:Message-ID:Subject:To:From:Date; bh=2ugRVdcR2UrpOdFAzgzqtuKZ8bZo7KnPsgUGUaLe0Jc=; b=Ht0X4NLDIFP6HpFUfxDcJ7SrsTxt4zGluOOv1764YOthGqK+OPMoDOpE/2dH0SrQlQ3vHH748x91UjWL+C5/eXhjzWMaqKMrRc9wlwnE9CRFT38b7mjtSbpbIcCnBKCIpbhXTl+doQxXO6VJxR2twSSYbIJo9d6v1mVFro6bljo=; Received: from [10.0.0.162] (helo=jggl.edm.orcorp.ca) by quartz.orcorp.ca with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1TKCgs-0006qi-W6; Fri, 05 Oct 2012 12:32:02 -0600 Received: from jgg by jggl.edm.orcorp.ca with local (Exim 4.76) (envelope-from ) id 1TKCgs-0002xv-Pr; Fri, 05 Oct 2012 12:32:02 -0600 Date: Fri, 5 Oct 2012 12:32:02 -0600 From: Jason Gunthorpe To: linux-mtd@lists.infradead.org, David Woodhouse Subject: [PATCH] [MTD] Adjust the NOR CFI flash timeouts to round better Message-ID: <20121005183202.GA11385@obsidianresearch.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Broken-Reverse-DNS: no host name found for IP address 10.0.0.162 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121005_193214_101715_F936BE8A X-CRM114-Status: GOOD ( 17.12 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.3.2 on casper.infradead.org summary: Content analysis details: (-2.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Using jiffies for timeout could have significant rounding, ie if we start at jiffie 1.9 and timeout at 2 then we may only get .1 jiffies of timeout, which is not nearly enough. With a Hz of 250 I've seen random bogus timeouts from this code. Add a +1 to the HZ calculations to ensure a guaranteed minimum timeout period. This also increases the write_buffer timeout to 1.5us since I have flashes in use that have a datasheet max of over 1 us. Signed-off-by: Jason Gunthorpe --- drivers/mtd/chips/cfi_cmdset_0002.c | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c index 22d0493..46a1dde 100644 --- a/drivers/mtd/chips/cfi_cmdset_0002.c +++ b/drivers/mtd/chips/cfi_cmdset_0002.c @@ -1150,10 +1150,10 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip, * use the maximum timeout value given by the chip at probe time * instead. Unfortunately, struct flchip does have a field for * maximum timeout, only for typical which can be far too short - * depending of the conditions. The ' + 1' is to avoid having a - * timeout of 0 jiffies if HZ is smaller than 1000. + * depending of the conditions. The ' + 2' is to ensure we get + * *at least* 1000us of timeout. */ - unsigned long uWriteTimeout = ( HZ / 1000 ) + 1; + unsigned long uWriteTimeout = (HZ / 1000) + 2; int ret = 0; map_word oldd; int retry_cnt = 0; @@ -1382,8 +1382,11 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, { struct cfi_private *cfi = map->fldrv_priv; unsigned long timeo = jiffies + HZ; - /* see comments in do_write_oneword() regarding uWriteTimeo. */ - unsigned long uWriteTimeout = ( HZ / 1000 ) + 1; + /* see comments in do_write_oneword() regarding uWriteTimeo. + Note: write_buffer commands take longer so we use a higher + time. The AMD 29LV256M for instance has a datasheet max + of 1.2ms for page and 600us for byte */ + unsigned long uWriteTimeout = (HZ / 1500) + 2; int ret = -EIO; unsigned long cmd_adr; int z, words;