[][OpenWrt Dev][Fix ecc status reporting of mtk-snand driver]
[Description]
Fix the ecc status reporting of mtk-snand driver to make sure the status
can be passed to upper layer, which is required by mtd framework and NMBM
[Release-log]
N/A
Change-Id: Id130372658d167ad6ead0802717bc7c7ea7afd74
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/4529287
diff --git a/target/linux/mediatek/files-5.4/drivers/mtd/mtk-snand/mtk-snand-mtd.c b/target/linux/mediatek/files-5.4/drivers/mtd/mtk-snand/mtk-snand-mtd.c
index 949a3de..3155c68 100644
--- a/target/linux/mediatek/files-5.4/drivers/mtd/mtk-snand/mtk-snand-mtd.c
+++ b/target/linux/mediatek/files-5.4/drivers/mtd/mtk-snand/mtk-snand-mtd.c
@@ -100,8 +100,8 @@
size_t len, ooblen, maxooblen, chklen;
uint32_t col, ooboffs;
uint8_t *datcache, *oobcache;
- bool raw = ops->mode == MTD_OPS_RAW ? true : false;
- int ret;
+ bool ecc_failed = false, raw = ops->mode == MTD_OPS_RAW ? true : false;
+ int ret, max_bitflips = 0;
col = addr & mtd->writesize_mask;
addr &= ~mtd->writesize_mask;
@@ -124,9 +124,17 @@
ret = mtk_snand_read_page(msm->snf, addr, datcache,
oobcache, raw);
- if (ret < 0)
+ if (ret < 0 && ret != -EBADMSG)
return ret;
+ if (ret == -EBADMSG) {
+ mtd->ecc_stats.failed++;
+ ecc_failed = true;
+ } else {
+ mtd->ecc_stats.corrected += ret;
+ max_bitflips = max_t(int, ret, max_bitflips);
+ }
+
if (len) {
/* Move data */
chklen = mtd->writesize - col;
@@ -156,7 +164,7 @@
addr += mtd->writesize;
}
- return 0;
+ return ecc_failed ? -EBADMSG : max_bitflips;
}
static int mtk_snand_mtd_read_oob(struct mtd_info *mtd, loff_t from,