From: Mike Dunn <mikedunn@newsguy.com>
To: linux-mtd@lists.infradead.org
Subject: Re: [PATCH 12/13] mtd/docg3: add ECC correction code
Date: Mon, 31 Oct 2011 06:16:38 -0700 [thread overview]
Message-ID: <4EAE9FB6.6090200@newsguy.com> (raw)
In-Reply-To: <1319824292-11085-13-git-send-email-robert.jarzmik@free.fr>
Hi Robert,
A few comments (limited to the bch decode for now)...
On 10/28/2011 10:51 AM, Robert Jarzmik wrote:
>
> /**
> + * doc_correct_data - Fix if need be read data from flash
> + * @docg3: the device
> + * @buf: the buffer of read data (512 + 7 + 1 bytes)
> + * @calc_ecc: the hardware calculated ECC
To avoid confusion with the terminology in Ivan's BCH algorithm, I wouldn't call
it calc_ecc. It's actually recv_ecc ^ calc_ecc, where recv_ecc is what the hw
read from the ecc field of the oob data, and calc_ecc is what the hw calculated
from the page data. Maybe just hwecc or similiar.
> + *
> + * Checks if the received data matches the ECC, and if an error is detected,
> + * tries to fix the bit flips (at most 4) in the buffer buf. As the docg3
> + * understands the (data, ecc, syndroms) in an inverted order in comparison to
> + * the BCH library, the function reverses the order of bits (ie. bit7 and bit0,
> + * bit6 and bit 1, ...) for all ECC data.
> + *
> + * Returns number of fixed bits (0, 1, 2, 3, 4) or -EBADMSG if too many bit
> + * errors were detected and cannot be fixed.
> + */
> +static int doc_ecc_bch_fix_data(struct docg3 *docg3, void *buf, u8 *calc_ecc)
> +{
> + u8 ecc[DOC_ECC_BCH_T + 1];
> + int errorpos[DOC_ECC_BCH_T + 1], i, numerrs;
> +
> + for (i = 0; i < DOC_ECC_BCH_SIZE; i++)
> + ecc[i] = bitrev8(calc_ecc[i]);
> + numerrs = decode_bch(docg3_bch, NULL, DOC_ECC_BCH_COVERED_BYTES,
> + NULL, ecc, NULL, errorpos);
This looks right, with the redefined DOC_ECC_BCH_COVERED_BYTES (now 520).
Some commentary would be helpful (though maybe I'm too verbose)...
/*
* The hardware ecc unit produces oob_ecc ^ calc_ecc. The kernel's bch
* algorithm is used to decode this. However the hw operates on page
* data in a bit order that is the reverse of that of the bch alg,
* requiring that the bits be reversed on the result. Thanks to Ivan
* Djelic for his analysis.
*/
I recommend you test this. One way would be to compile the bch algorithm in
userspace and use it to generate the ecc for a 520 byte test vector. Reverse
the bits of this ecc, then flip a few bits in the test vector and write it to a
page in flash, with your driver modified to write the calculated ecc instead of
that served up by the hardware. Then when you read the page, the above code
should identify and correct the bits you flipped (assuming a genuine flash error
did not occur while reading back the page). I have the bch alg modified for
userspace, if that would help.
Alternatively, you could just fill the flash with a fixed pattern, then read all
the pages, waiting for an error to occur so that correct correction (ha) can be
verified.
> + if (numerrs < 0)
> + return numerrs;
I recommend you check for the -EINVAL return value and issue a big fat error.
Maybe BUG_ON(numerrs == -EINVAL), at least for now.
Another explanatory comment here...
/* undo last step in BCH alg (modulo mirroring not needed) */
> +
> + for (i = 0; i < numerrs; i++)
> + errorpos[i] = (errorpos[i] & ~7) | (7 - (errorpos[i] & 7));
> + for (i = 0; i < numerrs; i++)
> + change_bit(errorpos[i], buf);
> +
> + doc_dbg("doc_ecc_bch_fix_data: flipped %d bits\n", numerrs);
> + return numerrs;
> +}
> +
> +
Thanks,
Mike
next prev parent reply other threads:[~2011-10-31 13:17 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-28 17:51 [PATCH 00/13] DocG3 fixes and write support Robert Jarzmik
2011-10-28 17:51 ` Robert Jarzmik
2011-10-28 17:51 ` [PATCH 01/13] mtd/docg3: fix debug log verbosity Robert Jarzmik
2011-10-28 17:51 ` Robert Jarzmik
2011-10-28 17:51 ` [PATCH 02/13] mtd/docg3: fix tracing of IO in writeb Robert Jarzmik
2011-10-28 17:51 ` Robert Jarzmik
2011-10-28 17:51 ` [PATCH 03/13] mtd/docg3: fix protection areas reading Robert Jarzmik
2011-10-28 17:51 ` Robert Jarzmik
2011-10-28 17:51 ` [PATCH 04/13] mtd/docg3: fix BCH registers Robert Jarzmik
2011-10-28 17:51 ` Robert Jarzmik
2011-10-28 17:51 ` [PATCH 05/13] mtd/docg3: add multiple floor support Robert Jarzmik
2011-10-28 17:51 ` Robert Jarzmik
2011-10-31 17:32 ` Mike Dunn
2011-10-31 19:32 ` Robert Jarzmik
2011-11-01 12:59 ` Mike Dunn
2011-10-28 17:51 ` [PATCH 06/13] mtd/docg3: add OOB layout to mtdinfo Robert Jarzmik
2011-10-28 17:51 ` Robert Jarzmik
2011-10-28 17:51 ` [PATCH 07/13] mtd/docg3: add registers for erasing and writing Robert Jarzmik
2011-10-28 17:51 ` Robert Jarzmik
2011-10-28 17:51 ` [PATCH 08/13] mtd/docg3: add OOB buffer to device structure Robert Jarzmik
2011-10-28 17:51 ` Robert Jarzmik
2011-10-28 17:51 ` [PATCH 09/13] mtd/docg3: add write functions Robert Jarzmik
2011-10-28 17:51 ` Robert Jarzmik
2011-10-28 17:51 ` [PATCH 10/13] mtd/docg3: add erase functions Robert Jarzmik
2011-10-28 17:51 ` Robert Jarzmik
2011-10-28 17:51 ` [PATCH 11/13] mtd/docg3: map erase and write functions Robert Jarzmik
2011-10-28 17:51 ` Robert Jarzmik
2011-10-28 17:51 ` [PATCH 12/13] mtd/docg3: add ECC correction code Robert Jarzmik
2011-10-28 17:51 ` Robert Jarzmik
2011-10-29 8:52 ` Ivan Djelic
2011-10-29 8:52 ` Ivan Djelic
2011-10-29 9:09 ` Ivan Djelic
2011-10-29 9:09 ` Ivan Djelic
2011-10-29 16:37 ` Robert Jarzmik
2011-10-29 16:37 ` Robert Jarzmik
2011-10-30 0:10 ` Ivan Djelic
2011-10-30 0:10 ` Ivan Djelic
2011-10-31 13:16 ` Mike Dunn [this message]
2011-10-31 16:39 ` Robert Jarzmik
2011-10-31 17:32 ` Mike Dunn
2011-10-28 17:51 ` [PATCH 13/13] mtd/docg3: add suspend and resume Robert Jarzmik
2011-10-28 17:51 ` Robert Jarzmik
2011-10-30 0:41 ` [PATCH 00/13] DocG3 fixes and write support Marek Vasut
2011-10-30 0:41 ` Marek Vasut
2011-10-30 9:04 ` Robert Jarzmik
2011-10-30 9:04 ` Robert Jarzmik
2011-10-30 21:43 ` Mike Dunn
2011-10-30 21:43 ` Mike Dunn
2011-10-30 22:18 ` Marek Vasut
2011-10-30 22:18 ` Marek Vasut
2011-10-30 21:59 ` Mike Dunn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4EAE9FB6.6090200@newsguy.com \
--to=mikedunn@newsguy.com \
--cc=linux-mtd@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.