Skip to contentSkip to conversation

MTK NAND driver improvements and fixes

PATCH Applied Xiaolei Li 4 participants 12 messages May 7, 2019 – Jun 3, 2019 3 messages not in the archive

Subsystems (5)
lore
Share & tools
lore

Xiaolei Li

author
#0 lore raw

v3 cover MTK NAND driver improvements and fixes

The following patch set mainly contains:
* Fix low level time calculation of read/write cycle to meet tRC_min and tWC_min requirements.
* Refine RE# pulse width calculation and data sampling to improve read performance.
* Add CS validity check.
* Fix oob buffer pointer wrongly setting.

Changes on v3 relative to:
--------------------

tree : https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git/
branch : nand/next
commit :
'commit 1c14fe2167ef ("mtd: nandsim: switch to exec_op interface")

Patch v3:
---------
- Fix some comment style.
- Format patch base branch: nand/next
- Pend to sent patch "mtd: rawnand: mtk: Setup empty page threshold correctly", because it seems that we should confirm this change has no side effect and need more test.

Patch v2:
---------
- Fix type
- Reference correct faulty patch
- Refine code to do calculation and condition in separate steps
- Fix empty threshold calculation

Tests:
------

* ubifs and jffs2 are validated on NAND device MT29F16G08ADBCA by 'dd' command.
* all drivers/mtd/tests/* pass.
* speed test:
eraseblock write speed is 11087 KiB/s
eraseblock read speed is 19986 KiB/s
page write speed is 10689 KiB/s
page read speed is 18724 KiB/s
2 page write speed is 10611 KiB/s
2 page read speed is 18713 KiB/s
erase speed is 103696 KiB/s
2x multi-block erase speed is 354248 KiB/s
4x multi-block erase speed is 350459 KiB/s
8x multi-block erase speed is 356173 KiB/s
16x multi-block erase speed is 356173 KiB/s
32x multi-block erase speed is 358120 KiB/s
64x multi-block erase speed is 356173 KiB/s

Xiaolei Li (4):
mtd: rawnand: mtk: Correct low level time calculation of r/w cycle
mtd: rawnand: mtk: Improve data sampling timing for read cycle
mtd: rawnand: mtk: Add validity check for CE# pin setting
mtd: rawnand: mtk: Fix wrongly assigned OOB buffer pointer issue

 drivers/mtd/nand/raw/mtk_nand.c | 84 +++++++++++++++++++++++++++------
 1 file changed, 70 insertions(+), 14 deletions(-)
Signature · 7 lines
2.18.0



______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
author
#1 lore raw

PATCH v3 1/4 mtd: rawnand: mtk: Correct low level time calculation of r/w cycle

At present, the flow of calculating AC timing of read/write cycle in SDR mode is that:
At first, calculate high hold time which is valid for both read and write cycle using the max value between tREH_min and tWH_min. Secondly, calculate WE# pulse width using tWP_min.
Thridly, calculate RE# pulse width using the bigger one between tREA_max and tRP_min.

But NAND SPEC shows that Controller should also meet write/read cycle time. That is write cycle time should be more than tWC_min and read cycle should be more than tRC_min. Obviously, we do not achieve that now.

This patch corrects the low level time calculation to meet minimum read/write cycle time required. After getting the high hold time, WE# low level time will be promised to meet tWP_min and tWC_min requirement, and RE# low level time will be promised to meet tREA_max, tRP_min and tRC_min requirement.

Fixes edfee3619c49 ("mtd: nand: mtk: add ->setup_data_interface() hook")
Cc [email protected] # v4.17+
---
 drivers/mtd/nand/raw/mtk_nand.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
drivers/mtd/nand/raw/mtk_nand.c +21 -3
index b17619f30b1b..717f17bcffb4 100644
@@ -508,7 +508,8 @@ static int mtk_nfc_setup_data_interface(struct nand_chip *chip, int csline,
 {
 	struct mtk_nfc *nfc = nand_get_controller_data(chip);
 	const struct nand_sdr_timings *timings;
-	u32 rate, tpoecs, tprecs, tc2r, tw2r, twh, twst, trlt;
+	u32 rate, tpoecs, tprecs, tc2r, tw2r, twh, twst = 0, trlt = 0;
+	u32 thold;
 
 	timings = nand_get_sdr_timings(conf);
 	if (IS_ERR(timings))
@@ -544,11 +545,28 @@ static int mtk_nfc_setup_data_interface(struct nand_chip *chip, int csline,
 	twh = DIV_ROUND_UP(twh * rate, 1000000) - 1;
 	twh &= 0xf;
 
-	twst = timings->tWP_min / 1000;
+	/* Calculate real WE#/RE# hold time in nanosecond */
+	thold = (twh + 1) * 1000000 / rate;
+	/* nanosecond to picosecond */
+	thold *= 1000;
+
+	/*
+	 * WE# low level time should be expaned to meet WE# pulse time
+	 * and WE# cycle time at the same time.
+	 */
+	if (thold < timings->tWC_min)
+		twst = timings->tWC_min - thold;
+	twst = max(timings->tWP_min, twst) / 1000;
 	twst = DIV_ROUND_UP(twst * rate, 1000000) - 1;
 	twst &= 0xf;
 
-	trlt = max(timings->tREA_max, timings->tRP_min) / 1000;
+	/*
+	 * RE# low level time should be expaned to meet RE# pulse time,
+	 * RE# access time and RE# cycle time at the same time.
+	 */
+	if (thold < timings->tRC_min)
+		trlt = timings->tRC_min - thold;
+	trlt = max3(trlt, timings->tREA_max, timings->tRP_min) / 1000;
 	trlt = DIV_ROUND_UP(trlt * rate, 1000000) - 1;
 	trlt &= 0xf;
 
Signature · 1 line
2.18.0
maintainer Applied
#2 lore raw

Re: [PATCH v3 1/4] mtd: rawnand: mtk: Correct low level time calculation of r/w cycle

Quoted 18 lines · Xiaolei Li

At present, the flow of calculating AC timing of read/write cycle in SDR mode is that:
At first, calculate high hold time which is valid for both read and write cycle using the max value between tREH_min and tWH_min. Secondly, calculate WE# pulse width using tWP_min.
Thridly, calculate RE# pulse width using the bigger one between tREA_max and tRP_min.

But NAND SPEC shows that Controller should also meet write/read cycle time. That is write cycle time should be more than tWC_min and read cycle should be more than tRC_min. Obviously, we do not achieve that now.

This patch corrects the low level time calculation to meet minimum read/write cycle time required. After getting the high hold time, WE# low level time will be promised to meet tWP_min and tWC_min requirement, and RE# low level time will be promised to meet tREA_max, tRP_min and tRC_min requirement.

Quoted 4 lines
Fixes edfee3619c49 ("mtd: nand: mtk: add ->setup_data_interface() hook")
Cc [email protected] # v4.17+

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

Miquel

author
#3 lore raw

PATCH v3 2/4 mtd: rawnand: mtk: Improve data sampling timing for read cycle

In reply to Xiaolei Li

Currently, we expand RE# low level time by choosing the max value between RE# pulse width and RE# access time, and sample data at the rising edge of RE#.

Then, if RE# access time is bigger than RE# pulse width, the real read cycle time may be more than NAND SPEC required. This makes read performance be worse than that expected.

This patch improves data sampling timing by calculating RE# low level time according to RE# pulse width. If RE# access time is bigger than RE# pulse width, then delay sampling data timing.

The result of contrast test base on MT2712 evaluat board is as follow.

nand: Micron MT29F16G08ADBCAH4
nand: 2048 MiB, SLC, erase size: 256 KiB, page size: 4096, OOB size: 224 NFI 2x clock rate: 124800000 HZ.

Read speed without this patch:
mtd_speedtest: page read speed is 14012 KiB/s
mtd_speedtest: 2 page read speed is 14860 KiB/s

Read speed with this patch:
mtd_speedtest: page read speed is 18724 KiB/s
mtd_speedtest: 2 page read speed is 18713 KiB/s

---
 drivers/mtd/nand/raw/mtk_nand.c | 46 ++++++++++++++++++++++++++-------
 1 file changed, 36 insertions(+), 10 deletions(-)
drivers/mtd/nand/raw/mtk_nand.c +36 -10
index 717f17bcffb4..6b79a0f9aef8 100644
@@ -87,6 +87,10 @@
 #define NFI_FDMM(x)		(0xA4 + (x) * sizeof(u32) * 2)
 #define NFI_FDM_MAX_SIZE	(8)
 #define NFI_FDM_MIN_SIZE	(1)
+#define NFI_DEBUG_CON1		(0x220)
+#define		STROBE_MASK		GENMASK(4, 3)
+#define		STROBE_SHIFT		(3)
+#define		MAX_STROBE_DLY		(3)
 #define NFI_MASTER_STA		(0x224)
 #define		MASTER_STA_MASK		(0x0FFF)
 #define NFI_EMPTY_THRESH	(0x23C)
@@ -509,7 +513,7 @@ static int mtk_nfc_setup_data_interface(struct nand_chip *chip, int csline,
 	struct mtk_nfc *nfc = nand_get_controller_data(chip);
 	const struct nand_sdr_timings *timings;
 	u32 rate, tpoecs, tprecs, tc2r, tw2r, twh, twst = 0, trlt = 0;
-	u32 thold;
+	u32 temp, tsel = 0;
 
 	timings = nand_get_sdr_timings(conf);
 	if (IS_ERR(timings))
@@ -546,30 +550,52 @@ static int mtk_nfc_setup_data_interface(struct nand_chip *chip, int csline,
 	twh &= 0xf;
 
 	/* Calculate real WE#/RE# hold time in nanosecond */
-	thold = (twh + 1) * 1000000 / rate;
+	temp = (twh + 1) * 1000000 / rate;
 	/* nanosecond to picosecond */
-	thold *= 1000;
+	temp *= 1000;
 
 	/*
 	 * WE# low level time should be expaned to meet WE# pulse time
 	 * and WE# cycle time at the same time.
 	 */
-	if (thold < timings->tWC_min)
-		twst = timings->tWC_min - thold;
+	if (temp < timings->tWC_min)
+		twst = timings->tWC_min - temp;
 	twst = max(timings->tWP_min, twst) / 1000;
 	twst = DIV_ROUND_UP(twst * rate, 1000000) - 1;
 	twst &= 0xf;
 
 	/*
-	 * RE# low level time should be expaned to meet RE# pulse time,
-	 * RE# access time and RE# cycle time at the same time.
+	 * RE# low level time should be expaned to meet RE# pulse time
+	 * and RE# cycle time at the same time.
 	 */
-	if (thold < timings->tRC_min)
-		trlt = timings->tRC_min - thold;
-	trlt = max3(trlt, timings->tREA_max, timings->tRP_min) / 1000;
+	if (temp < timings->tRC_min)
+		trlt = timings->tRC_min - temp;
+	trlt = max(trlt, timings->tRP_min) / 1000;
 	trlt = DIV_ROUND_UP(trlt * rate, 1000000) - 1;
 	trlt &= 0xf;
 
+	/* Calculate RE# pulse time in nanosecond. */
+	temp = (trlt + 1) * 1000000 / rate;
+	/* nanosecond to picosecond */
+	temp *= 1000;
+	/*
+	 * If RE# access time is bigger than RE# pulse time,
+	 * delay sampling data timing.
+	 */
+	if (temp < timings->tREA_max) {
+		tsel = timings->tREA_max / 1000;
+		tsel = DIV_ROUND_UP(tsel * rate, 1000000);
+		tsel -= (trlt + 1);
+		if (tsel > MAX_STROBE_DLY) {
+			trlt += tsel - MAX_STROBE_DLY;
+			tsel = MAX_STROBE_DLY;
+		}
+	}
+	temp = nfi_readl(nfc, NFI_DEBUG_CON1);
+	temp &= ~STROBE_MASK;
+	temp |= tsel << STROBE_SHIFT;
+	nfi_writel(nfc, temp, NFI_DEBUG_CON1);
+
 	/*
 	 * ACCON: access timing control register
 	 * -------------------------------------
Signature · 6 lines
2.18.0


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

A message that is not in the archive (sent off-list or not yet received): 20190507102541.34341-3-xiaolei.li-NuS5LvNUpcJWk0Htik3J/[email protected]

#5 lore raw

Re: [PATCH v3 2/4] mtd: rawnand: mtk: Improve data sampling timing for read cycle

Quoted 22 lines · Xiaolei Li

Currently, we expand RE# low level time by choosing the max value between RE# pulse width and RE# access time, and sample data at the rising edge of RE#.

Then, if RE# access time is bigger than RE# pulse width, the real read cycle time may be more than NAND SPEC required. This makes read performance be worse than that expected.

This patch improves data sampling timing by calculating RE# low level time according to RE# pulse width. If RE# access time is bigger than RE# pulse width, then delay sampling data timing.

The result of contrast test base on MT2712 evaluat board is as follow.

nand: Micron MT29F16G08ADBCAH4
nand: 2048 MiB, SLC, erase size: 256 KiB, page size: 4096, OOB size: 224 NFI 2x clock rate: 124800000 HZ.

Read speed without this patch:
mtd_speedtest: page read speed is 14012 KiB/s
mtd_speedtest: 2 page read speed is 14860 KiB/s

Quoted 6 lines

Read speed with this patch:
mtd_speedtest: page read speed is 18724 KiB/s
mtd_speedtest: 2 page read speed is 18713 KiB/s

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

Miquel

author
#6 lore raw

PATCH v3 3/4 mtd: rawnand: mtk: Add validity check for CE# pin setting

In reply to Xiaolei Li

Currently, we only check how many CE# pins are set in device tree. But it should be necessary to check whether CE# pin setting is duplicated or if CE# pin index exceeds the maximum CE# number that controller supports.

So, add validity check to avoid these invalid settings.

---
 drivers/mtd/nand/raw/mtk_nand.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/mtd/nand/raw/mtk_nand.c +13 -0
index 6b79a0f9aef8..14a9b8c2a8db 100644
@@ -162,6 +162,8 @@ struct mtk_nfc {
 	struct list_head chips;
 
 	u8 *buffer;
+
+	unsigned long assigned_cs;
 };
 
 /*
@@ -1367,6 +1369,17 @@ static int mtk_nfc_nand_chip_init(struct device *dev, struct mtk_nfc *nfc,
 			dev_err(dev, "reg property failure : %d\n", ret);
 			return ret;
 		}
+
+		if (tmp >= MTK_NAND_MAX_NSELS) {
+			dev_err(dev, "invalid CS: %u\n", tmp);
+			return -EINVAL;
+		}
+
+		if (test_and_set_bit(tmp, &nfc->assigned_cs)) {
+			dev_err(dev, "CS %u already assigned\n", tmp);
+			return -EINVAL;
+		}
+
 		chip->sels[i] = tmp;
 	}
 
Signature · 6 lines
2.18.0


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

A message that is not in the archive (sent off-list or not yet received): 20190507102541.34341-4-xiaolei.li-NuS5LvNUpcJWk0Htik3J/[email protected]

#8 lore raw

Re: [PATCH v3 3/4] mtd: rawnand: mtk: Add validity check for CE# pin setting

Quoted 9 lines · Xiaolei Li

Currently, we only check how many CE# pins are set in device tree. But it should be necessary to check whether CE# pin setting is duplicated or if CE# pin index exceeds the maximum CE# number that controller supports.

So, add validity check to avoid these invalid settings.

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

Miquel

author
#9 lore raw

PATCH v3 4/4 mtd: rawnand: mtk: Fix wrongly assigned OOB buffer pointer issue

In reply to Xiaolei Li

One main goal of the function mtk_nfc_update_ecc_stats is to check whether sectors are all empty. If they are empty, set these sectors's data buffer and OOB buffer as 0xff.

But now, the sector OOB buffer pointer is wrongly assigned. We always do memset from sector 0.

To fix this issue, pass start sector number to make OOB buffer pointer be properly assigned.

Fixes 1d6b1e464950 ("mtd: mediatek: driver for MTK Smart Device")
---
 drivers/mtd/nand/raw/mtk_nand.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/mtd/nand/raw/mtk_nand.c +10 -11
index 14a9b8c2a8db..617f9656a045 100644
@@ -889,19 +889,21 @@ static int mtk_nfc_write_oob_std(struct nand_chip *chip, int page)
 	return mtk_nfc_write_page_raw(chip, NULL, 1, page);
 }
 
-static int mtk_nfc_update_ecc_stats(struct mtd_info *mtd, u8 *buf, u32 sectors)
+static int mtk_nfc_update_ecc_stats(struct mtd_info *mtd, u8 *buf, u32 start,
+				    u32 sectors)
 {
 	struct nand_chip *chip = mtd_to_nand(mtd);
 	struct mtk_nfc *nfc = nand_get_controller_data(chip);
 	struct mtk_nfc_nand_chip *mtk_nand = to_mtk_nand(chip);
 	struct mtk_ecc_stats stats;
+	u32 reg_size = mtk_nand->fdm.reg_size;
 	int rc, i;
 
 	rc = nfi_readl(nfc, NFI_STA) & STA_EMP_PAGE;
 	if (rc) {
 		memset(buf, 0xff, sectors * chip->ecc.size);
 		for (i = 0; i < sectors; i++)
-			memset(oob_ptr(chip, i), 0xff, mtk_nand->fdm.reg_size);
+			memset(oob_ptr(chip, start + i), 0xff, reg_size);
 		return 0;
 	}
 
@@ -921,7 +923,7 @@ static int mtk_nfc_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
 	u32 spare = mtk_nand->spare_per_sector;
 	u32 column, sectors, start, end, reg;
 	dma_addr_t addr;
-	int bitflips;
+	int bitflips = 0;
 	size_t len;
 	u8 *buf;
 	int rc;
@@ -988,14 +990,11 @@ static int mtk_nfc_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
 	if (rc < 0) {
 		dev_err(nfc->dev, "subpage done timeout\n");
 		bitflips = -EIO;
-	} else {
-		bitflips = 0;
-		if (!raw) {
-			rc = mtk_ecc_wait_done(nfc->ecc, ECC_DECODE);
-			bitflips = rc < 0 ? -ETIMEDOUT :
-				mtk_nfc_update_ecc_stats(mtd, buf, sectors);
-			mtk_nfc_read_fdm(chip, start, sectors);
-		}
+	} else if (!raw) {
+		rc = mtk_ecc_wait_done(nfc->ecc, ECC_DECODE);
+		bitflips = rc < 0 ? -ETIMEDOUT :
+			mtk_nfc_update_ecc_stats(mtd, buf, start, sectors);
+		mtk_nfc_read_fdm(chip, start, sectors);
 	}
 
 	dma_unmap_single(nfc->dev, addr, len, DMA_FROM_DEVICE);
Signature · 6 lines
2.18.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer Applied
#10 lore raw

Re: [PATCH v3 4/4] mtd: rawnand: mtk: Fix wrongly assigned OOB buffer pointer issue

Quoted 7 lines · Xiaolei Li

One main goal of the function mtk_nfc_update_ecc_stats is to check whether sectors are all empty. If they are empty, set these sectors's data buffer and OOB buffer as 0xff.

But now, the sector OOB buffer pointer is wrongly assigned. We always do memset from sector 0.

Quoted 6 lines

To fix this issue, pass start sector number to make OOB buffer pointer be properly assigned.

Fixes 1d6b1e464950 ("mtd: mediatek: driver for MTK Smart Device")

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/

A message that is not in the archive (sent off-list or not yet received): 20190507102541.34341-1-xiaolei.li-NuS5LvNUpcJWk0Htik3J/[email protected]

#12 lore raw

Hi Miquel,

Sorry to bother you, but may I ask if it is fine to accept this patch set now, patches all with your review.

Thanks,
Xiaolei

Quoted 61 lines · Xiaolei Li

The following patch set mainly contains:
* Fix low level time calculation of read/write cycle to meet tRC_min and tWC_min requirements.
* Refine RE# pulse width calculation and data sampling to improve read performance.
* Add CS validity check.
* Fix oob buffer pointer wrongly setting.

Changes on v3 relative to:
--------------------

tree : https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git/
branch : nand/next
commit :
'commit 1c14fe2167ef ("mtd: nandsim: switch to exec_op interface")

Patch v3:
---------
- Fix some comment style.
- Format patch base branch: nand/next
- Pend to sent patch "mtd: rawnand: mtk: Setup empty page threshold correctly", because it seems that we should confirm this change has no side effect and need more test.

Patch v2:
---------
- Fix type
- Reference correct faulty patch
- Refine code to do calculation and condition in separate steps
- Fix empty threshold calculation

Tests:
------

* ubifs and jffs2 are validated on NAND device MT29F16G08ADBCA by 'dd' command.
* all drivers/mtd/tests/* pass.
* speed test:
eraseblock write speed is 11087 KiB/s
eraseblock read speed is 19986 KiB/s
page write speed is 10689 KiB/s
page read speed is 18724 KiB/s
2 page write speed is 10611 KiB/s
2 page read speed is 18713 KiB/s
erase speed is 103696 KiB/s
2x multi-block erase speed is 354248 KiB/s
4x multi-block erase speed is 350459 KiB/s
8x multi-block erase speed is 356173 KiB/s
16x multi-block erase speed is 356173 KiB/s
32x multi-block erase speed is 358120 KiB/s
64x multi-block erase speed is 356173 KiB/s

Xiaolei Li (4):
mtd: rawnand: mtk: Correct low level time calculation of r/w cycle
mtd: rawnand: mtk: Improve data sampling timing for read cycle
mtd: rawnand: mtk: Add validity check for CE# pin setting
mtd: rawnand: mtk: Fix wrongly assigned OOB buffer pointer issue

 drivers/mtd/nand/raw/mtk_nand.c | 84 +++++++++++++++++++++++++++------
 1 file changed, 70 insertions(+), 14 deletions(-)
#13 lore raw

Hi xiaolei,

xiaolei li <[email protected]> wrote on Fri, 17 May 2019 09:32:47 +0800:

Quoted 4 lines

Hi Miquel,

Sorry to bother you, but may I ask if it is fine to accept this patch set now, patches all with your review.

We are in the middle of the merge window, so yes, I will take your patches, but not now.

Thanks,
Miquèl

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

author
#14 lore raw
Quoted 5 lines · Miquel Raynal

Hi xiaolei,

xiaolei li <[email protected]> wrote on Fri, 17 May 2019 09:32:47 +0800:

Quoted 7 lines
Quoted 4 lines

Hi Miquel,

Sorry to bother you, but may I ask if it is fine to accept this patch set now, patches all with your review.

We are in the middle of the merge window, so yes, I will take your patches, but not now.

Got it. Thanks Miquel.

Quoted 3 lines

Thanks,
Miquèl

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