Skip to contentSkip to conversation

MTK NAND driver improvements and fixes

PATCH Superseded Xiaolei Li 3 participants 17 messages Apr 29, 2019 – Apr 30, 2019 5 messages not in the archive

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Xiaolei Li

author
#0 lore raw

cover MTK NAND driver improvements and fixes

Hello Maintainers,

The following patch set is used to do MTK NAND driver improvements and bug fixes, include:
* 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 and empty page threshold setting.

Changes relative to:
--------------------

tree : git://git.infradead.org/linux-mtd.git
branch : master
commit :

        'commit 3e35730dd754 ("mtd: powernv_flash: Fix device
         registration error")

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 (5):
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
mtd: rawnand: mtk: Setup empty page threshold correctly

 drivers/mtd/nand/raw/mtk_nand.c | 73 ++++++++++++++++++++++++++-------
 1 file changed, 59 insertions(+), 14 deletions(-)

--
2.18.0

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

author
#1 lore raw

PATCH 1/5 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 93db446a424c ("mtd: nand: move raw NAND related code to the raw/ subdir")
---
 drivers/mtd/nand/raw/mtk_nand.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/mtd/nand/raw/mtk_nand.c +11 -3
index b6b4602f5132..dd855f860a4b 100644
@@ -508,7 +508,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, trlt;
+	u32 rate, tpoecs, tprecs, tc2r, tw2r, twh, twst = 0, trlt = 0;
 
 	timings = nand_get_sdr_timings(conf);
 	if (IS_ERR(timings))
@@ -544,11 +544,19 @@ 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 min low level timing for write cycle */
+	if ((twh + 1) * 1000000 / rate < timings->tWC_min / 1000)
+		twst = (timings->tWC_min / 1000 - (twh + 1) * 1000000 / rate)
+			* 1000;
+	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;
+	/* Calculate min low level timing for read cycle */
+	if ((twh + 1) * 1000000 / rate < timings->tRC_min / 1000)
+		trlt = (timings->tRC_min / 1000 - (twh + 1) * 1000000 / rate)
+			* 1000;
+	trlt = max3(trlt, timings->tREA_max, timings->tRP_min) / 1000;
 	trlt = DIV_ROUND_UP(trlt * rate, 1000000) - 1;
 	trlt &= 0xf;
 
Signature · 6 lines
2.18.0


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

PATCH 2/5 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.

Test tool: mtd_speedtest.ko

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 | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/mtd/nand/raw/mtk_nand.c +21 -1
index dd855f860a4b..a2f7af536380 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,6 +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 tsel, reg;
 
 	timings = nand_get_sdr_timings(conf);
 	if (IS_ERR(timings))
@@ -556,10 +561,25 @@ static int mtk_nfc_setup_data_interface(struct nand_chip *chip, int csline,
 	if ((twh + 1) * 1000000 / rate < timings->tRC_min / 1000)
 		trlt = (timings->tRC_min / 1000 - (twh + 1) * 1000000 / rate)
 			* 1000;
-	trlt = max3(trlt, timings->tREA_max, timings->tRP_min) / 1000;
+	trlt = max(trlt, timings->tRP_min) / 1000;
 	trlt = DIV_ROUND_UP(trlt * rate, 1000000) - 1;
 	trlt &= 0xf;
 
+	/* Calculate strobe sel */
+	reg = nfi_readl(nfc, NFI_DEBUG_CON1);
+	reg &= ~STROBE_MASK;
+	if ((trlt + 1) * 1000000 / rate < timings->tREA_max / 1000) {
+		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;
+		}
+		reg |= tsel << STROBE_SHIFT;
+	}
+	nfi_writel(nfc, reg, 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/
author
#11 lore raw

PATCH 3/5 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 a2f7af536380..7a5e8c9cf61b 100644
@@ -162,6 +162,8 @@ struct mtk_nfc {
 	struct list_head chips;
 
 	u8 *buffer;
+
+	unsigned long assigned_cs;
 };
 
 /*
@@ -1351,6 +1353,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/
author
#14 lore raw

PATCH 4/5 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 secotr number to make oob buffer pointer be properly assigned.

Fixes 93db446a424c ("mtd: nand: move raw NAND related code to the raw/ subdir")
---
 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 7a5e8c9cf61b..cf5e50e704ae 100644
@@ -873,19 +873,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;
 	}
 
@@ -905,7 +907,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;
@@ -972,14 +974,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/
author
#18 lore raw

PATCH 5/5 mtd: rawnand: mtk: Setup empty page threshold correctly

In reply to Xiaolei Li

MTK NAND Controller has the ability to check whether read data are mostly 0xff by comparing zero bit conut of read data with empty threshold automatically.

But now we never set this threshold and always make it be default value which is 10.

This patch fixes this problem by setting empty threshold as the product of read sector count and ecc strength.

Fixes 93db446a424c ("mtd: nand: move raw NAND related code to the raw/ subdir")
---
 drivers/mtd/nand/raw/mtk_nand.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/mtd/nand/raw/mtk_nand.c +5 -0
index cf5e50e704ae..675d4faa3480 100644
@@ -94,6 +94,7 @@
 #define NFI_MASTER_STA		(0x224)
 #define		MASTER_STA_MASK		(0x0FFF)
 #define NFI_EMPTY_THRESH	(0x23C)
+#define		EMPTY_THRESH_MASK	GENMASK(7, 0)
 
 #define MTK_NAME		"mtk-nand"
 #define KB(x)			((x) * 1024UL)
@@ -931,6 +932,10 @@ static int mtk_nfc_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
 		return -EINVAL;
 	}
 
+	/* Setup empty threshold */
+	reg = max(sectors * chip->ecc.strength, EMPTY_THRESH_MASK);
+	nfi_writel(nfc, reg, NFI_EMPTY_THRESH);
+
 	reg = nfi_readw(nfc, NFI_CNFG);
 	reg |= CNFG_READ_EN | CNFG_DMA_BURST_EN | CNFG_AHB;
 	if (!raw) {
Signature · 6 lines
2.18.0


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

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

In reply to a message not in the archive

Hi Xiaolei,

Xiaolei Li <[email protected]> wrote on Mon, 29 Apr 2019 14:38:30 +0800:

Quoted 12 lines

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.

Quoted 7 lines

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 93db446a424c ("mtd: nand: move raw NAND related code to the raw/ subdir")

This is definitely not the faulty patch. Please use --follow when searching for the culprit, to avoid being blocked by the renaming/moving work.

Also a Cc: stable might be worth.

Quoted 30 lines
---
 drivers/mtd/nand/raw/mtk_nand.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/mtd/nand/raw/mtk_nand.c +6 -2
index b6b4602f5132..dd855f860a4b 100644
@@ -508,7 +508,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, trlt;
+	u32 rate, tpoecs, tprecs, tc2r, tw2r, twh, twst = 0, trlt = 0;
 
 	timings = nand_get_sdr_timings(conf);
 	if (IS_ERR(timings))
@@ -544,11 +544,19 @@ 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 min low level timing for write cycle */
+	if ((twh + 1) * 1000000 / rate < timings->tWC_min / 1000)
+		twst = (timings->tWC_min / 1000 - (twh + 1) * 1000000 / rate)
+			* 1000;
+	twst = max(timings->tWP_min, twst) / 1000;
 	twst = DIV_ROUND_UP(twst * rate, 1000000) - 1;
 	twst &= 0xf;

drivers/mtd/nand/raw/mtk_nand.c static int mtk_nfc_setup_data_interface(struct nand_chip *chip, int csline, · line 562

Quoted 10 lines
drivers/mtd/nand/raw/mtk_nand.c +5 -1
 
-	trlt = max(timings->tREA_max, timings->tRP_min) / 1000;
+	/* Calculate min low level timing for read cycle */
+	if ((twh + 1) * 1000000 / rate < timings->tRC_min / 1000)
+		trlt = (timings->tRC_min / 1000 - (twh + 1) * 1000000 / rate)
+			* 1000;
+	trlt = max3(trlt, timings->tREA_max, timings->tRP_min) / 1000;
 	trlt = DIV_ROUND_UP(trlt * rate, 1000000) - 1;
 	trlt &= 0xf;
 

With this fixed,

Thanks,
Miquèl

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

#9 lore raw

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

In reply to a message not in the archive

Hi Xiaolei,

Xiaolei Li <[email protected]> wrote on Mon, 29 Apr 2019 14:38:31 +0800:

Quoted 60 lines

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.

Test tool: mtd_speedtest.ko

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 | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/mtd/nand/raw/mtk_nand.c +5 -0
index dd855f860a4b..a2f7af536380 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,6 +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 tsel, reg;
 
 	timings = nand_get_sdr_timings(conf);
 	if (IS_ERR(timings))
@@ -556,10 +561,25 @@ static int mtk_nfc_setup_data_interface(struct nand_chip *chip, int csline,
 	if ((twh + 1) * 1000000 / rate < timings->tRC_min / 1000)
 		trlt = (timings->tRC_min / 1000 - (twh + 1) * 1000000 / rate)

drivers/mtd/nand/raw/mtk_nand.c static int mtk_nfc_setup_data_interface(struct nand_chip *chip, int csline, · line 571

Quoted 10 lines
drivers/mtd/nand/raw/mtk_nand.c +5 -1
 			* 1000;
-	trlt = max3(trlt, timings->tREA_max, timings->tRP_min) / 1000;
+	trlt = max(trlt, timings->tRP_min) / 1000;
 	trlt = DIV_ROUND_UP(trlt * rate, 1000000) - 1;
 	trlt &= 0xf;
 
+	/* Calculate strobe sel */
+	reg = nfi_readl(nfc, NFI_DEBUG_CON1);
+	reg &= ~STROBE_MASK;
+	if ((trlt + 1) * 1000000 / rate < timings->tREA_max / 1000) {

Please do the calculation and condition in separate step, this is hardly readable. Maybe you can explain it with a comment as well.

drivers/mtd/nand/raw/mtk_nand.c static int mtk_nfc_setup_data_interface(struct nand_chip *chip, int csline, · line 573

Quoted 2 lines
drivers/mtd/nand/raw/mtk_nand.c +2 -0
+		tsel = timings->tREA_max / 1000;
+		tsel = DIV_ROUND_UP(tsel * rate, 1000000);

Are you sure tsel * rate cannot overflow?

drivers/mtd/nand/raw/mtk_nand.c static int mtk_nfc_setup_data_interface(struct nand_chip *chip, int csline, · line 585

Quoted 12 lines
drivers/mtd/nand/raw/mtk_nand.c +9 -0
+		tsel -= (trlt + 1);
+		if (tsel > MAX_STROBE_DLY) {
+			trlt += tsel - MAX_STROBE_DLY;
+			tsel = MAX_STROBE_DLY;
+		}
+		reg |= tsel << STROBE_SHIFT;
+	}
+	nfi_writel(nfc, reg, NFI_DEBUG_CON1);
+
 	/*
 	 * ACCON: access timing control register
 	 * -------------------------------------

Thanks,
Miquèl

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

Reviewed-by
#13 lore raw

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

In reply to a message not in the archive

Hi Xiaolei,

Xiaolei Li <[email protected]> wrote on Mon, 29 Apr 2019 14:38:32 +0800:

Quoted 33 lines

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 +6 -0
index a2f7af536380..7a5e8c9cf61b 100644
@@ -162,6 +162,8 @@ struct mtk_nfc {
 	struct list_head chips;
 
 	u8 *buffer;
+
+	unsigned long assigned_cs;
 };
 
 /*
@@ -1351,6 +1353,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;

drivers/mtd/nand/raw/mtk_nand.c static int mtk_nfc_nand_chip_init(struct device *dev, struct mtk_nfc *nfc, · line 1369

Quoted 10 lines
drivers/mtd/nand/raw/mtk_nand.c +7 -0
+		}
+
+		if (test_and_set_bit(tmp, &nfc->assigned_cs)) {
+			dev_err(dev, "CS %u already assigned\n", tmp);
+			return -EINVAL;
+		}
+
 		chip->sels[i] = tmp;
 	}
 

Thanks,
Miquèl

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

Reviewed-by
#16 lore raw

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

In reply to a message not in the archive

Hi Xiaolei,

Xiaolei Li <[email protected]> wrote on Mon, 29 Apr 2019 14:38:33 +0800:

Quoted 8 lines

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 secotr number to make oob buffer pointer

sector

Quoted 1 line

be properly assigned.

Please use upper case for plain English acronyms: NAND, ECC, OOB, etc.

Quoted 2 lines
Fixes 93db446a424c ("mtd: nand: move raw NAND related code to the raw/ subdir")

Same comment as before, wrong commit pointed in the Fixes tag.

Quoted 52 lines
---
 drivers/mtd/nand/raw/mtk_nand.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/mtd/nand/raw/mtk_nand.c +5 -9
index 7a5e8c9cf61b..cf5e50e704ae 100644
@@ -873,19 +873,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;
 	}
 
@@ -905,7 +907,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;
@@ -972,14 +974,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);

drivers/mtd/nand/raw/mtk_nand.c static int mtk_nfc_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, · line 984

Quoted 10 lines
drivers/mtd/nand/raw/mtk_nand.c +5 -2
-			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);

With this addressed:

Thanks,
Miquèl

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

#20 lore raw

Re: [PATCH 5/5] mtd: rawnand: mtk: Setup empty page threshold correctly

In reply to a message not in the archive

Hi Xiaolei,

Xiaolei Li <[email protected]> wrote on Mon, 29 Apr 2019 14:38:34 +0800:

Quoted 2 lines

MTK NAND Controller has the ability to check whether read data are mostly 0xff by comparing zero bit conut of read data with empty

count ?

Quoted 7 lines

threshold automatically.

But now we never set this threshold and always make it be default value which is 10.

This patch fixes this problem by setting empty threshold as the product of read sector count and ecc strength.

Do we use these feature yet?

s/ecc/ECC/

Quoted 2 lines
Fixes 93db446a424c ("mtd: nand: move raw NAND related code to the raw/ subdir")

Ditto.

Quoted 18 lines
---
 drivers/mtd/nand/raw/mtk_nand.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/mtd/nand/raw/mtk_nand.c +1 -0
index cf5e50e704ae..675d4faa3480 100644
@@ -94,6 +94,7 @@
 #define NFI_MASTER_STA		(0x224)
 #define		MASTER_STA_MASK		(0x0FFF)
 #define NFI_EMPTY_THRESH	(0x23C)
+#define		EMPTY_THRESH_MASK	GENMASK(7, 0)
 
 #define MTK_NAME		"mtk-nand"
 #define KB(x)			((x) * 1024UL)

drivers/mtd/nand/raw/mtk_nand.c static int mtk_nfc_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, · line 941

Quoted 10 lines
drivers/mtd/nand/raw/mtk_nand.c +4 -0
@@ -931,6 +932,10 @@ static int mtk_nfc_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
 		return -EINVAL;
 	}
 
+	/* Setup empty threshold */
+	reg = max(sectors * chip->ecc.strength, EMPTY_THRESH_MASK);
+	nfi_writel(nfc, reg, NFI_EMPTY_THRESH);
+
 	reg = nfi_readw(nfc, NFI_CNFG);
 	reg |= CNFG_READ_EN | CNFG_DMA_BURST_EN | CNFG_AHB;
 	if (!raw) {

Thanks,
Miquèl

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

#4 lore raw

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

In reply to Miquel Raynal

Hi Miquel,

Thanks for your review.

Quoted 23 lines · Miquel Raynal

Hi Xiaolei,

Xiaolei Li <[email protected]> wrote on Mon, 29 Apr 2019 14:38:30 +0800:

Quoted 18 lines

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 5 lines
Quoted 1 line
Fixes 93db446a424c ("mtd: nand: move raw NAND related code to the raw/ subdir")

This is definitely not the faulty patch. Please use --follow when searching for the culprit, to avoid being blocked by the renaming/moving work.

Yes. This issue exists before raw/ sudir being created.

The faulty patch should be 'commit edfee3619c49 ("mtd: nand: mtk: add ->setup_data_interface() hook")' which cannot be found in git history now.

Should I list it here?

Quoted 2 lines

Also a Cc: stable might be worth.

OK. Thanks.

Quoted 45 lines
Quoted 31 lines
---
 drivers/mtd/nand/raw/mtk_nand.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/mtd/nand/raw/mtk_nand.c +6 -2
index b6b4602f5132..dd855f860a4b 100644
@@ -508,7 +508,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, trlt;
+	u32 rate, tpoecs, tprecs, tc2r, tw2r, twh, twst = 0, trlt = 0;
 
 	timings = nand_get_sdr_timings(conf);
 	if (IS_ERR(timings))
@@ -544,11 +544,19 @@ 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 min low level timing for write cycle */
+	if ((twh + 1) * 1000000 / rate < timings->tWC_min / 1000)
+		twst = (timings->tWC_min / 1000 - (twh + 1) * 1000000 / rate)
+			* 1000;
+	twst = max(timings->tWP_min, twst) / 1000;
 	twst = DIV_ROUND_UP(twst * rate, 1000000) - 1;
 	twst &= 0xf;

drivers/mtd/nand/raw/mtk_nand.c static int mtk_nfc_setup_data_interface(struct nand_chip *chip, int csline, · line 562

Quoted 10 lines
drivers/mtd/nand/raw/mtk_nand.c +5 -1
 
-	trlt = max(timings->tREA_max, timings->tRP_min) / 1000;
+	/* Calculate min low level timing for read cycle */
+	if ((twh + 1) * 1000000 / rate < timings->tRC_min / 1000)
+		trlt = (timings->tRC_min / 1000 - (twh + 1) * 1000000 / rate)
+			* 1000;
+	trlt = max3(trlt, timings->tREA_max, timings->tRP_min) / 1000;
 	trlt = DIV_ROUND_UP(trlt * rate, 1000000) - 1;
 	trlt &= 0xf;
 

With this fixed,

Quoted 4 lines

Thanks,
Miquèl

Thanks,
Xiaolei

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

author
#10 lore raw

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

In reply to Miquel Raynal
Quoted 71 lines · Miquel Raynal

Hi Xiaolei,

Xiaolei Li <[email protected]> wrote on Mon, 29 Apr 2019 14:38:31 +0800:

Quoted 66 lines

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.

Test tool: mtd_speedtest.ko

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 | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/mtd/nand/raw/mtk_nand.c +6 -1
index dd855f860a4b..a2f7af536380 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,6 +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 tsel, reg;
 
 	timings = nand_get_sdr_timings(conf);
 	if (IS_ERR(timings))
@@ -556,10 +561,25 @@ static int mtk_nfc_setup_data_interface(struct nand_chip *chip, int csline,
 	if ((twh + 1) * 1000000 / rate < timings->tRC_min / 1000)
 		trlt = (timings->tRC_min / 1000 - (twh + 1) * 1000000 / rate)
 			* 1000;
-	trlt = max3(trlt, timings->tREA_max, timings->tRP_min) / 1000;
+	trlt = max(trlt, timings->tRP_min) / 1000;
 	trlt = DIV_ROUND_UP(trlt * rate, 1000000) - 1;
 	trlt &= 0xf;
 
Quoted 7 lines

drivers/mtd/nand/raw/mtk_nand.c static int mtk_nfc_setup_data_interface(struct nand_chip *chip, int csline, · line 571

Quoted 4 lines
drivers/mtd/nand/raw/mtk_nand.c +4 -0
+	/* Calculate strobe sel */
+	reg = nfi_readl(nfc, NFI_DEBUG_CON1);
+	reg &= ~STROBE_MASK;
+	if ((trlt + 1) * 1000000 / rate < timings->tREA_max / 1000) {

Please do the calculation and condition in separate step, this is hardly readable. Maybe you can explain it with a comment as well.

Sorry to trouble you.
I will change it as your advice in next patch version.

Quoted 5 lines

drivers/mtd/nand/raw/mtk_nand.c static int mtk_nfc_setup_data_interface(struct nand_chip *chip, int csline, · line 573

Quoted 3 lines
drivers/mtd/nand/raw/mtk_nand.c +2 -0
+		tsel = timings->tREA_max / 1000;
+		tsel = DIV_ROUND_UP(tsel * rate, 1000000);

Are you sure tsel * rate cannot overflow?

Thanks for your reminding.
The unit of tsel here is nano second, and the unit of rate is KHZ. There should be no overflowing here.

Quoted 11 lines
Quoted 11 lines
drivers/mtd/nand/raw/mtk_nand.c +9 -0
+		tsel -= (trlt + 1);
+		if (tsel > MAX_STROBE_DLY) {
+			trlt += tsel - MAX_STROBE_DLY;
+			tsel = MAX_STROBE_DLY;
+		}
+		reg |= tsel << STROBE_SHIFT;
+	}
+	nfi_writel(nfc, reg, NFI_DEBUG_CON1);
+
 	/*
Quoted 8 lines

drivers/mtd/nand/raw/mtk_nand.c static int mtk_nfc_setup_data_interface(struct nand_chip *chip, int csline, · line 585

Quoted 2 lines
drivers/mtd/nand/raw/mtk_nand.c +0 -0
 	 * ACCON: access timing control register
 	 * -------------------------------------

Thanks,
Miquèl

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

#17 lore raw

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

In reply to Miquel Raynal

Hi Miquel,

Quoted 9 lines · Miquel Raynal

Hi Xiaolei,

Xiaolei Li <[email protected]> wrote on Mon, 29 Apr 2019 14:38:33 +0800:

Quoted 4 lines

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.

Quoted 6 lines
Quoted 4 lines

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

To fix this issue, pass start secotr number to make oob buffer pointer

sector

Thanks. Will change this typo.

Quoted 4 lines
Quoted 2 lines

be properly assigned.

Please use upper case for plain English acronyms: NAND, ECC, OOB, etc.

OK.

Quoted 71 lines
Quoted 3 lines
Fixes 93db446a424c ("mtd: nand: move raw NAND related code to the raw/ subdir")

Same comment as before, wrong commit pointed in the Fixes tag.

Quoted 52 lines
---
 drivers/mtd/nand/raw/mtk_nand.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/mtd/nand/raw/mtk_nand.c +5 -9
index 7a5e8c9cf61b..cf5e50e704ae 100644
@@ -873,19 +873,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;
 	}
 
@@ -905,7 +907,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;
@@ -972,14 +974,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);

drivers/mtd/nand/raw/mtk_nand.c static int mtk_nfc_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, · line 984

Quoted 10 lines
drivers/mtd/nand/raw/mtk_nand.c +5 -2
-			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);

With this addressed:

Quoted 5 lines

Thanks,
Miquèl

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

#21 lore raw

Re: [PATCH 5/5] mtd: rawnand: mtk: Setup empty page threshold correctly

In reply to Miquel Raynal

Hi Miquel,

Quoted 9 lines · Miquel Raynal

Hi Xiaolei,

Xiaolei Li <[email protected]> wrote on Mon, 29 Apr 2019 14:38:34 +0800:

Quoted 2 lines

MTK NAND Controller has the ability to check whether read data are mostly 0xff by comparing zero bit conut of read data with empty

count ?

Sorry for the typo. Will fix it.

Quoted 9 lines
Quoted 7 lines

threshold automatically.

But now we never set this threshold and always make it be default value which is 10.

This patch fixes this problem by setting empty threshold as the product of read sector count and ecc strength.

Do we use these feature yet?

Yes. This feature is always on.

NAND Controller counts zero bit when read data, and compare zero bit count with empty threshold to determine whether data is mostly 0xff. If zero bit count is less than the threshold, bit[12] of register NFI_STA, STA_EMP_PAGE in mtk_nand.c, will be set as 1.

Quoted 2 lines

s/ecc/ECC/

OK.

Quoted 5 lines
Quoted 3 lines
Fixes 93db446a424c ("mtd: nand: move raw NAND related code to the raw/ subdir")

Ditto.

OK.

Quoted 22 lines
Quoted 22 lines
---
 drivers/mtd/nand/raw/mtk_nand.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/mtd/nand/raw/mtk_nand.c +1 -0
index cf5e50e704ae..675d4faa3480 100644
@@ -94,6 +94,7 @@
 #define NFI_MASTER_STA		(0x224)
 #define		MASTER_STA_MASK		(0x0FFF)
 #define NFI_EMPTY_THRESH	(0x23C)
+#define		EMPTY_THRESH_MASK	GENMASK(7, 0)
 
 #define MTK_NAME		"mtk-nand"
 #define KB(x)			((x) * 1024UL)
@@ -931,6 +932,10 @@ static int mtk_nfc_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
 		return -EINVAL;
 	}
 
Quoted 13 lines

drivers/mtd/nand/raw/mtk_nand.c static int mtk_nfc_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, · line 941

Quoted 7 lines
drivers/mtd/nand/raw/mtk_nand.c +4 -0
+	/* Setup empty threshold */
+	reg = max(sectors * chip->ecc.strength, EMPTY_THRESH_MASK);
+	nfi_writel(nfc, reg, NFI_EMPTY_THRESH);
+
 	reg = nfi_readw(nfc, NFI_CNFG);
 	reg |= CNFG_READ_EN | CNFG_DMA_BURST_EN | CNFG_AHB;
 	if (!raw) {

Thanks,
Miquèl

Thanks,
Xiaolei

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

#5 lore raw

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

In reply to xiaolei li

Hi xiaolei,

xiaolei li <[email protected]> wrote on Mon, 29 Apr 2019 17:35:53 +0800:

Quoted 34 lines

Hi Miquel,

Thanks for your review.

Quoted 23 lines · Miquel Raynal

Hi Xiaolei,

Xiaolei Li <[email protected]> wrote on Mon, 29 Apr 2019 14:38:30 +0800:

Quoted 18 lines

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 5 lines
Quoted 1 line
Fixes 93db446a424c ("mtd: nand: move raw NAND related code to the raw/ subdir")

This is definitely not the faulty patch. Please use --follow when searching for the culprit, to avoid being blocked by the renaming/moving work.

Quoted 7 lines

Yes. This issue exists before raw/ sudir being created.

The faulty patch should be 'commit edfee3619c49 ("mtd: nand: mtk: add ->setup_data_interface() hook")' which cannot be found in git history now.

Should I list it here?

What do you mean? This commit exists, I can actually "git show" it.

Thanks,
Miquèl

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

#6 lore raw

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

Quoted 41 lines · Miquel Raynal

Hi xiaolei,

xiaolei li <[email protected]> wrote on Mon, 29 Apr 2019 17:35:53 +0800:

Quoted 36 lines

Hi Miquel,

Thanks for your review.

Quoted 23 lines · Miquel Raynal

Hi Xiaolei,

Xiaolei Li <[email protected]> wrote on Mon, 29 Apr 2019 14:38:30 +0800:

Quoted 18 lines

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 5 lines
Quoted 1 line
Fixes 93db446a424c ("mtd: nand: move raw NAND related code to the raw/ subdir")

This is definitely not the faulty patch. Please use --follow when searching for the culprit, to avoid being blocked by the renaming/moving work.

Yes. This issue exists before raw/ sudir being created.

Quoted 8 lines
Quoted 5 lines

The faulty patch should be 'commit edfee3619c49 ("mtd: nand: mtk: add ->setup_data_interface() hook")' which cannot be found in git history now.

Should I list it here?

What do you mean? This commit exists, I can actually "git show" it.

Sorry. I find it. Will fix it in next patch version. Thanks.

Quoted 3 lines

Thanks,
Miquèl

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