From patchwork Thu Oct 25 16:32:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: IKEGAMI Tokunori X-Patchwork-Id: 989210 X-Patchwork-Delegate: boris.brezillon@free-electrons.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=allied-telesis.co.jp Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="dKQNLwMM"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42gt3M1w3Rz9sB5 for ; Fri, 26 Oct 2018 03:33:13 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=PH23jIhkcWdg+/fwna2r5SOEOh6Rx6gVN8k+o+H+980=; b=dKQNLwMMup5lXDg4VnVi3UAc62 DapBLOxUkwlHv5UWGtihSM2VvZ28BR33UaQ6Eg3TRS70QpMIh2TNjEYYebhvLAEfwLvHeu3X6GFxz Jp1w8qsnvwwgeDffndphrTKZ8APilhPomFbMnTEhefhGxb/PVfuHrdiD9A2v1vB2hd6sRbymmrNkd /azhDOjUmjmYqn1Hz3jSzRNXyP5t0ruKHElYoT8o4kHr2a7ywgWyi3DZp+AehLfpigv87Mm9nX7Zj ak7H2bMwCvaFN9Hl3BgbtJ1u7cXkk12O+GxmpNtHddhxhwHXF73saedu+OLdOKuGjN+GlFaL9MF35 XcnWuubA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gFiZ5-0004l2-4j; Thu, 25 Oct 2018 16:32:55 +0000 Received: from mail1.bemta23.messagelabs.com ([67.219.246.3]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gFiZ0-0004jJ-Jk for linux-mtd@lists.infradead.org; Thu, 25 Oct 2018 16:32:53 +0000 Received: from [67.219.246.100] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-3.bemta.az-b.us-east-1.aws.symcld.net id 55/6B-08438-620F1DB5; Thu, 25 Oct 2018 16:32:38 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsUyLfyHiK7ah4v RBuu3qVnsblrG7sDosXlJfQBjFGtmXlJ+RQJrxublM1gLfkpVfP1/j62B8YNYFyMXh5DAXEaJ wzs3sEA4vxglll66wNbFyMnBJmAqMf3VQkYQW0RATWJr/zlGkCJmgbNMEpMnbgXq4OAQFoiRW N3ABmKyCKhKHH4qClLOK+Ao8fH9D7AxEgLyEg+Pt4ON4RRwkuj4/4QZxBYCqvnb2wJla0o87/ nOCFEfLNH/eznTBEbeBYwMqxjNkooy0zNKchMzc3QNDQx0DQ2NdI2BLCO9xCrdJL3SYt3UxOI SXUO9xPJiveLK3OScFL281JJNjMBASSlgTtvBeLU9/RCjJAeTkihvYsrFaCG+pPyUyozE4oz4 otKc1OJDjDIcHEoSvLzvgXKCRanpqRVpmTnAkIVJS3DwKInwzn8HlOYtLkjMLc5Mh0idYlSUE ue9ApIQAElklObBtcHi5BKjrJQwLyMDA4MQT0FqUW5mCar8K0ZxDkYlYd4YkO08mXklcNNfAS 1mAlo8Q+ECyOKSRISUVAOjUE7sd8PGIwEJ5laFsXKnpEuf6xvpLzzfsi1hsk1BZnqPsc/2H4u 0na0M5HYr+zNML3csuHLhjbOs1mxlXYtpjIbGvH9uci623B3SleK80+SeXn5+qvc1nxfs1xIf qa4/IM/uXrfUmvlZ4YOHX5U9HY8t26n8fXNG5pEyhcS5Dm9iLVZH6iuxFGckGmoxFxUnAgAbe 54TjgIAAA== X-Env-Sender: ikegami@allied-telesis.co.jp X-Msg-Ref: server-26.tower-384.messagelabs.com!1540485156!931210!2 X-Originating-IP: [150.87.248.20] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.14.24; banners=-,-,- X-VirusChecked: Checked Received: (qmail 4869 invoked from network); 25 Oct 2018 16:32:38 -0000 Received: from abricot-inet.allied-telesis.co.jp (HELO TKY-DS01.at.lc) (150.87.248.20) by server-26.tower-384.messagelabs.com with SMTP; 25 Oct 2018 16:32:38 -0000 Received: from swim-manx.rd.allied-telesis.co.jp ([150.87.21.50]) by TKY-DS01.at.lc with Microsoft SMTPSVC(8.0.9200.16384); Fri, 26 Oct 2018 01:32:36 +0900 Received: from ikegami-pc.rd.allied-telesis.co.jp by swim-manx.rd.allied-telesis.co.jp (AlliedTelesis SMTPRS 1.3 pl 1 ++E6B86F8C687C6288D9B5559052954DC9) with ESMTP id ; Fri, 26 Oct 2018 01:32:35 +0900 From: Tokunori Ikegami To: boris.brezillon@free-electrons.com Subject: [PATCH v3 01/11] mtd: cfi_cmdset_0002: Change do_write_oneword() to use chip_good() Date: Fri, 26 Oct 2018 01:32:09 +0900 Message-Id: <20181025163219.25788-2-ikegami@allied-telesis.co.jp> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181025163219.25788-1-ikegami@allied-telesis.co.jp> References: <20181025163219.25788-1-ikegami@allied-telesis.co.jp> X-OriginalArrivalTime: 25 Oct 2018 16:32:36.0329 (UTC) FILETIME=[567DDD90:01D46C80] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181025_093250_739643_1814F936 X-CRM114-Status: GOOD ( 18.41 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [67.219.246.3 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [67.219.246.3 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tokunori Ikegami , Hauke Mehrtens , stable@vger.kernel.org, Joakim Tjernlund , Chris Packham , linux-mtd@lists.infradead.org, Koen Vandeputte , Fabio Bettoni MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org In OpenWrt Project the flash write error caused on some products. Also the issue can be fixed by using chip_good() instead of chip_ready(). The chip_ready() just checks the value from flash memory twice. And the chip_good() checks the value with the expected value. Probably the issue can be fixed as checked correctly by the chip_good(). So change to use chip_good() instead of chip_ready(). Signed-off-by: Tokunori Ikegami Signed-off-by: Hauke Mehrtens Signed-off-by: Koen Vandeputte Signed-off-by: Fabio Bettoni Co-Developed-by: Hauke Mehrtens Co-Developed-by: Koen Vandeputte Co-Developed-by: Fabio Bettoni Reported-by: Fabio Bettoni Cc: Chris Packham Cc: Joakim Tjernlund Cc: Boris Brezillon Cc: linux-mtd@lists.infradead.org Cc: stable@vger.kernel.org --- Changes since v2: - Just update the commit message for the comment. Changes since v1: - Just update the commit message. Background: This is required for OpenWrt Project to result the flash write issue as below patche. Also the original patch in OpenWRT is below. The reason to use chip_good() is that just actually fix the issue. And also in the past I had fixed the erase function also as same way by the patch below. Note: The reason for the patch for erase is same. In my understanding the chip_ready() is just checked the value twice from flash. So I think that sometimes incorrect value is read twice and it is depended on the flash device behavior but not sure.. So change to use chip_good() instead of chip_ready(). drivers/mtd/chips/cfi_cmdset_0002.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c index 72428b6bfc47..251c9e1675bd 100644 --- a/drivers/mtd/chips/cfi_cmdset_0002.c +++ b/drivers/mtd/chips/cfi_cmdset_0002.c @@ -1627,31 +1627,37 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip, continue; } - if (time_after(jiffies, timeo) && !chip_ready(map, adr)){ + if (chip_good(map, adr, datum)) + break; + + if (time_after(jiffies, timeo)){ xip_enable(map, chip, adr); printk(KERN_WARNING "MTD %s(): software timeout\n", __func__); xip_disable(map, chip, adr); + ret = -EIO; break; } - if (chip_ready(map, adr)) - break; - /* Latency issues. Drop the lock, wait a while and retry */ UDELAY(map, chip, adr, 1); } + /* Did we succeed? */ - if (!chip_good(map, adr, datum)) { + if (ret) { /* reset on all failures. */ map_write(map, CMD(0xF0), chip->start); /* FIXME - should have reset delay before continuing */ - if (++retry_cnt <= MAX_RETRIES) + if (++retry_cnt <= MAX_RETRIES) { + ret = 0; goto retry; + } ret = -EIO; } + xip_enable(map, chip, adr); + op_done: if (mode == FL_OTP_WRITE) otp_exit(map, chip, adr, map_bankwidth(map));