From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC3EFC4360C for ; Sun, 29 Sep 2019 14:03:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7F90821882 for ; Sun, 29 Sep 2019 14:03:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569765797; bh=4RpIUmaAfy9boE6eBfawdS14OQeP2tuTyRAyuCbuMkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=mX32b8Qi5Izc0rW7Dcmtwek32j6YT9eIDrVjVwzVMnB5gF2bu8LZPn8ZynP7PqfJg 60RyoGwOGlJDvtTNcNUIc62mMWHclceUQaARNwYFX/jIx0F8MAUVGk4tMB7u9iA+9g ZRasi4lyF1rVATyY3qIkON7dADI7AuIlVk/Z+3zQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730321AbfI2ODQ (ORCPT ); Sun, 29 Sep 2019 10:03:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:46200 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729223AbfI2ODO (ORCPT ); Sun, 29 Sep 2019 10:03:14 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C3FAE21835; Sun, 29 Sep 2019 14:03:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569765793; bh=4RpIUmaAfy9boE6eBfawdS14OQeP2tuTyRAyuCbuMkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oISv7dhA+GHrNBq88NKCfHvIYTh6AwXZNjb2+1ch92xQExbIbpIN6vQqKuVOFdv3J BGhQPQz9n5YyOXmzA2mWT5edllV6N0b641Llev9L6LBwY9rb2fsAj8VjNGHdkV6OGP ffVCYPmcmks7Rrv80pGG7JzAfqBPqeQuxDtunkEg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chris Packham , Joakim Tjernlund , linux-mtd@lists.infradead.org, Fabio Bettoni , Felix Fietkau , Hauke Mehrtens , Tokunori Ikegami , Vignesh Raghavendra Subject: [PATCH 5.3 15/25] mtd: cfi_cmdset_0002: Use chip_good() to retry in do_write_oneword() Date: Sun, 29 Sep 2019 15:56:18 +0200 Message-Id: <20190929135015.235296003@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190929135006.127269625@linuxfoundation.org> References: <20190929135006.127269625@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tokunori Ikegami commit 37c673ade35c707d50583b5b25091ff8ebdeafd7 upstream. As reported by the OpenWRT team, write requests sometimes fail on some platforms. Currently to check the state chip_ready() is used correctly as described by the flash memory S29GL256P11TFI01 datasheet. Also chip_good() is used to check if the write is succeeded and it was implemented by the commit fb4a90bfcd6d8 ("[MTD] CFI-0002 - Improve error checking"). But actually the write failure is caused on some platforms and also it can be fixed by using chip_good() to check the state and retry instead. Also it seems that it is caused after repeated about 1,000 times to retry the write one word with the reset command. By using chip_good() to check the state to be done it can be reduced the retry with reset. It is depended on the actual flash chip behavior so the root cause is unknown. Cc: Chris Packham Cc: Joakim Tjernlund Cc: linux-mtd@lists.infradead.org Cc: stable@vger.kernel.org Reported-by: Fabio Bettoni Signed-off-by: Felix Fietkau Signed-off-by: Hauke Mehrtens Signed-off-by: Tokunori Ikegami [vigneshr@ti.com: Fix a checkpatch warning] Signed-off-by: Vignesh Raghavendra Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/chips/cfi_cmdset_0002.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) --- a/drivers/mtd/chips/cfi_cmdset_0002.c +++ b/drivers/mtd/chips/cfi_cmdset_0002.c @@ -1717,31 +1717,37 @@ static int __xipram do_write_oneword(str continue; } + /* + * We check "time_after" and "!chip_good" before checking + * "chip_good" to avoid the failure due to scheduling. + */ if (time_after(jiffies, timeo) && - !chip_ready(map, chip, adr)) { + !chip_good(map, chip, adr, datum)) { 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, chip, adr)) + if (chip_good(map, chip, adr, datum)) break; /* Latency issues. Drop the lock, wait a while and retry */ UDELAY(map, chip, adr, 1); } + /* Did we succeed? */ - if (!chip_good(map, chip, adr, datum)) { + if (ret) { /* reset on all failures. */ cfi_check_err_status(map, chip, adr); 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: From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C8E0C32793 for ; Sun, 29 Sep 2019 14:03:19 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0C52B21835 for ; Sun, 29 Sep 2019 14:03:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="VmUlAl6i"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="oISv7dhA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C52B21835 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=2lkA9vBlyL2N6VQfh4SXgeBKCaETIDQt0kS7Bo9wt1c=; b=VmUlAl6izNcbdG 3fRXYzIqN9EPuK9Gm+UCmlsAwJ2UowJCX4YnlFwZu/H5Ut7hP2wfCXwgjGru84zTyHLRg5sJ//U7D KMrllzQla9AaNpP1tRNVPYxQTrGqf+ja59expCY+z99fMI43Y80S9uJjKP7h1v81eXOzDKAYqEHVD yeAF4F2itDQuXrXs1ZDPluCPNAi65SF3o35qgAjcvg3PsEnVwckPbPfqL3rewn/Thl273P66pUMr3 dD7ELRuoW8ZfW4zSuFpnBD/DOeM4QQ+FJ9lEACyKclH1cpdgdKv7Enl5qiDtYPwBZg/ai0d3GuoCC KzSbbyKsxxOc4N3hrzvg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iEZnB-0007Dy-EG; Sun, 29 Sep 2019 14:03:17 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iEZn7-0007DH-UB for linux-mtd@lists.infradead.org; Sun, 29 Sep 2019 14:03:15 +0000 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C3FAE21835; Sun, 29 Sep 2019 14:03:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569765793; bh=4RpIUmaAfy9boE6eBfawdS14OQeP2tuTyRAyuCbuMkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oISv7dhA+GHrNBq88NKCfHvIYTh6AwXZNjb2+1ch92xQExbIbpIN6vQqKuVOFdv3J BGhQPQz9n5YyOXmzA2mWT5edllV6N0b641Llev9L6LBwY9rb2fsAj8VjNGHdkV6OGP ffVCYPmcmks7Rrv80pGG7JzAfqBPqeQuxDtunkEg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Subject: [PATCH 5.3 15/25] mtd: cfi_cmdset_0002: Use chip_good() to retry in do_write_oneword() Date: Sun, 29 Sep 2019 15:56:18 +0200 Message-Id: <20190929135015.235296003@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190929135006.127269625@linuxfoundation.org> References: <20190929135006.127269625@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190929_070314_016237_1BD0256C X-CRM114-Status: GOOD ( 15.00 ) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tokunori Ikegami , Vignesh Raghavendra , Greg Kroah-Hartman , stable@vger.kernel.org, Joakim Tjernlund , Chris Packham , linux-mtd@lists.infradead.org, Hauke Mehrtens , Fabio Bettoni , Felix Fietkau Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-mtd" Errors-To: linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org From: Tokunori Ikegami commit 37c673ade35c707d50583b5b25091ff8ebdeafd7 upstream. As reported by the OpenWRT team, write requests sometimes fail on some platforms. Currently to check the state chip_ready() is used correctly as described by the flash memory S29GL256P11TFI01 datasheet. Also chip_good() is used to check if the write is succeeded and it was implemented by the commit fb4a90bfcd6d8 ("[MTD] CFI-0002 - Improve error checking"). But actually the write failure is caused on some platforms and also it can be fixed by using chip_good() to check the state and retry instead. Also it seems that it is caused after repeated about 1,000 times to retry the write one word with the reset command. By using chip_good() to check the state to be done it can be reduced the retry with reset. It is depended on the actual flash chip behavior so the root cause is unknown. Cc: Chris Packham Cc: Joakim Tjernlund Cc: linux-mtd@lists.infradead.org Cc: stable@vger.kernel.org Reported-by: Fabio Bettoni Signed-off-by: Felix Fietkau Signed-off-by: Hauke Mehrtens Signed-off-by: Tokunori Ikegami [vigneshr@ti.com: Fix a checkpatch warning] Signed-off-by: Vignesh Raghavendra Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/chips/cfi_cmdset_0002.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) --- a/drivers/mtd/chips/cfi_cmdset_0002.c +++ b/drivers/mtd/chips/cfi_cmdset_0002.c @@ -1717,31 +1717,37 @@ static int __xipram do_write_oneword(str continue; } + /* + * We check "time_after" and "!chip_good" before checking + * "chip_good" to avoid the failure due to scheduling. + */ if (time_after(jiffies, timeo) && - !chip_ready(map, chip, adr)) { + !chip_good(map, chip, adr, datum)) { 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, chip, adr)) + if (chip_good(map, chip, adr, datum)) break; /* Latency issues. Drop the lock, wait a while and retry */ UDELAY(map, chip, adr, 1); } + /* Did we succeed? */ - if (!chip_good(map, chip, adr, datum)) { + if (ret) { /* reset on all failures. */ cfi_check_err_status(map, chip, adr); 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: ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/