Backport fixes for SPI NAND on i.MX6UL
Subsystems (2)
cover Backport fixes for SPI NAND on i.MX6UL
From: Frieder Schrempf <[email protected]>
There are failures with our Kontron i.MX6UL boards using Macronix SPI NAND chips on i.MX6UL that originate in the introduction of the continuous read feature in 6.12 (631cfdd0520d19b7f4fc13b834fd9c8b46c6dbac) and the absence of later fixes introduced in 6.18 that were never backported.
This series contains these fixes picked from mainline, applying to stable 6.12 cleanly.
Mikhail Kshevetskiy (3):
mtd: spinand: fix direct mapping creation sizes
mtd: spinand: try a regular dirmap if creating a dirmap for continuous
reading fails
mtd: spinand: repeat reading in regular mode if continuous reading
fails
drivers/mtd/nand/spi/core.c | 74 +++++++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 15 deletions(-)
Signature · 5 lines
2.55.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 1/3 mtd: spinand: fix direct mapping creation sizes
From: Mikhail Kshevetskiy <[email protected]>
[ Upstream commit e4a0cf9f1d90e6888e5373da3314f761024f6c97 ]
Continuous mode is only supported for data reads, thus writing requires only single flash page mapping.
--- drivers/mtd/nand/spi/core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/mtd/nand/spi/core.c +7 -7
@@ -1036,18 +1036,13 @@ static int spinand_create_dirmap(struct spinand_device *spinand, unsigned int plane) {struct nand_device *nand =spinand_to_nand (spinand); -struct spi_mem_dirmap_info info = { - .length =nanddev_page_size (nand) + -nanddev_per_page_oobsize (nand), - }; +struct spi_mem_dirmap_info info = {0 };struct spi_mem_dirmap_desc *desc; -if (spinand->cont_read_possible) - info.length =nanddev_eraseblock_size (nand); -/* The plane number is passed in MSB just above the column address */ info.offset = plane <<fls (nand->memorg.pagesize); + info.length =nanddev_page_size (nand) +nanddev_per_page_oobsize (nand); info.op_tmpl = *spinand->op_templates.update_cache; desc =devm_spi_mem_dirmap_create (&spinand->spimem->spi->dev, spinand->spimem, &info);
@@ -1056,6 +1051,8 @@ static int spinand_create_dirmap(struct spinand_device *spinand, spinand->dirmaps[plane].wdesc = desc; +if (spinand->cont_read_possible) + info.length =nanddev_eraseblock_size (nand); info.op_tmpl = *spinand->op_templates.read_cache; desc =devm_spi_mem_dirmap_create (&spinand->spimem->spi->dev, spinand->spimem, &info);
@@ -1071,6 +1068,7 @@ static int spinand_create_dirmap(struct spinand_device *spinand,return 0 ; } + info.length =nanddev_page_size (nand) +nanddev_per_page_oobsize (nand); info.op_tmpl = *spinand->op_templates.update_cache; info.op_tmpl.data.ecc = true; desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev,
@@ -1080,6 +1078,8 @@ static int spinand_create_dirmap(struct spinand_device *spinand, spinand->dirmaps[plane].wdesc_ecc = desc; +if (spinand->cont_read_possible) + info.length =nanddev_eraseblock_size (nand); info.op_tmpl = *spinand->op_templates.read_cache; info.op_tmpl.data.ecc = true; desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev,
Signature · 6 lines
2.55.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 2/3 mtd: spinand: try a regular dirmap if creating a dirmap for continuous reading fails
In reply to Frieder SchrempfFrom: Mikhail Kshevetskiy <[email protected]>
[ Upstream commit 004f8ea0d9917398aabff7388b3bf62a84a4088b ]
Continuous reading may result in multiple flash pages reading in one operation. Typically only one flash page has read/written (a little bit more than 2-4 Kb), but continuous reading requires the spi controller to read up to 512 Kb in one operation without toggling CS in beetween.
Roughly speaking spi controllers can be divided on 2 categories:
* spi controllers without dirmap acceleration support
* spi controllers with dirmap acceleration support
Firt of them will have issues with continuous reading if restriction on the transfer length is implemented in the adjust_op_size() handler. Second group often supports acceleration of single page only reading. Thus enabling of continuous reading can break flash reading.
This patch tries to create dirmap for continuous reading first and fallback to regular reading if spi controller refuses to create it.
--- drivers/mtd/nand/spi/core.c | 43 ++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 8 deletions(-)
drivers/mtd/nand/spi/core.c +35 -8
@@ -1032,6 +1032,39 @@ static int spinand_mtd_block_isreserved(struct mtd_info *mtd, loff_t offs)return ret; } +static struct spi_mem_dirmap_desc *spinand_create_rdesc ( +struct spinand_device *spinand, +struct spi_mem_dirmap_info *info) +{ +struct nand_device *nand =spinand_to_nand (spinand); +struct spi_mem_dirmap_desc *desc =NULL ; + +if (spinand->cont_read_possible) { +/* +* spi controller may return an error if info->length is +* too large +*/ + info->length =nanddev_eraseblock_size (nand); + desc =devm_spi_mem_dirmap_create (&spinand->spimem->spi->dev, + spinand->spimem, info); + } + +if (IS_ERR_OR_NULL (desc)) { +/* +* continuous reading is not supported by flash or +* its spi controller, use regular reading +*/ + spinand->cont_read_possible = false; + + info->length =nanddev_page_size (nand) + +nanddev_per_page_oobsize (nand); + desc =devm_spi_mem_dirmap_create (&spinand->spimem->spi->dev, + spinand->spimem, info); + } + +return desc; +} +static int spinand_create_dirmap (struct spinand_device *spinand,unsigned int plane) {
@@ -1051,11 +1084,8 @@ static int spinand_create_dirmap(struct spinand_device *spinand, spinand->dirmaps[plane].wdesc = desc; -if (spinand->cont_read_possible) - info.length =nanddev_eraseblock_size (nand); info.op_tmpl = *spinand->op_templates.read_cache; - desc =devm_spi_mem_dirmap_create (&spinand->spimem->spi->dev, - spinand->spimem, &info); + desc =spinand_create_rdesc (spinand, &info);if (IS_ERR (desc))return PTR_ERR (desc);
@@ -1078,12 +1108,9 @@ static int spinand_create_dirmap(struct spinand_device *spinand, spinand->dirmaps[plane].wdesc_ecc = desc; -if (spinand->cont_read_possible) - info.length =nanddev_eraseblock_size (nand); info.op_tmpl = *spinand->op_templates.read_cache; info.op_tmpl.data.ecc = true; - desc =devm_spi_mem_dirmap_create (&spinand->spimem->spi->dev, - spinand->spimem, &info); + desc =spinand_create_rdesc (spinand, &info);if (IS_ERR (desc))return PTR_ERR (desc);
Signature · 6 lines
2.55.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 3/3 mtd: spinand: repeat reading in regular mode if continuous reading fails
In reply to Frieder SchrempfFrom: Mikhail Kshevetskiy <[email protected]>
[ Upstream commit 010dc7f2dd6a0078ade3f88f627ed5fbf45ceb94 ]
Continuous reading may result in multiple flash pages reading in one operation. Unfortunately, not all spinand controllers support such large reading. They will read less data. Unfortunately, the operation can't be continued.
In this case:
* disable continuous reading on this (not good enough) spi controller
* repeat reading in regular mode.
--- drivers/mtd/nand/spi/core.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)
drivers/mtd/nand/spi/core.c +21 -4
@@ -427,8 +427,16 @@ static int spinand_read_from_cache_op(struct spinand_device *spinand,* Dirmap accesses are allowed to toggle the CS. * Toggling the CS during a continuous read is forbidden. */ -if (nbytes && req->continuous) -return -EIO ; +if (nbytes && req->continuous) { +/* +* Spi controller with broken support of continuous +* reading was detected. Disable future use of +* continuous reading and return -EAGAIN to retry +* reading within regular mode. +*/ + spinand->cont_read_possible = false; +return -EAGAIN ; + } }if (req->datalen)
@@ -849,10 +857,19 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from, old_stats = mtd->ecc_stats; -if (spinand_use_cont_read (mtd, from, ops)) +if (spinand_use_cont_read (mtd, from, ops)) { ret =spinand_mtd_continuous_page_read (mtd, from, ops, &max_bitflips); -else +if (ret == -EAGAIN && !spinand->cont_read_possible) { +/* +* Spi controller with broken support of continuous +* reading was detected (see spinand_read_from_cache_op()), +* repeat reading in regular mode. +*/ + ret =spinand_mtd_regular_page_read (mtd, from, ops, &max_bitflips); + } + }else { ret =spinand_mtd_regular_page_read (mtd, from, ops, &max_bitflips); + }if (ops->stats) { ops->stats->uncorrectable_errors +=
Signature · 6 lines
2.55.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Quoted 16 lines
This series contains these fixes picked from mainline, applying to stable 6.12 cleanly.
Cc Mikhail Kshevetskiy <[email protected]>Cc Miquel Raynal <[email protected]>Mikhail Kshevetskiy (3):
mtd: spinand: fix direct mapping creation sizes
mtd: spinand: try a regular dirmap if creating a dirmap for continuous
reading fails
mtd: spinand: repeat reading in regular mode if continuous reading
fails
Quoted 2 lines
drivers/mtd/nand/spi/core.c | 74 +++++++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 15 deletions(-)
Thanks for the backports,
Miquèl
Quoted 2 lines · Frieder Schrempf
This series contains these fixes picked from mainline, applying to stable 6.12 cleanly.
Queued the series for 6.12, thanks.
Signature · 2 lines
Thanks, Sasha