Skip to content

Commit 7c9414c

Browse files
committed
mtd: rawnand: Fix core interference with sequential reads
A couple of reports pointed at some strange failures happening a bit randomly since the introduction of sequential page reads support. After investigation it turned out the most likely reason for these issues was the fact that sometimes a (longer) read might happen, starting at the same page that was read previously. This is optimized by the raw NAND core, by not sending the READ_PAGE command to the NAND device and just reading out the data in a local cache. When this page is also flagged as being the starting point for a sequential read, it means the page right next will be accessed without the right instructions. The NAND chip will be confused and will not output correct data. In order to avoid such situation from happening anymore, we can however handle this case with a bit of additional logic, to postpone the initialization of the read sequence by one page. Reported-by: Alexander Shiyan <eagle.alexander923@gmail.com> Closes: https://lore.kernel.org/linux-mtd/CAP1tNvS=NVAm-vfvYWbc3k9Cx9YxMc2uZZkmXk8h1NhGX877Zg@mail.gmail.com/ Reported-by: Måns Rullgård <mans@mansr.com> Closes: https://lore.kernel.org/linux-mtd/yw1xfs6j4k6q.fsf@mansr.com/ Reported-by: Martin Hundebøll <martin@geanix.com> Closes: https://lore.kernel.org/linux-mtd/9d0c42fcde79bfedfe5b05d6a4e9fdef71d3dd52.camel@geanix.com/ Fixes: 003fe4b ("mtd: rawnand: Support for sequential cache reads") Cc: stable@vger.kernel.org Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Tested-by: Martin Hundebøll <martin@geanix.com> Link: https://lore.kernel.org/linux-mtd/20231215123208.516590-3-miquel.raynal@bootlin.com
1 parent bbcd80f commit 7c9414c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

drivers/mtd/nand/raw/nand_base.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3478,6 +3478,18 @@ static void rawnand_enable_cont_reads(struct nand_chip *chip, unsigned int page,
34783478
rawnand_cap_cont_reads(chip);
34793479
}
34803480

3481+
static void rawnand_cont_read_skip_first_page(struct nand_chip *chip, unsigned int page)
3482+
{
3483+
if (!chip->cont_read.ongoing || page != chip->cont_read.first_page)
3484+
return;
3485+
3486+
chip->cont_read.first_page++;
3487+
if (chip->cont_read.first_page == chip->cont_read.pause_page)
3488+
chip->cont_read.first_page++;
3489+
if (chip->cont_read.first_page >= chip->cont_read.last_page)
3490+
chip->cont_read.ongoing = false;
3491+
}
3492+
34813493
/**
34823494
* nand_setup_read_retry - [INTERN] Set the READ RETRY mode
34833495
* @chip: NAND chip object
@@ -3652,6 +3664,8 @@ static int nand_do_read_ops(struct nand_chip *chip, loff_t from,
36523664
buf += bytes;
36533665
max_bitflips = max_t(unsigned int, max_bitflips,
36543666
chip->pagecache.bitflips);
3667+
3668+
rawnand_cont_read_skip_first_page(chip, page);
36553669
}
36563670

36573671
readlen -= bytes;

0 commit comments

Comments
 (0)