Re: [PATCH v2 2/2] mtd: rawnand: fsl_ifc: use bit-wise majority to

From: Chris Moore
Date: Fri May 11 2018 - 01:03:50 EST


Hi,

Le 04/05/2018 à 04:09, Wan, Jane (Nokia - US/Sunnyvale) a écrit
The following is the reposting of patch with v2 version indication based on comment on "[PATCH 1/2]" (also in the attachment).

Subject: [PATCH v2 2/2] mtd: rawnand: fsl_ifc: use bit-wise majority to
recover the contents of ONFI parameter

Per ONFI specification (Rev. 4.0), if all parameter pages have invalid
CRC values, the bit-wise majority may be used to recover the contents of
the parameter pages from the parameter page copies present.

Signed-off-by: Jane Wan <Jane.Wan@xxxxxxxxx>
---
drivers/mtd/nand/raw/nand_base.c | 36 ++++++++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 72f3a89..464c4fb 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c

[snip]

+ pr_info("Recover ONFI params with bit-wise majority\n");
+ for (j = 0; j < pagesize; j++) {
+ v = 0;
+ for (k = 0; k < 8; k++) {
+ m = 0;
+ for (l = 0; l < 3; l++)
+ m += GET_BIT(k, buf[l*pagesize + j]);
+ if (m > 1)
+ v |= BIT(k);
+ }
+ ((u8 *)p)[j] = v;
+ }

I am not familiar with the context of this but the three way bit-wise majority can be implemented much more efficiently  using the identity:
majority3(a, b, c) = (a & b) | (a & c) | (b & c)
This can be factorized slightly to (a & (b | c)) | (b & c)
This enables the operation to be performed 8, 16, 32 or even 64 bits at a time depending on the hardware.

Cheers,
Chris