Using Micron 4-bit on-die ECC with v2.6.36 kernel?
Our current reference Linux kernel for the MAX32590 (JIBE) is based on v2.6.36. (Unfortunately, upgrading to a more recent version is not within the timeframe for solving the current problem.) Our recent reference boards use one of those Micron NAND chips with an on-die 4-bit ECC, which we have basically ignored: To-date, we have simply used the usual 1-bit ECC (i.e., living dangerously!).
This must change, and indeed we now have a case on my desk where, had we been using the on-die ECC, it would have saved us a ton of grief. The problem is our kernel version is far too old to take advantage of any of the recent-ish work for on-die ECC.
Hence, I am looking into the possibility of adding on-die ECC support to our JIBE controller driver specifically for such NAND chips (or at least the specific Micron NAND chip on the reference boards). Broadly, pretending JIBE's H/W directly supports on-die ECC, but actually doing the work in the driver. A similar trick we played in the past (bitwise-inverted ECC (now obsoleted and long-removed from the driver)) suggests this is not too difficult.
I am looking for hints (suggestions), gotchas (warnings), and/or any examples of similar (or other plausible) approaches. Or for something I am overlooking in (or available for) kernels of approximately the vintage we are using.
Thanks & cheers!
-blf-
p.s. At the present time, I am not too interested in the
problem of converting existing boards. This MAY change as the scope and details of the solution become more apparent.
Signature · 3 lines
Brian Foster Principal MTS, Software | La Ciotat, France Maxim Integrated | http://www.maximintegrated.com/
[Resend as plain text...]
Attached is a patch relative to 2.6.27.y. We use it with a 16-bit
wide Micron part needing 4-bit ECC. It works for us, YMMV. I'm pretty sure the raw access is broken badly but we are not using that so it's not a problem from us. The patch assumes that on-die ECC is enabled in the bootstrap loader.
Quoted 39 lines · Brian Foster
Our current reference Linux kernel for the MAX32590 (JIBE) is based on v2.6.36. (Unfortunately, upgrading to a more recent version is not within the timeframe for solving the current problem.) Our recent reference boards use one of those Micron NAND chips with an on-die 4-bit ECC, which we have basically ignored: To-date, we have simply used the usual 1-bit ECC (i.e., living dangerously!).
This must change, and indeed we now have a case on my desk where, had we been using the on-die ECC, it would have saved us a ton of grief. The problem is our kernel version is far too old to take advantage of any of the recent-ish work for on-die ECC.
Hence, I am looking into the possibility of adding on-die ECC support to our JIBE controller driver specifically for such NAND chips (or at least the specific Micron NAND chip on the reference boards). Broadly, pretending JIBE's H/W directly supports on-die ECC, but actually doing the work in the driver. A similar trick we played in the past (bitwise-inverted ECC (now obsoleted and long-removed from the driver)) suggests this is not too difficult.
I am looking for hints (suggestions), gotchas (warnings), and/or any examples of similar (or other plausible) approaches. Or for something I am overlooking in (or available for) kernels of approximately the vintage we are using.
Thanks & cheers!
-blf-p.s. At the present time, I am not too interested in the
problem of converting existing boards. This MAY change as the scope and details of the solution become more apparent.--
Brian Foster
Quoted 7 lines
Principal MTS, Software | La Ciotat, France Maxim Integrated | http://www.maximintegrated.com/______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
drivers/mtd/nand/atmel_nand.c +1 -1
@@ -255,7 +255,7 @@ static int atmel_nand_calculate(struct mtd_info *mtd,* buf: buffer to store read data */ static int atmel_nand_read_page (struct mtd_info *mtd, -struct nand_chip *chip,uint8_t *buf) +struct nand_chip *chip,uint8_t *buf,int page) {int eccsize = chip->ecc.size;int eccbytes = chip->ecc.bytes;
drivers/mtd/nand/nand_base.c +332 -24
483 lines not on this page · raw message
drivers/mtd/nand/nand_bbt.c +6 -2
@@ -1117,7 +1117,9 @@ static uint8_t mirror_pattern[] = {'1', 't', 'b', 'B' };static struct nand_bbt_descr bbt_main_descr = { .options =NAND_BBT_LASTBLOCK |NAND_BBT_CREATE |NAND_BBT_WRITE |NAND_BBT_2BIT |NAND_BBT_VERSION |NAND_BBT_PERCHIP , - .offs =8 , +/* Micron MT29F4G16ABADAWP places ECC at offset 8, so we use 4 +instead (User metadata I). */ + .offs =4 , .len =4 , .veroffs =12 , .maxblocks =4 ,
@@ -1127,7 +1129,9 @@ static struct nand_bbt_descr bbt_main_descr = {static struct nand_bbt_descr bbt_mirror_descr = { .options =NAND_BBT_LASTBLOCK |NAND_BBT_CREATE |NAND_BBT_WRITE |NAND_BBT_2BIT |NAND_BBT_VERSION |NAND_BBT_PERCHIP , - .offs =8 , +/* Micron MT29F4G16ABADAWP places ECC at offset 8, so we use 4 +instead (User metadata I). */ + .offs =4 , .len =4 , .veroffs =12 , .maxblocks =4 ,
include/linux/mtd/nand.h +15 -5
@@ -78,6 +78,8 @@ extern void nand_wait_ready(struct mtd_info *mtd);#define NAND_CMD_RNDIN 0x85#define NAND_CMD_READID 0x90#define NAND_CMD_ERASE2 0xd0 +#define NAND_CMD_GET_FEATURES 0xee +#define NAND_CMD_SET_FEATURES 0xef#define NAND_CMD_RESET 0xff/* Extended commands for large page devices */
@@ -109,6 +111,7 @@ extern void nand_wait_ready(struct mtd_info *mtd);/* Status bits */ #define NAND_STATUS_FAIL 0x01#define NAND_STATUS_FAIL_N1 0x02 +#define NAND_STATUS_REWRITE 0x08#define NAND_STATUS_TRUE_READY 0x20#define NAND_STATUS_READY 0x40#define NAND_STATUS_WP 0x80
@@ -121,6 +124,7 @@ typedef enum {NAND_ECC_SOFT ,NAND_ECC_HW ,NAND_ECC_HW_SYNDROME , +NAND_ECC_HW_ON_DIE , } nand_ecc_modes_t;/*
@@ -178,8 +182,9 @@ typedef enum {#define NAND_HAS_CACHEPROG (chip) ((chip->options & NAND_CACHEPRG))#define NAND_HAS_COPYBACK (chip) ((chip->options & NAND_COPYBACK))/* Large page NAND with SOFT_ECC should support subpage reads */ -#define NAND_SUBPAGE_READ (chip) ((chip->ecc.mode == NAND_ECC_SOFT) \ - && (chip->page_shift > 9)) +#define NAND_SUBPAGE_READ (chip) (((chip->ecc.mode == NAND_ECC_SOFT) || \ + (chip->ecc.mode == NAND_ECC_HW_ON_DIE)) \ + && (chip->page_shift > 9))/* Mask to zero out the chip options, which come from the id table */ #define NAND_CHIPOPTIONS_MSK (0x0000ffff & ~NAND_NO_AUTOINCR)
@@ -270,17 +275,17 @@ struct nand_ecc_ctrl { uint8_t *calc_ecc);int (*read_page_raw)(struct mtd_info *mtd,struct nand_chip *chip, -uint8_t *buf); +uint8_t *buf,int page);void (*write_page_raw)(struct mtd_info *mtd,struct nand_chip *chip,const uint8_t *buf);int (*read_page)(struct mtd_info *mtd,struct nand_chip *chip, -uint8_t *buf); +uint8_t *buf,int page);int (*read_subpage)(struct mtd_info *mtd,struct nand_chip *chip,uint32_t offs,uint32_t len, -uint8_t *buf); +uint8_t *buf,int page);void (*write_page)(struct mtd_info *mtd,struct nand_chip *chip,const uint8_t *buf);
@@ -306,6 +311,8 @@ struct nand_buffers {uint8_t ecccalc[NAND_MAX_OOBSIZE ];uint8_t ecccode[NAND_MAX_OOBSIZE ];uint8_t databuf[NAND_MAX_PAGESIZE +NAND_MAX_OOBSIZE ]; +uint8_t chkbuf[NAND_MAX_PAGESIZE +NAND_MAX_OOBSIZE ]; +uint8_t rawbuf[NAND_MAX_PAGESIZE +NAND_MAX_OOBSIZE ]; };/**
@@ -611,6 +618,9 @@ struct platform_nand_data {struct platform_nand_ctrl ctrl; }; +/* ONFI subfeature parameters length */ +#define ONFI_SUBFEATURE_PARAM_LEN 4 +/* Some helpers to access the data structures */ static inline struct platform_nand_chip *get_platform_nandchip (struct mtd_info *mtd)
Quoted 5 lines · On Wednesday 19-June-2013 14:40:45 David Mosberger-Tang wrote:
Attached is a patch relative to 2.6.27.y. We use it with a 16-bit
wide Micron part needing 4-bit ECC. It works for us, YMMV. I'm pretty sure the raw access is broken badly but we are not using that so it's not a problem from us. The patch assumes that on-die ECC is enabled in the bootstrap loader.
David,
Thanks! I've been working on getting our kernel and Das U-Boot up to a common baseline w.r.t. the NAND-handling (including a on-die compatible BBT layout in the OOB and other details), so I had not looked too closely at your Patch until now-ish....
In examining it, I may have spotted an oddity: When counting bit-flips, you only count them in the main-data area and in the ECC-area (in the OOB). What you do not count are any in the on-die ECC-protected bits in the OOB (which, in fact, happens to be all of .oobfree).
Whilst not necessarily wrong, it does mean you may under-count the true number of ECC-detected bit-flips, under-reporting the number of corrections, and hence (inadvertently?) fooling the system into thinking the block is in better health than it really is.
Or I may mis-understanding something here....
cheers!
-blf-
Signature · 3 lines
Brian Foster Principal MTS, Software | La Ciotat, France Maxim Integrated | http://www.maximintegrated.com/
PATCH 1/1 Init ONFI get/set features in a more logical place
In reply to a message not in the archiveAttached (SORRY! see below) is a Patch based on some work being done on a v2.6.36-based kernel (with parts of more recent MTD/NAND support backported), to add support for Micron on-die ECC to Maxim Integrated's MAX32590 (JIBE) reference boards.
This Patch makes a minor change to initialization order so code between nand_scan_ident() and nand_scan_tail() can easily get (or set) ONFI features.
Since the original Patch is based on that older kernel, I can neither confirm nor deny it builds and works with the latest kernel/MTD/NAND source. However, I also have no reason to believe it won't build or work.
Due to limitations of the e-mail server, the Patch is attached rather then being included inline. Apologies. Even so, the bloody server has _probably_ added CRs (\r), so you will _probably_ have to run the attached Patch through dos2unix(1) before it will apply. ;-\
CC-ed to the author of the original work. Since I do not regularly read this list (linux-mtd), any e-mail not CC-ed to me _may_ not be seen. Apologies!
cheers!
-blf-
Signature · 4 lines
Brian Foster Principal MTS, Software | La Ciotat, France Office: +33 (0)4 42 98 15 35 | Fax: +33 (0)4 42 08 33 19 Maxim Integrated | http://www.maximintegrated.com/
Quoted 1 line
From
400afdd7734c74881e208ae4b7fdb2a3dc2220bbMon Sep 17 00:00:00 2001
From: Brian Foster <[email protected]>
Date: Thu, 4 Jul 2013 13:35:31 +0200
Subject: [PATCH] Init ONFI get/set features in a more logical place
For some reason the ONFI get/set feature handlers were being initialized in nand_scan_tail(), making it rather difficult to use the default handlers after nand_scan_ident(), which determines whether or not the NAND chip is ONFI-compliant.
Move the handler initialization into nand_set_defaults(), where most handlers are initialized.
--- drivers/mtd/nand/nand_base.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/mtd/nand/nand_base.c +5 -6
@@ -2814,6 +2814,11 @@ static void nand_set_defaults(struct nand_chip *chip, int busw)init_waitqueue_head (&chip->controller->wq); } +/* set for ONFI nand */ +if (!chip->onfi_set_features) + chip->onfi_set_features = nand_onfi_set_features; +if (!chip->onfi_get_features) + chip->onfi_get_features = nand_onfi_get_features; }/* Sanitize ONFI strings so we can safely print them */
@@ -3446,12 +3451,6 @@ int nand_scan_tail(struct mtd_info *mtd)if (!chip->write_page) chip->write_page = nand_write_page; -/* set for ONFI nand */ -if (!chip->onfi_set_features) - chip->onfi_set_features = nand_onfi_set_features; -if (!chip->onfi_get_features) - chip->onfi_get_features = nand_onfi_get_features; -/* * Check ECC mode, default to software if 3byte/512byte hardware ECC is * selected and we have 256 byte pagesize fallback to software ECC
Signature · 1 line
1.7.9.5
Quoted 3 lines · On Wednesday 03-July-2013 09:20:47 David Mosberger-Tang wrote:
I think you're right. We use UBI which doesn't use oob at all (apart from ECC bytes) so we're not worried about errors in the OOB-areas that are ECC-protected.
David,
Ok. Pedantically, you are using the OOB in one very small
sense: The OOB is where the BBT marker and version is kept. So UBI does use OOB in, typically, just two (2) blocks. ;-)
In our case, whilst _we_ are like you on our reference boards, potentially some people may use JFFS2 or YAFFS, so I suspect I will include those EEC-checked bytes in the OOB in bit-flip counting.
cheers!
-blf-
Signature · 3 lines
Brian Foster Principal MTS, Software | La Ciotat, France Maxim Integrated | http://www.maximintegrated.com/
Quoted 1 line · On Thursday 04-July-2013 05:37:23 David Mosberger-Tang wrote:
BBT markers don't assume ECC correction (there are multiple copies).
At least in v2.6.36, that is misleading albeit not incorrect. There _is_ a duplicate BBT block (called the “mirror”), but neither it nor the primary BBT block have multiple copies of the BBT marker (or the version). (And, as it happens, the markers differ between the two blocks (I'm not too sure why?).)
So, unless both BBT blocks fail, you _should_ always be able to find and use one. What happens if both happen to fail (in v2.6.36) is not-clear (to me).
I have not checked to see what the situation is in the latest kernel.
Quoted 4 lines
However, I certainly agree that it'd be better to check all bits covered by ECC. It just didn't even cross my mind when we wrote the code in question. Had much bigger fish to fry at the time, like do we need to recall all the devices in the field...
I quite understand! Fortunately for us, there's no reason to recall any of our devices, since they are reference boards that come with the full source, which can be updated from our GIT servers. Hence, the users/developers can do what they like. What it does mean is I have to be a bit careful not to break the existing (“legacy”) situation!
cheers!
-blf-
Signature · 3 lines
Brian Foster Principal MTS, Software | La Ciotat, France Maxim Integrated | http://www.maximintegrated.com/
Re: [PATCH] Init ONFI get/set features in a more logical place
In reply to Brian FosterQuoted 5 lines · Brian Foster
Attached (SORRY! see below) is a Patch based on some work being done on a v2.6.36-based kernel (with parts of more recent MTD/NAND support backported), to add support for Micron on-die ECC to Maxim Integrated's MAX32590 (JIBE) reference boards.
Would you please resend it in-line?
Signature · 2 lines
Best Regards, Artem Bityutskiy