From patchwork Mon Nov 5 14:00:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu CASTET X-Patchwork-Id: 197203 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [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 28FD72C0082 for ; Tue, 6 Nov 2012 01:20:11 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TVNVo-0000JS-PC; Mon, 05 Nov 2012 14:18:49 +0000 Received: from mail-bk0-f49.google.com ([209.85.214.49]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TVNEW-0005uZ-Rs for linux-mtd@lists.infradead.org; Mon, 05 Nov 2012 14:00:59 +0000 Received: by mail-bk0-f49.google.com with SMTP id j4so1941062bkw.36 for ; Mon, 05 Nov 2012 06:00:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=OcRvqMMHNThv2obnCskNdufhjJGDlO4JLeRyRPUTRF8=; b=iUUQp83o6Cws4ciD68kVrIXA8tgrD0yQAiMzSw1b+BEh6op4KrBstDVlrfIeBsmFy5 a2rk9sJvIqwTIrXp4fT/tX2Eq3VPJJ316ecyX9E5P1mTcg8ZtdITMaON1a/YJ+wm/2sG /YrmULnwu7/HiC/sjWhVO51qXXeWIsRfVlUWBT62e9mnS8LlqKc6e9YlLRcYAllRUOdU aHbmJhplUjoH/Oxa5YnENoGtjRoy+U0eAQgisEJV1y20OBh3dA8BHR+yG0M3JtLYoBMN sz55dFPz17/dcIzniObz1r1jYPSxyf3+LhLBDAH0sOXosUppVbaWIhqsAJCl2/v+GMbt P+Dw== Received: by 10.205.120.134 with SMTP id fy6mr2313101bkc.18.1352124053409; Mon, 05 Nov 2012 06:00:53 -0800 (PST) Received: from perruche.Parrot.Biz ([46.218.109.82]) by mx.google.com with ESMTPS id 1sm9800496bks.3.2012.11.05.06.00.51 (version=SSLv3 cipher=OTHER); Mon, 05 Nov 2012 06:00:52 -0800 (PST) From: Matthieu CASTET To: linux-mtd@lists.infradead.org Subject: [PATCH] nand_wait : warn if the nand is busy on exit Date: Mon, 5 Nov 2012 15:00:44 +0100 Message-Id: <1352124044-31627-1-git-send-email-matthieu.castet@parrot.com> X-Mailer: git-send-email 1.7.10.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121105_090058_229095_D92E1BDF X-CRM114-Status: GOOD ( 13.38 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.214.49 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (matthieu.castet[at]gmail.com) -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_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 Cc: Ivan Djelic , Matthieu CASTET , dedekind1@gmail.com 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: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This patch allow to detect buggy driver/hardware with bad RnB (dev_ready) management or when timeout occurs in polling mode. This works when dev_ready is set or not set. There are 2 methods to wait for an erase/program command completion: 1. Wait until nand RnB pin goes high (that's what chip->dev_ready usually does) 2. Poll the device: send a status (0x70) command and read status byte in a loop until bit NAND_STATUS_READY is set In all cases, you should send a status command after completion, to check if the operation was successful. And if the operation completed, the status should have bit NAND_STATUS_READY set. Signed-off-by: Matthieu CASTET CC: Ivan Djelic --- drivers/mtd/nand/nand_base.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index ee49fe2..5894c2c 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -865,6 +865,8 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip) led_trigger_event(nand_led_trigger, LED_OFF); status = (int)chip->read_byte(mtd); + /* This can happen if in case of timeout or buggy dev_ready */ + WARN_ON(!(status & NAND_STATUS_READY)); return status; }