diff mbox series

[v2,5/5] mtd: rawnand: mtk: Setup empty page threshold correctly

Message ID 20190430100250.28083-6-xiaolei.li@mediatek.com (mailing list archive)
State New, archived
Headers show
Series MTK NAND driver improvements and fixes | expand

Commit Message

xiaolei li April 30, 2019, 10:02 a.m. UTC
MTK NAND Controller has the ability to check whether read data are
mostly 0xff by comparing zero bit count 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: 1d6b1e464950 ("mtd: mediatek: driver for MTK Smart Device")
Signed-off-by: Xiaolei Li <xiaolei.li@mediatek.com>
---
 drivers/mtd/nand/raw/mtk_nand.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Miquel Raynal April 30, 2019, 12:17 p.m. UTC | #1
Hi Xiaolei,

Xiaolei Li <xiaolei.li@mediatek.com> wrote on Tue, 30 Apr 2019 18:02:50
+0800:

> MTK NAND Controller has the ability to check whether read data are
> mostly 0xff by comparing zero bit count 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.

Are you sure it is not a per-sector value?

Did you use nandbiterrs to validate?

> 
> Fixes: 1d6b1e464950 ("mtd: mediatek: driver for MTK Smart Device")
> Signed-off-by: Xiaolei Li <xiaolei.li@mediatek.com>
> ---
>  drivers/mtd/nand/raw/mtk_nand.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/mtd/nand/raw/mtk_nand.c b/drivers/mtd/nand/raw/mtk_nand.c
> index 48759af5c058..b56965328771 100644
> --- a/drivers/mtd/nand/raw/mtk_nand.c
> +++ b/drivers/mtd/nand/raw/mtk_nand.c
> @@ -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)
> @@ -947,6 +948,14 @@ static int mtk_nfc_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
>  		return -EINVAL;
>  	}
>  
> +	/**

        /*

> +	 * Setup empty threshold as the product of sector count
> +	 * and ECC strength
> +	 */
> +	reg = sectors * chip->ecc.strength;
> +	reg = min_t(unsigned int, reg, 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
xiaolei li May 5, 2019, 7:50 a.m. UTC | #2
Hi Miquel,

On Tue, 2019-04-30 at 14:17 +0200, Miquel Raynal wrote:
> Hi Xiaolei,
> 
> Xiaolei Li <xiaolei.li@mediatek.com> wrote on Tue, 30 Apr 2019 18:02:50
> +0800:
> 
> > MTK NAND Controller has the ability to check whether read data are
> > mostly 0xff by comparing zero bit count 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.
> 
> Are you sure it is not a per-sector value?
Frankly, I also think it should be a per-sector value.

But MTK NAND Controller cannot check 0xff by sector. It counts zero bit
through all read data. So, I set the empty threshold as the product of
read sector count and ECC strength.

> 
> Did you use nandbiterrs to validate?
Yes. I ever did nandbiterrs test, and it passed.

> 
> > 
> > Fixes: 1d6b1e464950 ("mtd: mediatek: driver for MTK Smart Device")
> > Signed-off-by: Xiaolei Li <xiaolei.li@mediatek.com>
> > ---
> >  drivers/mtd/nand/raw/mtk_nand.c | 9 +++++++++
> >  1 file changed, 9 insertions(+)
> > 
> > diff --git a/drivers/mtd/nand/raw/mtk_nand.c b/drivers/mtd/nand/raw/mtk_nand.c
> > index 48759af5c058..b56965328771 100644
> > --- a/drivers/mtd/nand/raw/mtk_nand.c
> > +++ b/drivers/mtd/nand/raw/mtk_nand.c
> > @@ -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)
> > @@ -947,6 +948,14 @@ static int mtk_nfc_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
> >  		return -EINVAL;
> >  	}
> >  
> > +	/**
> 
>         /*
> 
> > +	 * Setup empty threshold as the product of sector count
> > +	 * and ECC strength
> > +	 */
> > +	reg = sectors * chip->ecc.strength;
> > +	reg = min_t(unsigned int, reg, 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
diff mbox series

Patch

diff --git a/drivers/mtd/nand/raw/mtk_nand.c b/drivers/mtd/nand/raw/mtk_nand.c
index 48759af5c058..b56965328771 100644
--- a/drivers/mtd/nand/raw/mtk_nand.c
+++ b/drivers/mtd/nand/raw/mtk_nand.c
@@ -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)
@@ -947,6 +948,14 @@  static int mtk_nfc_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
 		return -EINVAL;
 	}
 
+	/**
+	 * Setup empty threshold as the product of sector count
+	 * and ECC strength
+	 */
+	reg = sectors * chip->ecc.strength;
+	reg = min_t(unsigned int, reg, 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) {