linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [v2] mtd: rawnand: Change calculating of position page containing BBM
@ 2019-09-24  5:54 Piotr Sroka
  2019-10-04 16:04 ` Miquel Raynal
  0 siblings, 1 reply; 2+ messages in thread
From: Piotr Sroka @ 2019-09-24  5:54 UTC (permalink / raw)
  Cc: Kate Stewart, Vignesh Raghavendra, Boris Brezillon,
	Richard Weinberger, Greg Kroah-Hartman, stable, linux-kernel,
	Marek Vasut, linux-mtd, Frieder Schrempf, Miquel Raynal,
	Thomas Gleixner, Brian Norris, David Woodhouse, Piotr Sroka

Change calculating of position page containing BBM

If none of BBM flags are set then function nand_bbm_get_next_page 
reports EINVAL. It causes that BBM is not read at all during scanning
factory bad blocks. The result is that the BBT table is build without 
checking factory BBM at all. For Micron flash memories none of these 
flags are set if page size is different than 2048 bytes.

Address this regression by:
- adding NAND_BBM_FIRSTPAGE chip flag without any condition. It solves
  issue only for Micron devices.
- changing the nand_bbm_get_next_page_function. It will return 0 
  if no of BBM flag is set and page parameter is 0. After that modification
  way of discovering factory bad blocks will work similar as in kernel 
  version 5.1.

Cc: stable@vger.kernel.org
Fixes: f90da7818b14 (mtd: rawnand: Support bad block markers in first, second or last page)
Signed-off-by: Piotr Sroka <piotrs@cadence.com>
Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>
---
Changes for v2:
- add fix for micron nand driver
- add fixes and stable tags
---
 drivers/mtd/nand/raw/nand_base.c   | 8 ++++++--
 drivers/mtd/nand/raw/nand_micron.c | 4 +++-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 5c2c30a7dffa..f64e3b6605c6 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -292,12 +292,16 @@ int nand_bbm_get_next_page(struct nand_chip *chip, int page)
 	struct mtd_info *mtd = nand_to_mtd(chip);
 	int last_page = ((mtd->erasesize - mtd->writesize) >>
 			 chip->page_shift) & chip->pagemask;
+	unsigned int bbm_flags = NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE
+		| NAND_BBM_LASTPAGE;
 
+	if (page == 0 && !(chip->options & bbm_flags))
+		return 0;
 	if (page == 0 && chip->options & NAND_BBM_FIRSTPAGE)
 		return 0;
-	else if (page <= 1 && chip->options & NAND_BBM_SECONDPAGE)
+	if (page <= 1 && chip->options & NAND_BBM_SECONDPAGE)
 		return 1;
-	else if (page <= last_page && chip->options & NAND_BBM_LASTPAGE)
+	if (page <= last_page && chip->options & NAND_BBM_LASTPAGE)
 		return last_page;
 
 	return -EINVAL;
diff --git a/drivers/mtd/nand/raw/nand_micron.c b/drivers/mtd/nand/raw/nand_micron.c
index 1622d3145587..913f42854563 100644
--- a/drivers/mtd/nand/raw/nand_micron.c
+++ b/drivers/mtd/nand/raw/nand_micron.c
@@ -438,8 +438,10 @@ static int micron_nand_init(struct nand_chip *chip)
 	if (ret)
 		goto err_free_manuf_data;
 
+	chip->options |= NAND_BBM_FIRSTPAGE;
+
 	if (mtd->writesize == 2048)
-		chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE;
+		chip->options |= NAND_BBM_SECONDPAGE;
 
 	ondie = micron_supports_on_die_ecc(chip);
 
-- 
2.15.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [v2] mtd: rawnand: Change calculating of position page containing BBM
  2019-09-24  5:54 [v2] mtd: rawnand: Change calculating of position page containing BBM Piotr Sroka
@ 2019-10-04 16:04 ` Miquel Raynal
  0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2019-10-04 16:04 UTC (permalink / raw)
  To: Piotr Sroka
  Cc: Kate Stewart, Vignesh Raghavendra, Boris Brezillon,
	Richard Weinberger, Miquel Raynal, linux-kernel, stable,
	Marek Vasut, linux-mtd, Frieder Schrempf, Greg Kroah-Hartman,
	Thomas Gleixner, Brian Norris, David Woodhouse

On Tue, 2019-09-24 at 05:54:31 UTC, Piotr Sroka wrote:
> Change calculating of position page containing BBM
> 
> If none of BBM flags are set then function nand_bbm_get_next_page 
> reports EINVAL. It causes that BBM is not read at all during scanning
> factory bad blocks. The result is that the BBT table is build without 
> checking factory BBM at all. For Micron flash memories none of these 
> flags are set if page size is different than 2048 bytes.
> 
> Address this regression by:
> - adding NAND_BBM_FIRSTPAGE chip flag without any condition. It solves
>   issue only for Micron devices.
> - changing the nand_bbm_get_next_page_function. It will return 0 
>   if no of BBM flag is set and page parameter is 0. After that modification
>   way of discovering factory bad blocks will work similar as in kernel 
>   version 5.1.
> 
> Cc: stable@vger.kernel.org
> Fixes: f90da7818b14 (mtd: rawnand: Support bad block markers in first, second or last page)
> Signed-off-by: Piotr Sroka <piotrs@cadence.com>
> Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.

Miquel

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-04 16:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-24  5:54 [v2] mtd: rawnand: Change calculating of position page containing BBM Piotr Sroka
2019-10-04 16:04 ` Miquel Raynal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).