From patchwork Wed Jul 16 18:04:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 370823 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-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D253F140081 for ; Thu, 17 Jul 2014 04:06:05 +1000 (EST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1X7TZS-0003z0-T7; Wed, 16 Jul 2014 18:04:50 +0000 Received: from mail-ig0-x235.google.com ([2607:f8b0:4001:c05::235]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X7TZR-0003vR-4v for linux-mtd@lists.infradead.org; Wed, 16 Jul 2014 18:04:49 +0000 Received: by mail-ig0-f181.google.com with SMTP id h3so1151406igd.8 for ; Wed, 16 Jul 2014 11:04:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=/xzwBCA9fkjJdUh6X4w3xSfhwGpl37C998hxLqFTfLI=; b=IIneX+AgMXMLglQpi1W/P1vaVpaGmjxuYNAqFpRjCcDVWUp1pGoOUY4wkD68SyBJLC uc3ykMPIGFpqlfGcXdfl9jQIcMj8b89P21ePF1WorhELnwWlRRD3Mu/3hDhu1+LW3vBv KgdrRgUMBq9/k0/B81SYyieR5LOnS1y2WvkYS4yvhCL4bOXxTPhPI5JVQRq6jnaRiTj9 4o546077G+hqQ8sSSz65SJm1bWCBnvP1ma3aZ4FEDC57KuUrTtVys1EEsQVd2lGXl8N+ kUGlqp44Cwn42aGnis6z6cllqZqZ5EwhbMzJ3y0t9b2zqkOSB0U9mVQr9CPrmNNfZEuM fAJQ== X-Received: by 10.50.142.97 with SMTP id rv1mr18957537igb.13.1405533867445; Wed, 16 Jul 2014 11:04:27 -0700 (PDT) Received: from ld-irv-0074 (5520-maca-inet1-outside.broadcom.com. [216.31.211.11]) by mx.google.com with ESMTPSA id n10sm46731132igv.21.2014.07.16.11.04.25 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 16 Jul 2014 11:04:26 -0700 (PDT) Date: Wed, 16 Jul 2014 11:04:23 -0700 From: Brian Norris To: Bean Huo Subject: Re: [PATCH v6] mtd:nor:timeout:fix do_write_buffer() timeout error Message-ID: <20140716180423.GV7537@ld-irv-0074> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140716_110449_276034_3523AF96 X-CRM114-Status: GOOD ( 26.31 ) X-Spam-Score: -0.1 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (computersforpeace[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 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 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain Cc: Paul Gortmaker , Artem Bityutskiy , Jingoo Han , linux-kernel@vger.kernel.org, christian.riesch@omicron.at, Huang Shijie , linux-mtd@lists.infradead.org, David Woodhouse X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Hi Bean, On Wed, Jul 16, 2014 at 09:05:26AM -0700, Bean Huo wrote: > From: bean huo > > For some Norflashes,the size of the buffer program has been > increased from 256 bytes to 512 bytes,2ms maximum timeout can > not adapt to all the different vendor's norflash.There maximum > timeout information in the CFI area,so the best way is to choose > the result calculated according to timeout field of struct cfi_ident > that probed from norflash's CFI aera.This is also a standard defined > by CFI.If haven't probed this information,or smaller than 2000us,then > specify a defualt value 2000us. > > Tested with Micron JS28F512M29EWx and Micron MT28EW512ABA flash devices. > > Signed-off-by: bean huo > --- > v1->v2:Deleted unused parameters in this patch(word_write_time_max and erase_time_max). > Using usecs_to_jiffies instead of msecs_to_jiffies for convert timeout value into jiffies. > v2->v3:Removed unnecessary messages form comments and deleted trailing whitespace. > V3->v4:If haven't probed timeout information,or smaller than 2000us,specify default 2000us. > v4->v5:Add space before '>=' > v5->v6:Add the same indentation as 'if' at the front of 'else' > > drivers/mtd/chips/cfi_cmdset_0002.c | 29 +++++++++++++++++++++++++++-- > 1 file changed, 27 insertions(+), 2 deletions(-) > > diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c > index e21fde9..aed6f9e 100644 > --- a/drivers/mtd/chips/cfi_cmdset_0002.c > +++ b/drivers/mtd/chips/cfi_cmdset_0002.c > @@ -628,6 +628,25 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary) [...] > + cfi->chips[i].buffer_write_time_max = > + ((cfi->chips[i].buffer_write_time_max >= 2000) > + ? cfi->chips[i].buffer_write_time_max : 2000); This should just use the 'max()' macro, from . > + > cfi->chips[i].ref_point_counter = 0; > init_waitqueue_head(&(cfi->chips[i].wq)); > } I have just fixed up your patch myself, to use max() and to improve some of the language. Let me know if the below works for you. From 6534e6809e6c9d48114b537afe03bee3fd33bf01 Mon Sep 17 00:00:00 2001 From: Bean Huo Date: Wed, 16 Jul 2014 09:05:26 -0700 Subject: [PATCH] mtd: cfi_cmdset_0002: fix do_write_buffer() timeout error For some NOR flashes, the size of the buffer program has been increased from 256 bytes to 512 bytes, and so 2ms maximum timeout can may not be sufficient for all different vendor's NOR flash. There is maximum timeout information in the CFI area, so we instead of picking a fixed value, we can calculate this according to the standard CFI parameters parsed at probe time. If we haven't probed this information, or it is smaller than 2000us, then specify a minimum value 2000us. Tested with Micron JS28F512M29EWx and Micron MT28EW512ABA flash devices. Signed-off-by: Bean Huo [Brian: fix up comments, use 'max()'] Signed-off-by: Brian Norris Tested-by: Pekon Gupta --- drivers/mtd/chips/cfi_cmdset_0002.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c index bf313be6ee26..5a4bfe33112a 100644 --- a/drivers/mtd/chips/cfi_cmdset_0002.c +++ b/drivers/mtd/chips/cfi_cmdset_0002.c @@ -645,6 +645,23 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary) cfi->chips[i].word_write_time = 1<cfiq->WordWriteTimeoutTyp; cfi->chips[i].buffer_write_time = 1<cfiq->BufWriteTimeoutTyp; cfi->chips[i].erase_time = 1<cfiq->BlockEraseTimeoutTyp; + /* + * First calculate the timeout max according to timeout field + * of struct cfi_ident that probed from chip's CFI aera, if + * available. Specify a minimum of 2000us, in case the CFI data + * is wrong. + */ + if (cfi->cfiq->BufWriteTimeoutTyp && + cfi->cfiq->BufWriteTimeoutMax) + cfi->chips[i].buffer_write_time_max = + 1 << (cfi->cfiq->BufWriteTimeoutTyp + + cfi->cfiq->BufWriteTimeoutMax); + else + cfi->chips[i].buffer_write_time_max = 0; + + cfi->chips[i].buffer_write_time_max = + max(cfi->chips[i].buffer_write_time_max, 2000); + cfi->chips[i].ref_point_counter = 0; init_waitqueue_head(&(cfi->chips[i].wq)); } @@ -1774,8 +1791,12 @@ 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; + /* + * Timeout is calculated according to CFI data, if available. + * See more comments in cfi_cmdset_0002(). + */ + unsigned long uWriteTimeout = + usecs_to_jiffies(chip->buffer_write_time_max); int ret = -EIO; unsigned long cmd_adr; int z, words;