Add continuous read mode support
Subsystems (2)
v2 cover Add continuous read mode support
v2:
Fix missing definition of totallen in mtd_oob_ops structure in include/linux/mtd/mtd.h.
This patch series add continuous read mode support for SPI NAND devices.
Leo Yu (5):
mtd: spinand: Add continuous read mode configuration
mtd: spinand: Add continuous read mode initialization
cmd: mtd: Add total length of read operation
mtd: spinand: Add continuous read operation
mtd: spinand: macronix: Add continuous read mode flag for devices
cmd/mtd.c | 2 + drivers/mtd/nand/spi/core.c | 140 +++++++++++++++++++++++++++++++- drivers/mtd/nand/spi/macronix.c | 10 +-- include/linux/mtd/mtd.h | 2 + include/linux/mtd/spinand.h | 5 ++ 5 files changed, 153 insertions(+), 6 deletions(-)
--
2.17.1
PATCH v2 1/5 mtd: spinand: Add continuous read mode configuration
This patch sets the "CONT" bit in the configuration register and adds a flag for identifying continuous read mode capability.
--- drivers/mtd/nand/spi/core.c | 12 ++++++++++++ include/linux/mtd/spinand.h | 2 ++ 2 files changed, 14 insertions(+)
drivers/mtd/nand/spi/core.c +12 -0
@@ -216,6 +216,18 @@ static int spinand_init_quad_enable(struct spinand_device *spinand) enable ? CFG_QUAD_ENABLE : 0); } +static int spinand_continuous_read_enable (struct spinand_device *spinand, +bool enable) +{ +int ret =spinand_upd_cfg (spinand,CFG_CONT_READ_ENABLE , + enable ?CFG_CONT_READ_ENABLE :0 ); + +if (!ret) + spinand->use_continuous_read = enable; + +return ret; +} +static int spinand_ecc_enable (struct spinand_device *spinand,bool enable) {
include/linux/mtd/spinand.h +2 -0
@@ -131,6 +131,7 @@#define REG_CFG 0xb0#define CFG_OTP_ENABLE BIT(6)#define CFG_ECC_ENABLE BIT(4) +#define CFG_CONT_READ_ENABLE BIT(2)#define CFG_QUAD_ENABLE BIT(0)/* status register */
@@ -247,6 +248,7 @@ struct spinand_ecc_info {#define SPINAND_HAS_QE_BIT BIT(0)#define SPINAND_HAS_CR_FEAT_BIT BIT(1) +#define SPINAND_HAS_CONT_READ_BIT BIT(2)/** * struct spinand_info - Structure used to describe SPI NAND chips
--
2.17.1
PATCH v2 2/5 mtd: spinand: Add continuous read mode initialization
In reply to Leo YuAdd continuous read mode status and initialize the default status to false.
--- drivers/mtd/nand/spi/core.c | 8 ++++++++ include/linux/mtd/spinand.h | 3 +++ 2 files changed, 11 insertions(+)
drivers/mtd/nand/spi/core.c +8 -0
@@ -216,6 +216,11 @@ static int spinand_init_quad_enable(struct spinand_device *spinand) enable ? CFG_QUAD_ENABLE : 0); } +static void spinand_init_continuous_read (struct spinand_device *spinand) +{ + spinand->use_continuous_read = false; +} +static int spinand_continuous_read_enable (struct spinand_device *spinand,bool enable) {
@@ -1126,6 +1131,9 @@ static int spinand_init(struct spinand_device *spinand) mtd->oobavail = ret; +/* Init continuous read mode */ +spinand_init_continuous_read (spinand); +return 0 ; err_cleanup_nanddev:
include/linux/mtd/spinand.h +3 -0
@@ -337,6 +337,7 @@ struct spinand_info {* the stack * @manufacturer: SPI NAND manufacturer information * @priv: manufacturer private data +* @use_continuous_read: indicate the continuous read mode status */ struct spinand_device {struct nand_device base;
@@ -367,6 +368,8 @@ struct spinand_device {u8 *scratchbuf;const struct spinand_manufacturer *manufacturer;void *priv; + +bool use_continuous_read; };/**
--
2.17.1
PATCH v2 3/5 cmd: mtd: Add total length of read operation
In reply to Leo YuThis patch bypasses the limitation of length for read operations in MTD test module. Thus, the total length of a read operation can be passed down to the continuous read operation in SPI NAND layer.
--- cmd/mtd.c | 2 ++ include/linux/mtd/mtd.h | 2 ++ 2 files changed, 4 insertions(+)
cmd/mtd.c +2 -0
@@ -335,6 +335,8 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc, io_op.ooblen = woob ? mtd->oobsize :0 ; io_op.datbuf = buf; io_op.oobbuf = woob ? &buf[len] :NULL ; +/* Total length of this read operation passed by user */ + io_op.totallen = len;/* Search for the first good block after the given offset */ off = start_off;
include/linux/mtd/mtd.h +2 -0
@@ -79,6 +79,7 @@ struct mtd_erase_region_info {* mode = MTD_OPS_PLACE_OOB or MTD_OPS_RAW) * @datbuf: data buffer - if NULL only oob data are read/written * @oobbuf: oob data buffer +* @totallen: total number of data bytes to read in one read operation (for continuous read mode) */ struct mtd_oob_ops {unsigned int mode;
@@ -89,6 +90,7 @@ struct mtd_oob_ops {uint32_t ooboffs;uint8_t *datbuf;uint8_t *oobbuf; +size_t totallen; };#ifdef CONFIG_SYS_NAND_MAX_OOBFREE
--
2.17.1
Miquel Raynal
maintainerRe: [PATCH v2 3/5] cmd: mtd: Add total length of read operation
Hi Leo,
[email protected] wrote on Wed, 2 Nov 2022 14:14:30 +0800:
Quoted 16 lines
This patch bypasses the limitation of length for read operations in MTD test module. Thus, the total length of a read operation can be passed down to the continuous read operation in SPI NAND layer.
Signed-off-by Leo Yu <[email protected]>--- cmd/mtd.c | 2 ++ include/linux/mtd/mtd.h | 2 ++ 2 files changed, 4 insertions(+)cmd/mtd.c +0
-0
cmd/mtd.c static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc, · line 339
Quoted 5 lines
cmd/mtd.c +2
-0@@ -335,6 +335,8 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc, io_op.ooblen = woob ? mtd->oobsize :0 ; io_op.datbuf = buf; io_op.oobbuf = woob ? &buf[len] :NULL ; +/* Total length of this read operation passed by user */ + io_op.totallen = len;
Where is this used?
Quoted 24 lines
cmd/mtd.c +0
-0/* Search for the first good block after the given offset */ off = start_off;include/linux/mtd/mtd.h +2
-1@@ -79,6 +79,7 @@ struct mtd_erase_region_info {* mode = MTD_OPS_PLACE_OOB or MTD_OPS_RAW) * @datbuf: data buffer - if NULL only oob data are read/written * @oobbuf: oob data buffer +* @totallen: total number of data bytes to read in one read operation (for continuous read mode) */ struct mtd_oob_ops {unsigned int mode;@@ -89,6 +90,7 @@ struct mtd_oob_ops {uint32_t ooboffs;uint8_t *datbuf;uint8_t *oobbuf; +size_t totallen; };#ifdef CONFIG_SYS_NAND_MAX_OOBFREE --
Quoted 2 lines
2.17.1
Thanks,
Miquèl
Re: [PATCH v2 3/5] cmd: mtd: Add total length of read operation
Hi Miquel,
Quoted 16 lines
Hi Leo,
[email protected] wrote on Wed, 2 Nov 2022 14:14:30 +0800:
Quoted 11 lines
This patch bypasses the limitation of length for read operations in MTD test module. Thus, the total length of a read operation can be passed down to the continuous read operation in SPI NAND layer.
Signed-off-by Leo Yu <[email protected]>--- cmd/mtd.c | 2 ++ include/linux/mtd/mtd.h | 2 ++ 2 files changed, 4 insertions(+)
Quoted 12 lines
cmd/mtd.c static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc, · line 339
Quoted 10 lines
cmd/mtd.c +2
-0@@ -335,6 +335,8 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc, io_op.ooblen = woob ? mtd->oobsize :0 ; io_op.datbuf = buf; io_op.oobbuf = woob ? &buf[len] :NULL ; +/* Total length of this read operation passed by user */ + io_op.totallen = len;Where is this used?
It is used in spinand_mtd_read function (drivers/mtd/nand/spi/core.c) as a condition to trigger
continuous read mode (please refer to patch[4/5]). This member stores the total length of a
read operation. The reason why this member is added is because the mtd command sets
the length of an operation to one page if has_pages flag is set. This limits spinand_mtd_read
to receive length greater than one page. Which means there is no way to trigger continuous
mode. Thus, I added this member to bypass the limitation.
Quoted 22 lines
Quoted 22 lines
cmd/mtd.c +0
-0/* Search for the first good block after the given offset */ off = start_off;include/linux/mtd/mtd.h +2
-0@@ -79,6 +79,7 @@ struct mtd_erase_region_info {* mode = MTD_OPS_PLACE_OOB or MTD_OPS_RAW) * @datbuf: data buffer - if NULL only oob data are read/written * @oobbuf: oob data buffer +* @totallen: total number of data bytes to read in one read operation (for continuous read mode) */ struct mtd_oob_ops {unsigned int mode;@@ -89,6 +90,7 @@ struct mtd_oob_ops {uint32_t ooboffs;uint8_t *datbuf;uint8_t *oobbuf; +size_t totallen; };
Quoted 8 lines
Quoted 4 lines
include/linux/mtd/mtd.h +0
-1#ifdef CONFIG_SYS_NAND_MAX_OOBFREE --2.17.1
Thanks,
Miquèl
Best,
Leo Yu
PATCH v2 4/5 mtd: spinand: Add continuous read operation
In reply to Leo YuThe flow of continuous read operation is: firstly, starting with the page read command and the 1st page data will be read into the cache after the read latency tRD. Secondly, issuing the Read From Cache commands (03h/0Bh/3Bh/6Bh/BBh/EBh) to read out the data from cache continuously. After all the data is read out, the host should pull CS# high to terminate this continuous read operation and wait tRST for the NAND device resets read operation.
The continuous read usage is enabled by reading multiple pages (at least greater than 1 page size) and the column address is "don't care" in this operation, since the data output for each page will always start from byte 0 and a full page data should be read out for each page.
On the other hand, since the continuous read mode can only read the entire page of data and cannot read the oob data, the dynamic mode switching is added to enable continuous read mode and disable continuous read mode in spinand_continuous_read to avoid abnormal writing and erasing operations.
The performance of continuous read mode is as follows. Set the flash to QSPI mode and run 25MHz direct mapping mode on the SPI bus and use the MTD test module to show the performance of continuous reads.
--- drivers/mtd/nand/spi/core.c | 120 +++++++++++++++++++++++++++++++++++- 1 file changed, 119 insertions(+), 1 deletion(-)
drivers/mtd/nand/spi/core.c +119 -1
@@ -269,7 +269,10 @@ static int spinand_read_from_cache_op(struct spinand_device *spinand,u16 column =0 ;int ret; -if (req->datalen) { +if (spinand->use_continuous_read) { + buf = req->databuf.in; + nbytes = req->datalen; + }else if (req->datalen) { adjreq.datalen =nanddev_page_size (nand); adjreq.dataoffs =0 ; adjreq.databuf.in = spinand->databuf;
@@ -312,6 +315,9 @@ static int spinand_read_from_cache_op(struct spinand_device *spinand, op.addr.val += op.data.nbytes; } +if (spinand->use_continuous_read) +return 0 ; +if (req->datalen)memcpy (req->databuf.in, spinand->databuf + req->dataoffs, req->datalen);
@@ -577,6 +583,105 @@ static int spinand_write_page(struct spinand_device *spinand,return ret; } +static int spinand_continuous_read (struct mtd_info *mtd,loff_t from, +struct mtd_oob_ops *req, +struct nand_io_iter *iter) +{ +struct spinand_device *spinand =mtd_to_spinand (mtd); +struct nand_device *nand =mtd_to_nanddev (mtd); +int ret =0 ; + +bool enable_cont_read = true; +bool enable_ecc = false; + +/* +* Since the continuous read mode can only read the entire page of data +* and cannot read the oob data, therefore, only ECC-Free SPI-NAND support +* continuous read mode now. +*/ + iter->req.mode =MTD_OPS_RAW ; + iter->req.ooblen =0 ; + + req->retlen =0 ; + +/* Read the first unaligned page with conventional read */ +if (from & (nanddev_page_size (nand) -1 )) { +pr_debug ("address not aligned\n" ); + + iter->req.databuf.in = req->datbuf; + iter->req.dataoffs =nanddev_offs_to_pos (nand, from, &iter->req.pos); + iter->req.datalen =nanddev_page_size (nand) - iter->req.dataoffs; + +schedule (); + ret =spinand_select_target (spinand, iter->req.pos.target); +if (ret) +return ret; + +spinand_read_page (spinand, &iter->req, enable_ecc); +if (ret) +return ret; + + req->retlen += iter->req.datalen; + } + + iter->req.dataoffs =nanddev_offs_to_pos (nand, from + req->retlen, &iter->req.pos); + iter->req.databuf.in = req->datbuf + req->retlen; + iter->req.datalen = req->totallen - req->retlen; + +schedule (); + ret =spinand_continuous_read_enable (spinand, enable_cont_read); +if (ret) +return ret; + + ret =spinand_select_target (spinand, iter->req.pos.target); +if (ret) { + req->retlen =0 ; + goto continuous_read_error; + } + +/* +* The continuous read operation including: firstly, starting with the +* page read command and the 1 st page data will be read into the cache +* after the read latency tRD. Secondly, Issuing the Read From Cache +* commands (03h/0Bh/3Bh/6Bh/BBh/EBh) to read out the data from cache +* continuously. +* +* The cache is divided into two halves, while one half of the cache is +* outputting the data, the other half will be loaded for the new data; +* therefore, the host can read out the data continuously from page to +* page. Multiple of Read From Cache commands can be issued in one +* continuous read operation, each Read From Cache command is required +* to read multiple 4-byte data exactly; otherwise, the data output will +* be out of sequence from one Read From Cache command to another Read +* From Cache command. +* +* After all the data is read out, the host should pull CS# high to +* terminate this continuous read operation and wait a 6us of tRST for +* the NAND device resets read operation. The data output for each page +* will always start from byte 0 and a full page data should be read out +* for each page. +*/ + ret =spinand_read_page (spinand, &iter->req, enable_ecc); +if (ret) { + req->retlen =0 ; + goto continuous_read_error; + } + + ret =spinand_reset_op (spinand); +if (ret) { + req->retlen =0 ; + goto continuous_read_error; + } + + req->retlen += iter->req.datalen; + +continuous_read_error: + enable_cont_read = false; + ret =spinand_continuous_read_enable (spinand, enable_cont_read); + +return ret; +} +static int spinand_mtd_read (struct mtd_info *mtd,loff_t from,struct mtd_oob_ops *ops) {
@@ -594,6 +699,18 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from,#ifndef __UBOOT__mutex_lock (&spinand->lock);#endif +/* +* If the device supports continuous read mode and the read length is greater +* than one page size, the device will enter the continuous read mode. This mode +* helps avoiding issuing a page read command and read from cache command +* again, and improves the performance of reading continuous pages. +*/ +if ((spinand->flags &SPINAND_HAS_CONT_READ_BIT ) && + (ops->totallen >nanddev_page_size (nand))) { + ret =spinand_continuous_read (mtd, from, ops, &iter); + + goto continuous_read_finish; + }nanddev_io_for_each_page (nand, from, ops, &iter) {schedule ();
@@ -622,6 +739,7 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from, ops->oobretlen += iter.req.ooblen; } +continuous_read_finish:#ifndef __UBOOT__mutex_unlock (&spinand->lock);#endif
--
2.17.1
PATCH v2 5/5 mtd: spinand: macronix: Add continuous read mode flag for devices
In reply to Leo YuAdd continuous read mode flag to the devices support continuous read mode in ID table.
--- drivers/mtd/nand/spi/macronix.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/mtd/nand/spi/macronix.c +5 -5
@@ -128,7 +128,7 @@ static const struct spinand_info macronix_spinand_table[] = { SPINAND_INFO_OP_VARIANTS(&read_cache_variants, &write_cache_variants, &update_cache_variants), - SPINAND_HAS_QE_BIT, + SPINAND_HAS_QE_BIT | SPINAND_HAS_CONT_READ_BIT, SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, mx35lf1ge4ab_ecc_get_status)), SPINAND_INFO("MX35UF2GE4AD", 0xa6,
@@ -137,7 +137,7 @@ static const struct spinand_info macronix_spinand_table[] = { SPINAND_INFO_OP_VARIANTS(&read_cache_variants, &write_cache_variants, &update_cache_variants), - SPINAND_HAS_QE_BIT, + SPINAND_HAS_QE_BIT | SPINAND_HAS_CONT_READ_BIT, SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, mx35lf1ge4ab_ecc_get_status)), SPINAND_INFO("MX35UF2GE4AC", 0xa2,
@@ -146,7 +146,7 @@ static const struct spinand_info macronix_spinand_table[] = { SPINAND_INFO_OP_VARIANTS(&read_cache_variants, &write_cache_variants, &update_cache_variants), - SPINAND_HAS_QE_BIT, + SPINAND_HAS_QE_BIT | SPINAND_HAS_CONT_READ_BIT, SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, mx35lf1ge4ab_ecc_get_status)), SPINAND_INFO("MX35UF1GE4AD", 0x96,
@@ -155,7 +155,7 @@ static const struct spinand_info macronix_spinand_table[] = { SPINAND_INFO_OP_VARIANTS(&read_cache_variants, &write_cache_variants, &update_cache_variants), - SPINAND_HAS_QE_BIT, + SPINAND_HAS_QE_BIT | SPINAND_HAS_CONT_READ_BIT, SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, mx35lf1ge4ab_ecc_get_status)), SPINAND_INFO("MX35UF1GE4AC", 0x92,
@@ -164,7 +164,7 @@ static const struct spinand_info macronix_spinand_table[] = {SPINAND_INFO_OP_VARIANTS (&read_cache_variants, &write_cache_variants, &update_cache_variants), -SPINAND_HAS_QE_BIT , +SPINAND_HAS_QE_BIT |SPINAND_HAS_CONT_READ_BIT ,SPINAND_ECCINFO (&mx35lfxge4ab_ooblayout, mx35lf1ge4ab_ecc_get_status)),
--
2.17.1