Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp573931ybn; Thu, 3 Oct 2019 09:03:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqxPo2MHPzerWPEV3kdfxyeD146BEw4Wb4ngH6uPXFUa605sqzfsGXzRn4edVB08QkfHm+RP X-Received: by 2002:adf:9dd1:: with SMTP id q17mr7810757wre.176.1570118630028; Thu, 03 Oct 2019 09:03:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570118630; cv=none; d=google.com; s=arc-20160816; b=p7fzYW5P54zhni+N5IP8ZOY3TAT9fcFYxE4frwXycXSJ8IKMaXyXAXIQXtRc101OfJ dFwR9pBq5HCkDlBbeX1ZoTRw9Gx0ZNlPCb8acy3wMaJFD8eCULecCJtCkQT71/bKdErC h2Ch/EwO4bO0kD9pfKggIOypxUPgmRAMAazdDoDr1Yj7jzKuZdDlLMKslpDF9CnTbnC/ 31nP6atyuXuAjKLHSgvV1J2EG7HTVIEyU8+hR08AkM99lHD81WvZtwHqHztUr7x3ZiJL r7+WipYT3XuWlyhuSEiR28bxwC4kzLUkjoic3rg7+SETyWVZaVVB32rn/WSEpXAVnuTI 9L9w== 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=92/JuNsdTo+eiCpilINceHPH9zhLMJI1d8kBi8AORMk=; b=i51gLjVNkqPtF06fbnA2H4KsjN4BiVI8OgyJad6ZN3xEPmjo+PebMBFIHnvuptUMZd gku3aAKZ9AcRJslN2R0a/JXAIwyVoIEKZh0g6TTRtiEJsJwB7U316c/mYroG05ICq85z B+w4rHOdFFt7XbwdlwV5zFQ/v4z4d+/ehw7kbUG3PfyXeUofBJCGsussiu1N4okQD7B4 nJykENhkxFuTNqSZP1y3wAr8Yz9pzRzYDUodiqOC9ehsg1toH65L9Az6sJrKLHZ4IHXp 4TzDUD76N5bVGhW9II2L+O+1ArVHc2DZ49qG9eQlVI74vcSJhKUhvP37nz0L6Ye/hXNq q6gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ID7ZgIkJ; 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 k17si1492618ejz.227.2019.10.03.09.03.24; Thu, 03 Oct 2019 09:03:50 -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=ID7ZgIkJ; 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 S1730988AbfJCP5f (ORCPT + 99 others); Thu, 3 Oct 2019 11:57:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:40012 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730968AbfJCP5c (ORCPT ); Thu, 3 Oct 2019 11:57:32 -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 851B3207FF; Thu, 3 Oct 2019 15:57:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570118252; bh=+yVYbzi6NorjDufJSabcULv4qzLtVu0G7LVMv+Bk8DQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ID7ZgIkJqZEk6pVsnHKPf6XqkGHCzVpZR1sC3YkNLRfHCyLKGEhOAy2icUjAE7W2p y1UAKhVUAZ45cMIccyEJ08eqajlYpPnWa/pzy9LPxg4gE5+QzAgx6t73VEvTUp9UPv l1MX5VT/0klXgUhcE+Rwc6MqANabw1n0BEwCgXWE= 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 4.4 06/99] mtd: cfi_cmdset_0002: Use chip_good() to retry in do_write_oneword() Date: Thu, 3 Oct 2019 17:52:29 +0200 Message-Id: <20191003154255.205877418@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154252.297991283@linuxfoundation.org> References: <20191003154252.297991283@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 @@ -1626,29 +1626,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: