From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751917AbeEKFDp (ORCPT ); Fri, 11 May 2018 01:03:45 -0400 Received: from smtp4-g21.free.fr ([212.27.42.4]:43242 "EHLO smtp4-g21.free.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750751AbeEKFDo (ORCPT ); Fri, 11 May 2018 01:03:44 -0400 Subject: Re: [PATCH v2 2/2] mtd: rawnand: fsl_ifc: use bit-wise majority to To: "Wan, Jane (Nokia - US/Sunnyvale)" , Boris Brezillon , Miquel Raynal Cc: "shreeya.patel23498@gmail.com" , "yamada.masahiro@socionext.com" , "richard@nod.at" , "linux-kernel@vger.kernel.org" , "marek.vasut@gmail.com" , "Bos, Ties (Nokia - US/Sunnyvale)" , "prabhakar.kushwaha@nxp.com" , "linux-mtd@lists.infradead.org" , "jagdish.gediya@nxp.com" , "computersforpeace@gmail.com" , "shawnguo@kernel.org" References: From: Chris Moore Message-ID: Date: Fri, 11 May 2018 07:03:31 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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