Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4714963ybv; Mon, 17 Feb 2020 04:34:09 -0800 (PST) X-Google-Smtp-Source: APXvYqzogxmBeHjcK2qkIet8K46KS052MjBBmA6C/Xf22u+k5ktqEsFVuzcDHblk7P74zwDrE/1V X-Received: by 2002:a9d:6c8d:: with SMTP id c13mr12186266otr.277.1581942849609; Mon, 17 Feb 2020 04:34:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581942849; cv=none; d=google.com; s=arc-20160816; b=inWPMAJah1S/EOfwGtKGXJ5fgYHL4Ev9E3Cz40IgdJFj+HHcH63WpOoBmW2r2xyzC9 H6VCg9DY4wyk8G35CqdANMlnFx+UBxmTg3fQCHz+yUNP7rAaHYH9OEmi06w3wzhrDx7y Te0d0z7RuB5cUbolzcRLSj0LtqHBlk4ClEFaAXfm1n4uGiGEKepKcXbQnR82BjZRnij+ janEqcVxS3OmSBfLRv+bIpeaNCecVgifFHYUDGqTKGAa9asGjfDhJxZO3+7iy5x9Jw6e 1/8f1JVHamRVqeopwrNt+QYG5lnMsQihfsiHZe4avQYeiieGoUgCZENkPPuELUuiSutK nuGQ== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=oUXWMDUnknqoWk8nw9K3WrAH1lFRwBg/cVZqYZ9flWI=; b=Ft4NOc96T9dw1ANMpRgbFtuamiacw9mD2U2z1jUkg31EB+ezvRUQy2R8x6xzJD8wXS BopsLaRmO/wddbBlhjzJZrGgmK4dQ5F0y0Mb4nZuPHVMZnjCfJr9hRLcDJ6Xl3jZPNBI 5ASkgYSoHmhLFhgSiaNcsdHLDdvmVi58OHDCMUiAv35np+2hn03C5GKU+byB8ipbNAwS cOM9uvTl6gntOKnjqnyqK5wSvz+ZKiDT8aNaDYVxQZTIKSLhlyoJh0hcaYLAqwwdHLSK ZvSI+XIIthTRwJ0WcfPeD1Q6/qPlbxFjyas+Q068lWP5CdhLHmE7aSRIORNyqgWYQvLT 2gLA== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w2si145576otq.31.2020.02.17.04.33.57; Mon, 17 Feb 2020 04:34:09 -0800 (PST) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728698AbgBQLOI convert rfc822-to-8bit (ORCPT + 99 others); Mon, 17 Feb 2020 06:14:08 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:38990 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728297AbgBQLOI (ORCPT ); Mon, 17 Feb 2020 06:14:08 -0500 Received: from localhost (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: bbrezillon) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 1CC2D29313C; Mon, 17 Feb 2020 11:14:06 +0000 (GMT) Date: Mon, 17 Feb 2020 12:14:02 +0100 From: Boris Brezillon To: Miquel Raynal Cc: Schrempf Frieder , Boris Brezillon , Jeff Kletsky , liaoweixiong , Peter Pan , "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-mtd@lists.infradead.org" , "Richard Weinberger" Subject: Re: [PATCH 3/3] mtd: spinand: Wait for the erase op to finish before writing a bad block marker Message-ID: <20200217121402.44e00350@collabora.com> In-Reply-To: <20200217113919.0508acc4@xps13> References: <20200211163452.25442-1-frieder.schrempf@kontron.de> <20200211163452.25442-4-frieder.schrempf@kontron.de> <20200217113919.0508acc4@xps13> Organization: Collabora X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) 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 On Mon, 17 Feb 2020 11:39:19 +0100 Miquel Raynal wrote: > Hi Frieder, > > Schrempf Frieder wrote on Tue, 11 Feb > 2020 16:35:53 +0000: > > > From: Frieder Schrempf > > > > Currently when marking a block, we use spinand_erase_op() to erase > > the block before writing the marker to the OOB area without waiting > > for the operation to succeed. This can lead to the marking failing > > silently and no bad block marker being written to the flash. > > > > To fix this we reuse the spinand_erase() function, that already does > > everything we need to do before actually writing the marker. > > > > Thanks a lot for this series! > > Yet I don't really understand the point of waiting for the erasure if > it failed: we don't really care as programming (1 -> 0) cells is always > possible. Are you sure this lead to an error? Actually, I think I already pointed out that we should probably write the BBM without erasing the block. IIRC, this logic has been copied from rawnand where some controllers don't disable the ECC engine when doing raw accesses, leading to ECC errors if the block is not erased before BBMs are programmed. Assuming we don't let such drivers being merged in spinand, this erase operation can be dropped. > > Also, why just not calling spinand_erase() instead of > spinand_erase_op() from spinand_markbad()? > > > Fixes: 7529df465248 ("mtd: nand: Add core infrastructure to support SPI NANDs") > > Cc: stable@vger.kernel.org > > Signed-off-by: Frieder Schrempf > > --- > > drivers/mtd/nand/spi/core.c | 56 ++++++++++++++++++------------------- > > 1 file changed, 28 insertions(+), 28 deletions(-) > > > > diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c > > index 925db6269861..8a69d13639e2 100644 > > --- a/drivers/mtd/nand/spi/core.c > > +++ b/drivers/mtd/nand/spi/core.c > > @@ -600,6 +600,32 @@ static int spinand_mtd_block_isbad(struct mtd_info *mtd, loff_t offs) > > return ret; > > } > > > > +static int __spinand_erase(struct nand_device *nand, const struct nand_pos *pos, > > + bool hard_fail) I hate those __ prefix. Please find a more descriptive name (spinand_erase_block() or spinand_erase_and_wait()?) > > +{ > > + struct spinand_device *spinand = nand_to_spinand(nand); > > + u8 status; > > + int ret; > > + > > + ret = spinand_select_target(spinand, pos->target); > > + if (ret) > > + return ret; > > + > > + ret = spinand_write_enable_op(spinand); > > + if (ret) > > + return ret; > > + > > + ret = spinand_erase_op(spinand, pos); > > + if (ret && hard_fail) > > + return ret; > > + > > + ret = spinand_wait(spinand, &status); > > + if (!ret && (status & STATUS_ERASE_FAILED)) > > + ret = -EIO; > > + > > + return ret; > > +} > > + > > static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos) > > { > > struct spinand_device *spinand = nand_to_spinand(nand); > > @@ -614,16 +640,10 @@ static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos) > > int ret; > > > > /* Erase block before marking it bad. */ > > - ret = spinand_select_target(spinand, pos->target); > > - if (ret) > > - return ret; > > - > > - ret = spinand_write_enable_op(spinand); > > + ret = __spinand_erase(nand, pos, false); > > if (ret) > > return ret; > > > > - spinand_erase_op(spinand, pos); > > - > > return spinand_write_page(spinand, &req); > > } > > > > @@ -644,27 +664,7 @@ static int spinand_mtd_block_markbad(struct mtd_info *mtd, loff_t offs) > > > > static int spinand_erase(struct nand_device *nand, const struct nand_pos *pos) > > { > > - struct spinand_device *spinand = nand_to_spinand(nand); > > - u8 status; > > - int ret; > > - > > - ret = spinand_select_target(spinand, pos->target); > > - if (ret) > > - return ret; > > - > > - ret = spinand_write_enable_op(spinand); > > - if (ret) > > - return ret; > > - > > - ret = spinand_erase_op(spinand, pos); > > - if (ret) > > - return ret; > > - > > - ret = spinand_wait(spinand, &status); > > - if (!ret && (status & STATUS_ERASE_FAILED)) > > - ret = -EIO; > > - > > - return ret; > > + return __spinand_erase(nand, pos, true); > > } > > > > static int spinand_mtd_erase(struct mtd_info *mtd, > > Thanks, > Miquèl