linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: nand: atmel: correct bitflips in erased pages for pre-sama5d4 SoCs
@ 2016-03-01 13:11 Boris Brezillon
  2016-03-01 13:58 ` Herve Codina
  2016-03-30 14:29 ` Boris Brezillon
  0 siblings, 2 replies; 3+ messages in thread
From: Boris Brezillon @ 2016-03-01 13:11 UTC (permalink / raw)
  To: David Woodhouse, Brian Norris, linux-mtd
  Cc: Herve Codina, Nicolas Ferre, Jean-Christophe Plagniol-Villard,
	Alexandre Belloni, Wenyou Yang, Josh Wu, Boris Brezillon

New atmel SoCs are able to fix bitflips in erased pages, but old ones
are still impacted by this problem. Use nand_check_erased_ecc_chunk() to
handle this case.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Reported-by: Herve Codina <herve.CODINA@celad.com>
---
 drivers/mtd/nand/atmel_nand.c | 37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 20cbaab..0b5da72 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -863,17 +863,6 @@ static int pmecc_correction(struct mtd_info *mtd, u32 pmecc_stat, uint8_t *buf,
 	uint8_t *buf_pos;
 	int max_bitflips = 0;
 
-	/* If can correct bitfilps from erased page, do the normal check */
-	if (host->caps->pmecc_correct_erase_page)
-		goto normal_check;
-
-	for (i = 0; i < nand_chip->ecc.total; i++)
-		if (ecc[i] != 0xff)
-			goto normal_check;
-	/* Erased page, return OK */
-	return 0;
-
-normal_check:
 	for (i = 0; i < nand_chip->ecc.steps; i++) {
 		err_nbr = 0;
 		if (pmecc_stat & 0x1) {
@@ -884,16 +873,30 @@ normal_check:
 			pmecc_get_sigma(mtd);
 
 			err_nbr = pmecc_err_location(mtd);
-			if (err_nbr == -1) {
+			if (err_nbr >= 0) {
+				pmecc_correct_data(mtd, buf_pos, ecc, i,
+						   nand_chip->ecc.bytes,
+						   err_nbr);
+			} else if (!host->caps->pmecc_correct_erase_page) {
+				u8 *ecc_pos = ecc + (i * nand_chip->ecc.bytes);
+
+				/* Try to detect erased pages */
+				err_nbr = nand_check_erased_ecc_chunk(buf_pos,
+							host->pmecc_sector_size,
+							ecc_pos,
+							nand_chip->ecc.bytes,
+							NULL, 0,
+							nand_chip->ecc.strength);
+			}
+
+			if (err_nbr < 0) {
 				dev_err(host->dev, "PMECC: Too many errors\n");
 				mtd->ecc_stats.failed++;
 				return -EIO;
-			} else {
-				pmecc_correct_data(mtd, buf_pos, ecc, i,
-					nand_chip->ecc.bytes, err_nbr);
-				mtd->ecc_stats.corrected += err_nbr;
-				max_bitflips = max_t(int, max_bitflips, err_nbr);
 			}
+
+			mtd->ecc_stats.corrected += err_nbr;
+			max_bitflips = max_t(int, max_bitflips, err_nbr);
 		}
 		pmecc_stat >>= 1;
 	}
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mtd: nand: atmel: correct bitflips in erased pages for pre-sama5d4 SoCs
  2016-03-01 13:11 [PATCH] mtd: nand: atmel: correct bitflips in erased pages for pre-sama5d4 SoCs Boris Brezillon
@ 2016-03-01 13:58 ` Herve Codina
  2016-03-30 14:29 ` Boris Brezillon
  1 sibling, 0 replies; 3+ messages in thread
From: Herve Codina @ 2016-03-01 13:58 UTC (permalink / raw)
  To: Boris Brezillon, David Woodhouse, Brian Norris,
	linux-mtd@lists.infradead.org
  Cc: Nicolas Ferre, Jean-Christophe Plagniol-Villard,
	Alexandre Belloni, Wenyou Yang, Josh Wu



Le 01/03/2016 14:11, Boris Brezillon a écrit :
> New atmel SoCs are able to fix bitflips in erased pages, but old ones
> are still impacted by this problem. Use nand_check_erased_ecc_chunk() to
> handle this case.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> Reported-by: Herve Codina <herve.CODINA@celad.com>

Reviewed-by: Herve Codina <herve.CODINA@celad.com>

Tested-by: Herve Codina <herve.CODINA@celad.com>

For testing purpose on my system, 
this patch and dependencies were backported to 3.12.52 and succesfully tested using
a sama5d3 with a Micron MT29F16G08ABACAWP nand flash.


> ---
>  drivers/mtd/nand/atmel_nand.c | 37 ++++++++++++++++++++-----------------
>  1 file changed, 20 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
> index 20cbaab..0b5da72 100644
> --- a/drivers/mtd/nand/atmel_nand.c
> +++ b/drivers/mtd/nand/atmel_nand.c
> @@ -863,17 +863,6 @@ static int pmecc_correction(struct mtd_info *mtd, u32 pmecc_stat, uint8_t *buf,
>  	uint8_t *buf_pos;
>  	int max_bitflips = 0;
>  
> -	/* If can correct bitfilps from erased page, do the normal check */
> -	if (host->caps->pmecc_correct_erase_page)
> -		goto normal_check;
> -
> -	for (i = 0; i < nand_chip->ecc.total; i++)
> -		if (ecc[i] != 0xff)
> -			goto normal_check;
> -	/* Erased page, return OK */
> -	return 0;
> -
> -normal_check:
>  	for (i = 0; i < nand_chip->ecc.steps; i++) {
>  		err_nbr = 0;
>  		if (pmecc_stat & 0x1) {
> @@ -884,16 +873,30 @@ normal_check:
>  			pmecc_get_sigma(mtd);
>  
>  			err_nbr = pmecc_err_location(mtd);
> -			if (err_nbr == -1) {
> +			if (err_nbr >= 0) {
> +				pmecc_correct_data(mtd, buf_pos, ecc, i,
> +						   nand_chip->ecc.bytes,
> +						   err_nbr);
> +			} else if (!host->caps->pmecc_correct_erase_page) {
> +				u8 *ecc_pos = ecc + (i * nand_chip->ecc.bytes);
> +
> +				/* Try to detect erased pages */
> +				err_nbr = nand_check_erased_ecc_chunk(buf_pos,
> +							host->pmecc_sector_size,
> +							ecc_pos,
> +							nand_chip->ecc.bytes,
> +							NULL, 0,
> +							nand_chip->ecc.strength);
> +			}
> +
> +			if (err_nbr < 0) {
>  				dev_err(host->dev, "PMECC: Too many errors\n");
>  				mtd->ecc_stats.failed++;
>  				return -EIO;
> -			} else {
> -				pmecc_correct_data(mtd, buf_pos, ecc, i,
> -					nand_chip->ecc.bytes, err_nbr);
> -				mtd->ecc_stats.corrected += err_nbr;
> -				max_bitflips = max_t(int, max_bitflips, err_nbr);
>  			}
> +
> +			mtd->ecc_stats.corrected += err_nbr;
> +			max_bitflips = max_t(int, max_bitflips, err_nbr);
>  		}
>  		pmecc_stat >>= 1;
>  	}
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mtd: nand: atmel: correct bitflips in erased pages for pre-sama5d4 SoCs
  2016-03-01 13:11 [PATCH] mtd: nand: atmel: correct bitflips in erased pages for pre-sama5d4 SoCs Boris Brezillon
  2016-03-01 13:58 ` Herve Codina
@ 2016-03-30 14:29 ` Boris Brezillon
  1 sibling, 0 replies; 3+ messages in thread
From: Boris Brezillon @ 2016-03-30 14:29 UTC (permalink / raw)
  To: David Woodhouse, Brian Norris, linux-mtd
  Cc: Josh Wu, Nicolas Ferre, Wenyou Yang, Herve Codina,
	Alexandre Belloni, Jean-Christophe Plagniol-Villard

On Tue,  1 Mar 2016 14:11:52 +0100
Boris Brezillon <boris.brezillon@free-electrons.com> wrote:

> New atmel SoCs are able to fix bitflips in erased pages, but old ones
> are still impacted by this problem. Use nand_check_erased_ecc_chunk() to
> handle this case.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> Reported-by: Herve Codina <herve.CODINA@celad.com>

Applied to nand/next [1].

[1]https://github.com/linux-nand/linux/tree/nand/next

> ---
>  drivers/mtd/nand/atmel_nand.c | 37 ++++++++++++++++++++-----------------
>  1 file changed, 20 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
> index 20cbaab..0b5da72 100644
> --- a/drivers/mtd/nand/atmel_nand.c
> +++ b/drivers/mtd/nand/atmel_nand.c
> @@ -863,17 +863,6 @@ static int pmecc_correction(struct mtd_info *mtd, u32 pmecc_stat, uint8_t *buf,
>  	uint8_t *buf_pos;
>  	int max_bitflips = 0;
>  
> -	/* If can correct bitfilps from erased page, do the normal check */
> -	if (host->caps->pmecc_correct_erase_page)
> -		goto normal_check;
> -
> -	for (i = 0; i < nand_chip->ecc.total; i++)
> -		if (ecc[i] != 0xff)
> -			goto normal_check;
> -	/* Erased page, return OK */
> -	return 0;
> -
> -normal_check:
>  	for (i = 0; i < nand_chip->ecc.steps; i++) {
>  		err_nbr = 0;
>  		if (pmecc_stat & 0x1) {
> @@ -884,16 +873,30 @@ normal_check:
>  			pmecc_get_sigma(mtd);
>  
>  			err_nbr = pmecc_err_location(mtd);
> -			if (err_nbr == -1) {
> +			if (err_nbr >= 0) {
> +				pmecc_correct_data(mtd, buf_pos, ecc, i,
> +						   nand_chip->ecc.bytes,
> +						   err_nbr);
> +			} else if (!host->caps->pmecc_correct_erase_page) {
> +				u8 *ecc_pos = ecc + (i * nand_chip->ecc.bytes);
> +
> +				/* Try to detect erased pages */
> +				err_nbr = nand_check_erased_ecc_chunk(buf_pos,
> +							host->pmecc_sector_size,
> +							ecc_pos,
> +							nand_chip->ecc.bytes,
> +							NULL, 0,
> +							nand_chip->ecc.strength);
> +			}
> +
> +			if (err_nbr < 0) {
>  				dev_err(host->dev, "PMECC: Too many errors\n");
>  				mtd->ecc_stats.failed++;
>  				return -EIO;
> -			} else {
> -				pmecc_correct_data(mtd, buf_pos, ecc, i,
> -					nand_chip->ecc.bytes, err_nbr);
> -				mtd->ecc_stats.corrected += err_nbr;
> -				max_bitflips = max_t(int, max_bitflips, err_nbr);
>  			}
> +
> +			mtd->ecc_stats.corrected += err_nbr;
> +			max_bitflips = max_t(int, max_bitflips, err_nbr);
>  		}
>  		pmecc_stat >>= 1;
>  	}



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-03-30 14:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-01 13:11 [PATCH] mtd: nand: atmel: correct bitflips in erased pages for pre-sama5d4 SoCs Boris Brezillon
2016-03-01 13:58 ` Herve Codina
2016-03-30 14:29 ` Boris Brezillon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).