Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2196067iof; Tue, 7 Jun 2022 22:53:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4iVy2nXC8qgvqEuhfZTbLclS9UVTi+3Noe76B9CY1HP/iAiL5i6dbkj+0xXZIlKWHC1AD X-Received: by 2002:a63:d314:0:b0:3fc:7054:bf54 with SMTP id b20-20020a63d314000000b003fc7054bf54mr28161405pgg.615.1654667593620; Tue, 07 Jun 2022 22:53:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654667593; cv=none; d=google.com; s=arc-20160816; b=Hru0wP3okkxe/W6YnMRnkZzk74b1xjpbQ0lJi7JEkR55PrjqlJ5sBDMCIRBgwsR7v1 iuBB49JQh1QRgUhR9sDXAi8W+YeA7G6S4HneTG8JaFYqzXxWYd+KmqR6k+zsjqPCG0Le Gzhh9cZZdUKD3QSyR/8A/CSJpAlZ3cZKc24SlbflkUXfSx6kuIHGrv/GWNU/P9JeXsr/ S40oQe8b0h2jj2wuu3uXi+zTEQBciRaoBh0fUr4i6+fIZWj30WDAud6PX3V2YxCH62Qx I4iBVdEdTbXHg6GwyjAEdhh23w9+wHScNpIzdDKWu17dKlDynH8wreyQHXc0wMP9vaci YmKw== 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=jqK4DDLi5Cr/MV/btkbl+Q0kPKSeJnXWsdDggbTCzTc=; b=P8Pz9rlveJQETUo6oK5Abh0vFvDMl+iaGjwt6t1DDg51NhFAEWBY+5/njlbdA2GrRs yRUxOziC9EnuwkMR6/drViHNW9QfeLl970ZtTw+ZARWyRO4uQYyEKWZGabBiKaRk8EW0 +JVMYqZnxynMDqE+vMEvpfRP+EI8txnEu3jIVI3kF6QNqedxyPnVE7tKngrW78kNFJYd oleDFx0rkgFK8OU8quIAO8F1IHDrTlHA8dTxOub6cQHKUvAGFN2caI09BiBPT66g59K9 CDwPOG92B2gxw2ExQtcdvUfpTgWwsSpjK79hTuRawxq08/DW/Lqojao+jzt+Ii5BTClQ Xkeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jT9S7nCI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id g4-20020a655944000000b003fdc5b67013si10664951pgu.735.2022.06.07.22.53.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:53:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jT9S7nCI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0372D45EE7E; Tue, 7 Jun 2022 22:19:51 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441875AbiFHAxT (ORCPT + 99 others); Tue, 7 Jun 2022 20:53:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357930AbiFGWVv (ORCPT ); Tue, 7 Jun 2022 18:21:51 -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 943D226D274; Tue, 7 Jun 2022 12:22:31 -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 C31BC60A21; Tue, 7 Jun 2022 19:22:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB389C385A2; Tue, 7 Jun 2022 19:22:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629750; bh=zNeRIJjkEW1zo9LCtloBDr6hePcLyXcetBHHajv3tZI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jT9S7nCIF3Wh7AZBBslurwyJ/z0jeXzawlMYhuZ1/ipg6o3xbp3tOnvTCpA0sils+ 1g1NRMNg6uJQ6H0FxAvaj2SK+xp0pKDsanBSasG1ESBJJt+ClB2e+r6mz2W67W9Cu+ inm9D0hmTVr1/MD5M40Cw70gKvEeD/f2T/v80prs= 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 5.18 801/879] mtd: cfi_cmdset_0002: Use chip_ready() for write on S29GL064N Date: Tue, 7 Jun 2022 19:05:19 +0200 Message-Id: <20220607165026.108653744@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 0a8e98305f63deaf0a799d5cf5532cc83af035d1 upstream. Since commit dfeae1073583("mtd: cfi_cmdset_0002: Change write buffer to check correct value") buffered writes fail on S29GL064N. This is because, on S29GL064N, reads return 0xFF at the end of DQ polling for write completion, where as, chip_good() check expects actual data written to the last location to be returned post DQ polling completion. Fix is to revert to using chip_good() for S29GL064N which only checks for DQ lines to settle down to determine write completion. 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") Cc: stable@vger.kernel.org Signed-off-by: Tokunori Ikegami Acked-by: Vignesh Raghavendra Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20220323170458.5608-3-ikegami.t@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/chips/cfi_cmdset_0002.c | 42 +++++++++++++++++++++++++++++------- include/linux/mtd/cfi.h | 1 2 files changed, 35 insertions(+), 8 deletions(-) --- a/drivers/mtd/chips/cfi_cmdset_0002.c +++ b/drivers/mtd/chips/cfi_cmdset_0002.c @@ -59,6 +59,10 @@ #define CFI_SR_WBASB BIT(3) #define CFI_SR_SLSB BIT(1) +enum cfi_quirks { + CFI_QUIRK_DQ_TRUE_DATA = BIT(0), +}; + static int cfi_amdstd_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *); static int cfi_amdstd_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); #if !FORCE_WORD_WRITE @@ -436,6 +440,15 @@ static void fixup_s29ns512p_sectors(stru mtd->name); } +static void fixup_quirks(struct mtd_info *mtd) +{ + struct map_info *map = mtd->priv; + struct cfi_private *cfi = map->fldrv_priv; + + if (cfi->mfr == CFI_MFR_AMD && cfi->id == 0x0c01) + cfi->quirks |= CFI_QUIRK_DQ_TRUE_DATA; +} + /* Used to fix CFI-Tables of chips without Extended Query Tables */ static struct cfi_fixup cfi_nopri_fixup_table[] = { { CFI_MFR_SST, 0x234a, fixup_sst39vf }, /* SST39VF1602 */ @@ -474,6 +487,7 @@ static struct cfi_fixup cfi_fixup_table[ #if !FORCE_WORD_WRITE { CFI_MFR_ANY, CFI_ID_ANY, fixup_use_write_buffers }, #endif + { CFI_MFR_ANY, CFI_ID_ANY, fixup_quirks }, { 0, 0, NULL } }; static struct cfi_fixup jedec_fixup_table[] = { @@ -846,6 +860,18 @@ static int __xipram chip_ready(struct ma return map_word_equal(map, t, *expected); } +static int __xipram chip_good(struct map_info *map, struct flchip *chip, + unsigned long addr, map_word *expected) +{ + struct cfi_private *cfi = map->fldrv_priv; + map_word *datum = expected; + + if (cfi->quirks & CFI_QUIRK_DQ_TRUE_DATA) + datum = NULL; + + return chip_ready(map, chip, addr, datum); +} + static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr, int mode) { DECLARE_WAITQUEUE(wait, current); @@ -1662,11 +1688,11 @@ static int __xipram do_write_oneword_onc } /* - * We check "time_after" and "!chip_ready" before checking - * "chip_ready" to avoid the failure due to scheduling. + * 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, &datum)) { + !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); @@ -1674,7 +1700,7 @@ static int __xipram do_write_oneword_onc break; } - if (chip_ready(map, chip, adr, &datum)) { + if (chip_good(map, chip, adr, &datum)) { if (cfi_check_err_status(map, chip, adr)) ret = -EIO; break; @@ -1942,18 +1968,18 @@ static int __xipram do_write_buffer_wait } /* - * We check "time_after" and "!chip_ready" before checking - * "chip_ready" to avoid the failure due to scheduling. + * 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, &datum)) { + !chip_good(map, chip, adr, &datum)) { pr_err("MTD %s(): software timeout, address:0x%.8lx.\n", __func__, adr); ret = -EIO; break; } - if (chip_ready(map, chip, adr, &datum)) { + if (chip_good(map, chip, adr, &datum)) { if (cfi_check_err_status(map, chip, adr)) ret = -EIO; break; --- a/include/linux/mtd/cfi.h +++ b/include/linux/mtd/cfi.h @@ -286,6 +286,7 @@ struct cfi_private { map_word sector_erase_cmd; unsigned long chipshift; /* Because they're of the same type */ const char *im_name; /* inter_module name for cmdset_setup */ + unsigned long quirks; struct flchip chips[]; /* per-chip data structure for each chip */ };