Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp616370iog; Mon, 13 Jun 2022 09:13:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhBu6uTIpyFSaAUsXl7oBWh9TSoiwZgQoLB/JDjSg1ZjmmKtdCBn5XqIP4O4DjOqZLZRZ7 X-Received: by 2002:aa7:c84d:0:b0:431:4226:70c9 with SMTP id g13-20020aa7c84d000000b00431422670c9mr521677edt.51.1655136780098; Mon, 13 Jun 2022 09:13:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655136780; cv=none; d=google.com; s=arc-20160816; b=YhNoCOje2p5VKQTt1Wp6a4AYqZ9mfdwI6TOqYZW2IQAaTMBTMXt/AtCMQ71sBzMV6n 0yEqaeK5rkWUuDSN533iai120F8+F5v76nASAFc3KGiLM0YboyksTwy32nqkTQZzX7Dz 2vkRfErgh1Z9mb0CFKMJiyHcg9syu6vGaGJAFr7HNVaNk5xhOnElJzOBnUKtOqQUpbnv cQz8QE4JvZ3Uqk7PX0uLTI37KHIafH7EbwSi7/U7yWtiVhFyWTI9IkRkfxuhlcKmdNhy /HOONFZgt7QREy5KZcNpoB8u5pJmvJ3y1NtJoeMfbNDWXnxGNuQ5DxmbmJvU+hf1eI0J HiOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mx2O5GZcgXmI2/Zu9qmapX+tLC0XdHVbNXkSjuyRqc0=; b=Ep1dMva+TZr6S323lIy/WaNR/ouoTa5Y+eWW3Ml5WejnIWkw5dIgHKclH78j86YjmT 6wxw9R2Cd554Cjmf9ErxZECBvbBx98oFLH3hSzwbkL2TdvoXtzKuawk/v/Zkv3/YziMo ExR2mkwq31tjPvT+OG8Vno9KMnDTX3uOmi/CXPu/gWefoTJ7g6uQR2lKKHXZvx2AD/BO GNTfDbxG+d2oPorXJ1Vj6H2hk9HHPLn7XMyHUD6EatiMa7pSIeJNp34LcvkvtyyIaovm +VGFKRLwAgYUS7nSHecRQNL43iSbhTYrJIlDhaxyGVc00lDoLOk+aIq5OinJNfXPO6Gq ZX9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Z7sIUyJS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y23-20020a170906519700b007156bee9755si6707990ejk.917.2022.06.13.09.12.33; Mon, 13 Jun 2022 09:13:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Z7sIUyJS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348911AbiFMMZg (ORCPT + 99 others); Mon, 13 Jun 2022 08:25:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354782AbiFMMXs (ORCPT ); Mon, 13 Jun 2022 08:23:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 492B3580DA; Mon, 13 Jun 2022 04:03:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DBCA661347; Mon, 13 Jun 2022 11:03:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EAE0BC34114; Mon, 13 Jun 2022 11:03:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655118225; bh=qmLyxOF1QlqqtHH/XqRrUGjso9HD9RiZ88Y2BKFYqYQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z7sIUyJSfV8ev3P7vR4NBavtT4lw7hyBBe6itwyjilnUerZxzlkaKEvBwKmX9cuJC UI4eSLg06lk3zqY/s/aDnsQxLFRX/JNwOZTp8+EkCyteX4gVB27EL9LCxNNZDZ8uVf 3eszevwf5i3YCxhINCNdCM9holkjs14Rx+A/DVcE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tokunori Ikegami , Vignesh Raghavendra , Miquel Raynal Subject: [PATCH 4.19 286/287] mtd: cfi_cmdset_0002: Move and rename chip_check/chip_ready/chip_good_for_write Date: Mon, 13 Jun 2022 12:11:50 +0200 Message-Id: <20220613094932.665758427@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094923.832156175@linuxfoundation.org> References: <20220613094923.832156175@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tokunori Ikegami commit 083084df578a8bdb18334f69e7b32d690aaa3247 upstream. This is a preparation patch for the S29GL064N buffer writes fix. There is no functional change. Link: https://lore.kernel.org/r/b687c259-6413-26c9-d4c9-b3afa69ea124@pengutronix.de/ Fixes: dfeae1073583("mtd: cfi_cmdset_0002: Change write buffer to check correct value") Signed-off-by: Tokunori Ikegami Cc: stable@vger.kernel.org Acked-by: Vignesh Raghavendra Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20220323170458.5608-2-ikegami.t@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/chips/cfi_cmdset_0002.c | 77 ++++++++++++++---------------------- 1 file changed, 32 insertions(+), 45 deletions(-) --- a/drivers/mtd/chips/cfi_cmdset_0002.c +++ b/drivers/mtd/chips/cfi_cmdset_0002.c @@ -731,50 +731,34 @@ static struct mtd_info *cfi_amdstd_setup } /* - * Return true if the chip is ready. + * Return true if the chip is ready and has the correct value. * * Ready is one of: read mode, query mode, erase-suspend-read mode (in any * non-suspended sector) and is indicated by no toggle bits toggling. * + * Error are indicated by toggling bits or bits held with the wrong value, + * or with bits toggling. + * * Note that anything more complicated than checking if no bits are toggling * (including checking DQ5 for an error status) is tricky to get working * correctly and is therefore not done (particularly with interleaved chips * as each chip must be checked independently of the others). */ -static int __xipram chip_ready(struct map_info *map, unsigned long addr) +static int __xipram chip_ready(struct map_info *map, unsigned long addr, + map_word *expected) { map_word d, t; + int ret; d = map_read(map, addr); t = map_read(map, addr); - return map_word_equal(map, d, t); -} + ret = map_word_equal(map, d, t); -/* - * Return true if the chip is ready and has the correct value. - * - * Ready is one of: read mode, query mode, erase-suspend-read mode (in any - * non-suspended sector) and it is indicated by no bits toggling. - * - * Error are indicated by toggling bits or bits held with the wrong value, - * or with bits toggling. - * - * Note that anything more complicated than checking if no bits are toggling - * (including checking DQ5 for an error status) is tricky to get working - * correctly and is therefore not done (particularly with interleaved chips - * as each chip must be checked independently of the others). - * - */ -static int __xipram chip_good(struct map_info *map, unsigned long addr, map_word expected) -{ - map_word oldd, curd; - - oldd = map_read(map, addr); - curd = map_read(map, addr); + if (!ret || !expected) + return ret; - return map_word_equal(map, oldd, curd) && - map_word_equal(map, curd, expected); + return map_word_equal(map, t, *expected); } static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr, int mode) @@ -791,7 +775,7 @@ static int get_chip(struct map_info *map case FL_STATUS: for (;;) { - if (chip_ready(map, adr)) + if (chip_ready(map, adr, NULL)) break; if (time_after(jiffies, timeo)) { @@ -829,7 +813,7 @@ static int get_chip(struct map_info *map chip->state = FL_ERASE_SUSPENDING; chip->erase_suspended = 1; for (;;) { - if (chip_ready(map, adr)) + if (chip_ready(map, adr, NULL)) break; if (time_after(jiffies, timeo)) { @@ -1360,7 +1344,7 @@ static int do_otp_lock(struct map_info * /* wait for chip to become ready */ timeo = jiffies + msecs_to_jiffies(2); for (;;) { - if (chip_ready(map, adr)) + if (chip_ready(map, adr, NULL)) break; if (time_after(jiffies, timeo)) { @@ -1627,10 +1611,11 @@ static int __xipram do_write_oneword(str } /* - * We check "time_after" and "!chip_good" before checking - * "chip_good" to avoid the failure due to scheduling. + * We check "time_after" and "!chip_ready" before checking + * "chip_ready" to avoid the failure due to scheduling. */ - if (time_after(jiffies, timeo) && !chip_good(map, adr, datum)) { + if (time_after(jiffies, timeo) && + !chip_ready(map, adr, &datum)) { xip_enable(map, chip, adr); printk(KERN_WARNING "MTD %s(): software timeout\n", __func__); xip_disable(map, chip, adr); @@ -1638,7 +1623,7 @@ static int __xipram do_write_oneword(str break; } - if (chip_good(map, adr, datum)) + if (chip_ready(map, adr, &datum)) break; /* Latency issues. Drop the lock, wait a while and retry */ @@ -1882,13 +1867,13 @@ static int __xipram do_write_buffer(stru } /* - * We check "time_after" and "!chip_good" before checking "chip_good" to avoid - * the failure due to scheduling. + * We check "time_after" and "!chip_ready" before checking + * "chip_ready" to avoid the failure due to scheduling. */ - if (time_after(jiffies, timeo) && !chip_good(map, adr, datum)) + if (time_after(jiffies, timeo) && !chip_ready(map, adr, &datum)) break; - if (chip_good(map, adr, datum)) { + if (chip_ready(map, adr, &datum)) { xip_enable(map, chip, adr); goto op_done; } @@ -2022,7 +2007,7 @@ static int cfi_amdstd_panic_wait(struct * If the driver thinks the chip is idle, and no toggle bits * are changing, then the chip is actually idle for sure. */ - if (chip->state == FL_READY && chip_ready(map, adr)) + if (chip->state == FL_READY && chip_ready(map, adr, NULL)) return 0; /* @@ -2039,7 +2024,7 @@ static int cfi_amdstd_panic_wait(struct /* wait for the chip to become ready */ for (i = 0; i < jiffies_to_usecs(timeo); i++) { - if (chip_ready(map, adr)) + if (chip_ready(map, adr, NULL)) return 0; udelay(1); @@ -2103,13 +2088,13 @@ retry: map_write(map, datum, adr); for (i = 0; i < jiffies_to_usecs(uWriteTimeout); i++) { - if (chip_ready(map, adr)) + if (chip_ready(map, adr, NULL)) break; udelay(1); } - if (!chip_good(map, adr, datum)) { + if (!chip_ready(map, adr, &datum)) { /* reset on all failures. */ map_write(map, CMD(0xF0), chip->start); /* FIXME - should have reset delay before continuing */ @@ -2250,6 +2235,7 @@ static int __xipram do_erase_chip(struct DECLARE_WAITQUEUE(wait, current); int ret = 0; int retry_cnt = 0; + map_word datum = map_word_ff(map); adr = cfi->addr_unlock1; @@ -2304,7 +2290,7 @@ static int __xipram do_erase_chip(struct chip->erase_suspended = 0; } - if (chip_good(map, adr, map_word_ff(map))) + if (chip_ready(map, adr, &datum)) break; if (time_after(jiffies, timeo)) { @@ -2346,6 +2332,7 @@ static int __xipram do_erase_oneblock(st DECLARE_WAITQUEUE(wait, current); int ret = 0; int retry_cnt = 0; + map_word datum = map_word_ff(map); adr += chip->start; @@ -2400,7 +2387,7 @@ static int __xipram do_erase_oneblock(st chip->erase_suspended = 0; } - if (chip_good(map, adr, map_word_ff(map))) + if (chip_ready(map, adr, &datum)) break; if (time_after(jiffies, timeo)) { @@ -2593,7 +2580,7 @@ static int __maybe_unused do_ppb_xxlock( */ timeo = jiffies + msecs_to_jiffies(2000); /* 2s max (un)locking */ for (;;) { - if (chip_ready(map, adr)) + if (chip_ready(map, adr, NULL)) break; if (time_after(jiffies, timeo)) {