Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp5854911ybn; Sun, 29 Sep 2019 07:08:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqywvN3aq6QhAP8VCJRZ+yWk6rydj3Z6fPCLoasGRKKi4ZRO4Cy672jdl0Ql38ubYsYaY3m/ X-Received: by 2002:a50:a8c5:: with SMTP id k63mr14825105edc.122.1569766096348; Sun, 29 Sep 2019 07:08:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569766096; cv=none; d=google.com; s=arc-20160816; b=zWRIuk+QVeZJRQY3+Cn+Fk8CRcGpfszt9C2cJdYM7ryPNGc7NYtgXJZuMArU9baZXi 5spgEnQ3s8cjSitUNB1TAkQBZqqQ1ko/Z0I7KPJuQOu/RKDjqgBRwmIwlqhV8QcclaRS uMB7JqzkkjnA2OuC7/S7u8tMdhjXeC2jvP59dqmXGCqcEb4OKgWlRNH6/x1suXUaFG6V YbFOmOL77D+zGApOHQ6BodwD6A8As4L+2u3TCq/0932u1qg/3Q07ci0/Um3FbEdriS3Q DZTYuM/xb1C4dB3XNQcIm++EzlwlhDmLPweZh93FQTSqrsnqyw0fx5pKQHLVTk0epOWe 2+3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ug7GScRuRbqNwhtg2yyCloNYkiIfTegZvv7Xu2HDZCE=; b=xGkp2XLX/uqXk8lO8uRxxGPogTFcXRaMC1kbBNZ1cJhlAglnDS59hMpzuWYuKQo/61 Z09MlrLjAYN9sZ9F9V8RynisWtQ6hdPVepUkSp4V6I7XiKBZfjcsWXdy94ZneBrqteAN Nu8EG5qBY4QQLVc5eH5t4jJT/mTBU8OysL3wGGQeImubKbVepOb6aBn3+7+OjkN+iPAA YiwgoPpWutUgj6zz4V0mX65dkzFgdDXbaEMpC64LJvJR3pZHoSsVdxw2OhSPgZq1ljeY ARq1iuLsItv6TjVZkfcVhv9giKl8wij+DugEP84M8xgg48MXtmpkw83U2Lzt/IARZvd/ tQhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pAXo27Sa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i9si5405249ejy.106.2019.09.29.07.07.51; Sun, 29 Sep 2019 07:08:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pAXo27Sa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730173AbfI2OCP (ORCPT + 99 others); Sun, 29 Sep 2019 10:02:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:44622 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730144AbfI2OCJ (ORCPT ); Sun, 29 Sep 2019 10:02:09 -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 A5FE72082F; Sun, 29 Sep 2019 14:02:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569765728; bh=FGP+XNu2Ib1vWj/+5kSrQEzlaKrwsEKHcAsPA1D78Go=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pAXo27SazifWiS7+qcBWpNflYcdSsLJrC4q/MkobEkZVjXB1072doEukoF80pIaC7 zswUrLnhmVKuNxr+UnWWtCM+sC+229Ecdtq4BqxgT2EQrHEkwKaLrIQStYuzMaQ9sG NeykgY4DGNlV34QdWVh6aL21PDifPtVI6oVd1HAs= 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.2 18/45] mtd: cfi_cmdset_0002: Use chip_good() to retry in do_write_oneword() Date: Sun, 29 Sep 2019 15:55:46 +0200 Message-Id: <20190929135030.092855722@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190929135024.387033930@linuxfoundation.org> References: <20190929135024.387033930@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 @@ -1628,29 +1628,35 @@ static int __xipram do_write_oneword(str continue; } - if (time_after(jiffies, timeo) && !chip_ready(map, adr)){ + /* + * We check "time_after" and "!chip_good" before checking + * "chip_good" to avoid the failure due to scheduling. + */ + if (time_after(jiffies, timeo) && !chip_good(map, 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, adr)) + if (chip_good(map, 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, 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: