Commit 3f91e94f authored by Mike Dunn's avatar Mike Dunn Committed by David Woodhouse

mtd: nand: read_page() returns max_bitflips

The ecc.read_page() method for nand drivers is changed to return the maximum
number of bitflips that were corrected on any one region covering an ecc step,
This patch doesn't change what the nand code returns to mtd.

This v2 includes the change to the fsl_ifc_nand driver requested by Scott¹.

¹ http://lists.infradead.org/pipermail/linux-mtd/2012-April/040883.htmlSigned-off-by: default avatarMike Dunn <mikedunn@newsguy.com>
Acked-by (freescale changes): Scott Wood <scottwood@freescale.com>
Signed-off-by: default avatarArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent d062d4ed
...@@ -335,6 +335,7 @@ static int atmel_nand_read_page(struct mtd_info *mtd, ...@@ -335,6 +335,7 @@ static int atmel_nand_read_page(struct mtd_info *mtd,
uint8_t *oob = chip->oob_poi; uint8_t *oob = chip->oob_poi;
uint8_t *ecc_pos; uint8_t *ecc_pos;
int stat; int stat;
unsigned int max_bitflips = 0;
/* /*
* Errata: ALE is incorrectly wired up to the ECC controller * Errata: ALE is incorrectly wired up to the ECC controller
...@@ -371,10 +372,12 @@ static int atmel_nand_read_page(struct mtd_info *mtd, ...@@ -371,10 +372,12 @@ static int atmel_nand_read_page(struct mtd_info *mtd,
/* check if there's an error */ /* check if there's an error */
stat = chip->ecc.correct(mtd, p, oob, NULL); stat = chip->ecc.correct(mtd, p, oob, NULL);
if (stat < 0) if (stat < 0) {
mtd->ecc_stats.failed++; mtd->ecc_stats.failed++;
else } else {
mtd->ecc_stats.corrected += stat; mtd->ecc_stats.corrected += stat;
max_bitflips = max_t(unsigned int, max_bitflips, stat);
}
/* get back to oob start (end of page) */ /* get back to oob start (end of page) */
chip->cmdfunc(mtd, NAND_CMD_RNDOUT, mtd->writesize, -1); chip->cmdfunc(mtd, NAND_CMD_RNDOUT, mtd->writesize, -1);
...@@ -382,7 +385,7 @@ static int atmel_nand_read_page(struct mtd_info *mtd, ...@@ -382,7 +385,7 @@ static int atmel_nand_read_page(struct mtd_info *mtd,
/* read the oob */ /* read the oob */
chip->read_buf(mtd, oob, mtd->oobsize); chip->read_buf(mtd, oob, mtd->oobsize);
return 0; return max_bitflips;
} }
/* /*
......
...@@ -116,6 +116,7 @@ static int bcm_umi_bch_read_page_hwecc(struct mtd_info *mtd, ...@@ -116,6 +116,7 @@ static int bcm_umi_bch_read_page_hwecc(struct mtd_info *mtd,
uint8_t eccCalc[NAND_ECC_NUM_BYTES]; uint8_t eccCalc[NAND_ECC_NUM_BYTES];
int sectorOobSize = mtd->oobsize / eccsteps; int sectorOobSize = mtd->oobsize / eccsteps;
int stat; int stat;
unsigned int max_bitflips = 0;
for (sectorIdx = 0; sectorIdx < eccsteps; for (sectorIdx = 0; sectorIdx < eccsteps;
sectorIdx++, datap += eccsize) { sectorIdx++, datap += eccsize) {
...@@ -177,9 +178,10 @@ static int bcm_umi_bch_read_page_hwecc(struct mtd_info *mtd, ...@@ -177,9 +178,10 @@ static int bcm_umi_bch_read_page_hwecc(struct mtd_info *mtd,
} }
#endif #endif
mtd->ecc_stats.corrected += stat; mtd->ecc_stats.corrected += stat;
max_bitflips = max_t(unsigned int, max_bitflips, stat);
} }
} }
return 0; return max_bitflips;
} }
/**************************************************************************** /****************************************************************************
......
...@@ -383,6 +383,7 @@ static int cafe_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -383,6 +383,7 @@ static int cafe_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip,
uint8_t *buf, int page) uint8_t *buf, int page)
{ {
struct cafe_priv *cafe = mtd->priv; struct cafe_priv *cafe = mtd->priv;
unsigned int max_bitflips = 0;
cafe_dev_dbg(&cafe->pdev->dev, "ECC result %08x SYN1,2 %08x\n", cafe_dev_dbg(&cafe->pdev->dev, "ECC result %08x SYN1,2 %08x\n",
cafe_readl(cafe, NAND_ECC_RESULT), cafe_readl(cafe, NAND_ECC_RESULT),
...@@ -449,10 +450,11 @@ static int cafe_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -449,10 +450,11 @@ static int cafe_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip,
} else { } else {
dev_dbg(&cafe->pdev->dev, "Corrected %d symbol errors\n", n); dev_dbg(&cafe->pdev->dev, "Corrected %d symbol errors\n", n);
mtd->ecc_stats.corrected += n; mtd->ecc_stats.corrected += n;
max_bitflips = max_t(unsigned int, max_bitflips, n);
} }
} }
return 0; return max_bitflips;
} }
static struct nand_ecclayout cafe_oobinfo_2048 = { static struct nand_ecclayout cafe_oobinfo_2048 = {
......
...@@ -924,9 +924,10 @@ bool is_erased(uint8_t *buf, int len) ...@@ -924,9 +924,10 @@ bool is_erased(uint8_t *buf, int len)
#define ECC_LAST_ERR(x) ((x) & ERR_CORRECTION_INFO__LAST_ERR_INFO) #define ECC_LAST_ERR(x) ((x) & ERR_CORRECTION_INFO__LAST_ERR_INFO)
static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf, static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf,
uint32_t irq_status) uint32_t irq_status, unsigned int *max_bitflips)
{ {
bool check_erased_page = false; bool check_erased_page = false;
unsigned int bitflips = 0;
if (irq_status & INTR_STATUS__ECC_ERR) { if (irq_status & INTR_STATUS__ECC_ERR) {
/* read the ECC errors. we'll ignore them for now */ /* read the ECC errors. we'll ignore them for now */
...@@ -965,6 +966,7 @@ static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf, ...@@ -965,6 +966,7 @@ static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf,
/* correct the ECC error */ /* correct the ECC error */
buf[offset] ^= err_correction_value; buf[offset] ^= err_correction_value;
denali->mtd.ecc_stats.corrected++; denali->mtd.ecc_stats.corrected++;
bitflips++;
} }
} else { } else {
/* if the error is not correctable, need to /* if the error is not correctable, need to
...@@ -984,6 +986,7 @@ static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf, ...@@ -984,6 +986,7 @@ static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf,
clear_interrupts(denali); clear_interrupts(denali);
denali_set_intr_modes(denali, true); denali_set_intr_modes(denali, true);
} }
*max_bitflips = bitflips;
return check_erased_page; return check_erased_page;
} }
...@@ -1121,6 +1124,7 @@ static int denali_read_oob(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -1121,6 +1124,7 @@ static int denali_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip, static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip,
uint8_t *buf, int page) uint8_t *buf, int page)
{ {
unsigned int max_bitflips;
struct denali_nand_info *denali = mtd_to_denali(mtd); struct denali_nand_info *denali = mtd_to_denali(mtd);
dma_addr_t addr = denali->buf.dma_buf; dma_addr_t addr = denali->buf.dma_buf;
...@@ -1153,7 +1157,7 @@ static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -1153,7 +1157,7 @@ static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip,
memcpy(buf, denali->buf.buf, mtd->writesize); memcpy(buf, denali->buf.buf, mtd->writesize);
check_erased_page = handle_ecc(denali, buf, irq_status); check_erased_page = handle_ecc(denali, buf, irq_status, &max_bitflips);
denali_enable_dma(denali, false); denali_enable_dma(denali, false);
if (check_erased_page) { if (check_erased_page) {
...@@ -1167,7 +1171,7 @@ static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -1167,7 +1171,7 @@ static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip,
denali->mtd.ecc_stats.failed++; denali->mtd.ecc_stats.failed++;
} }
} }
return 0; return max_bitflips;
} }
static int denali_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip, static int denali_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
......
...@@ -720,6 +720,7 @@ static int read_page(struct mtd_info *mtd, struct nand_chip *nand, ...@@ -720,6 +720,7 @@ static int read_page(struct mtd_info *mtd, struct nand_chip *nand,
struct docg4_priv *doc = nand->priv; struct docg4_priv *doc = nand->priv;
void __iomem *docptr = doc->virtadr; void __iomem *docptr = doc->virtadr;
uint16_t status, edc_err, *buf16; uint16_t status, edc_err, *buf16;
int bits_corrected = 0;
dev_dbg(doc->dev, "%s: page %08x\n", __func__, page); dev_dbg(doc->dev, "%s: page %08x\n", __func__, page);
...@@ -772,7 +773,7 @@ static int read_page(struct mtd_info *mtd, struct nand_chip *nand, ...@@ -772,7 +773,7 @@ static int read_page(struct mtd_info *mtd, struct nand_chip *nand,
/* If bitflips are reported, attempt to correct with ecc */ /* If bitflips are reported, attempt to correct with ecc */
if (edc_err & DOC_ECCCONF1_BCH_SYNDROM_ERR) { if (edc_err & DOC_ECCCONF1_BCH_SYNDROM_ERR) {
int bits_corrected = correct_data(mtd, buf, page); bits_corrected = correct_data(mtd, buf, page);
if (bits_corrected == -EBADMSG) if (bits_corrected == -EBADMSG)
mtd->ecc_stats.failed++; mtd->ecc_stats.failed++;
else else
...@@ -781,7 +782,7 @@ static int read_page(struct mtd_info *mtd, struct nand_chip *nand, ...@@ -781,7 +782,7 @@ static int read_page(struct mtd_info *mtd, struct nand_chip *nand,
} }
writew(0, docptr + DOC_DATAEND); writew(0, docptr + DOC_DATAEND);
return 0; return bits_corrected;
} }
......
...@@ -75,6 +75,7 @@ struct fsl_elbc_fcm_ctrl { ...@@ -75,6 +75,7 @@ struct fsl_elbc_fcm_ctrl {
unsigned int use_mdr; /* Non zero if the MDR is to be set */ unsigned int use_mdr; /* Non zero if the MDR is to be set */
unsigned int oob; /* Non zero if operating on OOB data */ unsigned int oob; /* Non zero if operating on OOB data */
unsigned int counter; /* counter for the initializations */ unsigned int counter; /* counter for the initializations */
unsigned int max_bitflips; /* Saved during READ0 cmd */
}; };
/* These map to the positions used by the FCM hardware ECC generator */ /* These map to the positions used by the FCM hardware ECC generator */
...@@ -253,6 +254,8 @@ static int fsl_elbc_run_command(struct mtd_info *mtd) ...@@ -253,6 +254,8 @@ static int fsl_elbc_run_command(struct mtd_info *mtd)
if (chip->ecc.mode != NAND_ECC_HW) if (chip->ecc.mode != NAND_ECC_HW)
return 0; return 0;
elbc_fcm_ctrl->max_bitflips = 0;
if (elbc_fcm_ctrl->read_bytes == mtd->writesize + mtd->oobsize) { if (elbc_fcm_ctrl->read_bytes == mtd->writesize + mtd->oobsize) {
uint32_t lteccr = in_be32(&lbc->lteccr); uint32_t lteccr = in_be32(&lbc->lteccr);
/* /*
...@@ -262,11 +265,16 @@ static int fsl_elbc_run_command(struct mtd_info *mtd) ...@@ -262,11 +265,16 @@ static int fsl_elbc_run_command(struct mtd_info *mtd)
* bits 28-31 are uncorrectable errors, marked elsewhere. * bits 28-31 are uncorrectable errors, marked elsewhere.
* for small page nand only 1 bit is used. * for small page nand only 1 bit is used.
* if the ELBC doesn't have the lteccr register it reads 0 * if the ELBC doesn't have the lteccr register it reads 0
* FIXME: 4 bits can be corrected on NANDs with 2k pages, so
* count the number of sub-pages with bitflips and update
* ecc_stats.corrected accordingly.
*/ */
if (lteccr & 0x000F000F) if (lteccr & 0x000F000F)
out_be32(&lbc->lteccr, 0x000F000F); /* clear lteccr */ out_be32(&lbc->lteccr, 0x000F000F); /* clear lteccr */
if (lteccr & 0x000F0000) if (lteccr & 0x000F0000) {
mtd->ecc_stats.corrected++; mtd->ecc_stats.corrected++;
elbc_fcm_ctrl->max_bitflips = 1;
}
} }
return 0; return 0;
...@@ -743,13 +751,17 @@ static int fsl_elbc_read_page(struct mtd_info *mtd, ...@@ -743,13 +751,17 @@ static int fsl_elbc_read_page(struct mtd_info *mtd,
uint8_t *buf, uint8_t *buf,
int page) int page)
{ {
struct fsl_elbc_mtd *priv = chip->priv;
struct fsl_lbc_ctrl *ctrl = priv->ctrl;
struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = ctrl->nand;
fsl_elbc_read_buf(mtd, buf, mtd->writesize); fsl_elbc_read_buf(mtd, buf, mtd->writesize);
fsl_elbc_read_buf(mtd, chip->oob_poi, mtd->oobsize); fsl_elbc_read_buf(mtd, chip->oob_poi, mtd->oobsize);
if (fsl_elbc_wait(mtd, chip) & NAND_STATUS_FAIL) if (fsl_elbc_wait(mtd, chip) & NAND_STATUS_FAIL)
mtd->ecc_stats.failed++; mtd->ecc_stats.failed++;
return 0; return elbc_fcm_ctrl->max_bitflips;
} }
/* ECC will be calculated automatically, and errors will be detected in /* ECC will be calculated automatically, and errors will be detected in
...@@ -814,11 +826,6 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv) ...@@ -814,11 +826,6 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
chip->ecc.size = 512; chip->ecc.size = 512;
chip->ecc.bytes = 3; chip->ecc.bytes = 3;
chip->ecc.strength = 1; chip->ecc.strength = 1;
/*
* FIXME: can hardware ecc correct 4 bitflips if page size is
* 2k? Then does hardware report number of corrections for this
* case? If so, ecc_stats reporting needs to be fixed as well.
*/
} else { } else {
/* otherwise fall back to default software ECC */ /* otherwise fall back to default software ECC */
chip->ecc.mode = NAND_ECC_SOFT; chip->ecc.mode = NAND_ECC_SOFT;
......
...@@ -63,6 +63,7 @@ struct fsl_ifc_nand_ctrl { ...@@ -63,6 +63,7 @@ struct fsl_ifc_nand_ctrl {
unsigned int oob; /* Non zero if operating on OOB data */ unsigned int oob; /* Non zero if operating on OOB data */
unsigned int eccread; /* Non zero for a full-page ECC read */ unsigned int eccread; /* Non zero for a full-page ECC read */
unsigned int counter; /* counter for the initializations */ unsigned int counter; /* counter for the initializations */
unsigned int max_bitflips; /* Saved during READ0 cmd */
}; };
static struct fsl_ifc_nand_ctrl *ifc_nand_ctrl; static struct fsl_ifc_nand_ctrl *ifc_nand_ctrl;
...@@ -262,6 +263,8 @@ static void fsl_ifc_run_command(struct mtd_info *mtd) ...@@ -262,6 +263,8 @@ static void fsl_ifc_run_command(struct mtd_info *mtd)
if (ctrl->nand_stat & IFC_NAND_EVTER_STAT_WPER) if (ctrl->nand_stat & IFC_NAND_EVTER_STAT_WPER)
dev_err(priv->dev, "NAND Flash Write Protect Error\n"); dev_err(priv->dev, "NAND Flash Write Protect Error\n");
nctrl->max_bitflips = 0;
if (nctrl->eccread) { if (nctrl->eccread) {
int errors; int errors;
int bufnum = nctrl->page & priv->bufnum_mask; int bufnum = nctrl->page & priv->bufnum_mask;
...@@ -290,6 +293,9 @@ static void fsl_ifc_run_command(struct mtd_info *mtd) ...@@ -290,6 +293,9 @@ static void fsl_ifc_run_command(struct mtd_info *mtd)
} }
mtd->ecc_stats.corrected += errors; mtd->ecc_stats.corrected += errors;
nctrl->max_bitflips = max_t(unsigned int,
nctrl->max_bitflips,
errors);
} }
nctrl->eccread = 0; nctrl->eccread = 0;
...@@ -698,6 +704,7 @@ static int fsl_ifc_read_page(struct mtd_info *mtd, ...@@ -698,6 +704,7 @@ static int fsl_ifc_read_page(struct mtd_info *mtd,
{ {
struct fsl_ifc_mtd *priv = chip->priv; struct fsl_ifc_mtd *priv = chip->priv;
struct fsl_ifc_ctrl *ctrl = priv->ctrl; struct fsl_ifc_ctrl *ctrl = priv->ctrl;
struct fsl_ifc_nand_ctrl *nctrl = ifc_nand_ctrl;
fsl_ifc_read_buf(mtd, buf, mtd->writesize); fsl_ifc_read_buf(mtd, buf, mtd->writesize);
fsl_ifc_read_buf(mtd, chip->oob_poi, mtd->oobsize); fsl_ifc_read_buf(mtd, chip->oob_poi, mtd->oobsize);
...@@ -708,7 +715,7 @@ static int fsl_ifc_read_page(struct mtd_info *mtd, ...@@ -708,7 +715,7 @@ static int fsl_ifc_read_page(struct mtd_info *mtd,
if (ctrl->nand_stat != IFC_NAND_EVTER_STAT_OPC) if (ctrl->nand_stat != IFC_NAND_EVTER_STAT_OPC)
mtd->ecc_stats.failed++; mtd->ecc_stats.failed++;
return 0; return nctrl->max_bitflips;
} }
/* ECC will be calculated automatically, and errors will be detected in /* ECC will be calculated automatically, and errors will be detected in
......
...@@ -720,6 +720,7 @@ static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -720,6 +720,7 @@ static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
*/ */
uint16_t ecc_oob[7]; uint16_t ecc_oob[7];
uint8_t *oob = (uint8_t *)&ecc_oob[0]; uint8_t *oob = (uint8_t *)&ecc_oob[0];
unsigned int max_bitflips = 0;
for (i = 0, s = 0; s < eccsteps; s++, i += eccbytes, p += eccsize) { for (i = 0, s = 0; s < eccsteps; s++, i += eccbytes, p += eccsize) {
chip->cmdfunc(mtd, NAND_CMD_READ0, s * eccsize, page); chip->cmdfunc(mtd, NAND_CMD_READ0, s * eccsize, page);
...@@ -748,13 +749,15 @@ static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -748,13 +749,15 @@ static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
chip->ecc.calculate(mtd, p, &ecc_calc[i]); chip->ecc.calculate(mtd, p, &ecc_calc[i]);
stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]); stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]);
if (stat < 0) if (stat < 0) {
mtd->ecc_stats.failed++; mtd->ecc_stats.failed++;
else } else {
mtd->ecc_stats.corrected += stat; mtd->ecc_stats.corrected += stat;
max_bitflips = max_t(unsigned int, max_bitflips, stat);
}
} }
return 0; return max_bitflips;
} }
/* /*
......
...@@ -1138,6 +1138,7 @@ static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -1138,6 +1138,7 @@ static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
uint8_t *ecc_calc = chip->buffers->ecccalc; uint8_t *ecc_calc = chip->buffers->ecccalc;
uint8_t *ecc_code = chip->buffers->ecccode; uint8_t *ecc_code = chip->buffers->ecccode;
uint32_t *eccpos = chip->ecc.layout->eccpos; uint32_t *eccpos = chip->ecc.layout->eccpos;
unsigned int max_bitflips = 0;
chip->ecc.read_page_raw(mtd, chip, buf, page); chip->ecc.read_page_raw(mtd, chip, buf, page);
...@@ -1154,12 +1155,14 @@ static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -1154,12 +1155,14 @@ static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
int stat; int stat;
stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]); stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]);
if (stat < 0) if (stat < 0) {
mtd->ecc_stats.failed++; mtd->ecc_stats.failed++;
else } else {
mtd->ecc_stats.corrected += stat; mtd->ecc_stats.corrected += stat;
max_bitflips = max_t(unsigned int, max_bitflips, stat);
} }
return 0; }
return max_bitflips;
} }
/** /**
...@@ -1180,6 +1183,7 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -1180,6 +1183,7 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
int datafrag_len, eccfrag_len, aligned_len, aligned_pos; int datafrag_len, eccfrag_len, aligned_len, aligned_pos;
int busw = (chip->options & NAND_BUSWIDTH_16) ? 2 : 1; int busw = (chip->options & NAND_BUSWIDTH_16) ? 2 : 1;
int index = 0; int index = 0;
unsigned int max_bitflips = 0;
/* Column address within the page aligned to ECC size (256bytes) */ /* Column address within the page aligned to ECC size (256bytes) */
start_step = data_offs / chip->ecc.size; start_step = data_offs / chip->ecc.size;
...@@ -1244,12 +1248,14 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -1244,12 +1248,14 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
stat = chip->ecc.correct(mtd, p, stat = chip->ecc.correct(mtd, p,
&chip->buffers->ecccode[i], &chip->buffers->ecccalc[i]); &chip->buffers->ecccode[i], &chip->buffers->ecccalc[i]);
if (stat < 0) if (stat < 0) {
mtd->ecc_stats.failed++; mtd->ecc_stats.failed++;
else } else {
mtd->ecc_stats.corrected += stat; mtd->ecc_stats.corrected += stat;
max_bitflips = max_t(unsigned int, max_bitflips, stat);
} }
return 0; }
return max_bitflips;
} }
/** /**
...@@ -1271,6 +1277,7 @@ static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -1271,6 +1277,7 @@ static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
uint8_t *ecc_calc = chip->buffers->ecccalc; uint8_t *ecc_calc = chip->buffers->ecccalc;
uint8_t *ecc_code = chip->buffers->ecccode; uint8_t *ecc_code = chip->buffers->ecccode;
uint32_t *eccpos = chip->ecc.layout->eccpos; uint32_t *eccpos = chip->ecc.layout->eccpos;
unsigned int max_bitflips = 0;
for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) { for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
chip->ecc.hwctl(mtd, NAND_ECC_READ); chip->ecc.hwctl(mtd, NAND_ECC_READ);
...@@ -1289,12 +1296,14 @@ static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -1289,12 +1296,14 @@ static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
int stat; int stat;
stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]); stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]);
if (stat < 0) if (stat < 0) {
mtd->ecc_stats.failed++; mtd->ecc_stats.failed++;
else } else {
mtd->ecc_stats.corrected += stat; mtd->ecc_stats.corrected += stat;
max_bitflips = max_t(unsigned int, max_bitflips, stat);
} }
return 0; }
return max_bitflips;
} }
/** /**
...@@ -1320,6 +1329,7 @@ static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd, ...@@ -1320,6 +1329,7 @@ static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd,
uint8_t *ecc_code = chip->buffers->ecccode; uint8_t *ecc_code = chip->buffers->ecccode;
uint32_t *eccpos = chip->ecc.layout->eccpos; uint32_t *eccpos = chip->ecc.layout->eccpos;
uint8_t *ecc_calc = chip->buffers->ecccalc; uint8_t *ecc_calc = chip->buffers->ecccalc;
unsigned int max_bitflips = 0;
/* Read the OOB area first */ /* Read the OOB area first */
chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page); chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page);
...@@ -1337,12 +1347,14 @@ static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd, ...@@ -1337,12 +1347,14 @@ static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd,
chip->ecc.calculate(mtd, p, &ecc_calc[i]); chip->ecc.calculate(mtd, p, &ecc_calc[i]);
stat = chip->ecc.correct(mtd, p, &ecc_code[i], NULL); stat = chip->ecc.correct(mtd, p, &ecc_code[i], NULL);
if (stat < 0) if (stat < 0) {
mtd->ecc_stats.failed++; mtd->ecc_stats.failed++;
else } else {
mtd->ecc_stats.corrected += stat; mtd->ecc_stats.corrected += stat;
max_bitflips = max_t(unsigned int, max_bitflips, stat);
} }
return 0; }
return max_bitflips;
} }
/** /**
...@@ -1363,6 +1375,7 @@ static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -1363,6 +1375,7 @@ static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
int eccsteps = chip->ecc.steps; int eccsteps = chip->ecc.steps;
uint8_t *p = buf; uint8_t *p = buf;
uint8_t *oob = chip->oob_poi; uint8_t *oob = chip->oob_poi;
unsigned int max_bitflips = 0;
for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) { for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
int stat; int stat;
...@@ -1379,10 +1392,12 @@ static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -1379,10 +1392,12 @@ static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
chip->read_buf(mtd, oob, eccbytes); chip->read_buf(mtd, oob, eccbytes);
stat = chip->ecc.correct(mtd, p, oob, NULL); stat = chip->ecc.correct(mtd, p, oob, NULL);
if (stat < 0) if (stat < 0) {
mtd->ecc_stats.failed++; mtd->ecc_stats.failed++;
else } else {
mtd->ecc_stats.corrected += stat; mtd->ecc_stats.corrected += stat;
max_bitflips = max_t(unsigned int, max_bitflips, stat);
}
oob += eccbytes; oob += eccbytes;
...@@ -1397,7 +1412,7 @@ static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -1397,7 +1412,7 @@ static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
if (i) if (i)
chip->read_buf(mtd, oob, i); chip->read_buf(mtd, oob, i);
return 0; return max_bitflips;
} }
/** /**
...@@ -1588,7 +1603,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, ...@@ -1588,7 +1603,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
if (oob) if (oob)
ops->oobretlen = ops->ooblen - oobreadlen; ops->oobretlen = ops->ooblen - oobreadlen;
if (ret) if (ret < 0)
return ret; return ret;
if (mtd->ecc_stats.failed - stats.failed) if (mtd->ecc_stats.failed - stats.failed)
......
...@@ -359,7 +359,7 @@ static int flctl_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -359,7 +359,7 @@ static int flctl_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
if (flctl->hwecc_cant_correct[i]) if (flctl->hwecc_cant_correct[i])
mtd->ecc_stats.failed++; mtd->ecc_stats.failed++;
else else
mtd->ecc_stats.corrected += 0; mtd->ecc_stats.corrected += 0; /* FIXME */
} }
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment