On Wed, 27 Feb 2019 15:07:13 +0100 Miquel Raynal <miquel.raynal@xxxxxxxxxxx> wrote: > Hi Boris, > > Boris Brezillon <bbrezillon@xxxxxxxxxx> wrote on Fri, 22 Feb 2019 > 15:44:31 +0100: > > > On Thu, 21 Feb 2019 13:58:04 +0100 > > Miquel Raynal <miquel.raynal@xxxxxxxxxxx> wrote: > > > > > Add the logic in the NAND core to find the right ECC engine depending > > > on the NAND chip requirements and the user desires. Right now, the > > > choice may be made between (more will come): > > > * software Hamming > > > * software BCH > > > * on-die (SPI-NAND devices only) > > > > > > Once the ECC engine has been found, the ECC engine must be > > > configured. > > > > > > Signed-off-by: Miquel Raynal <miquel.raynal@xxxxxxxxxxx> > > > --- > > > drivers/mtd/nand/core.c | 107 +++++++++++++++++++++++++++++++++++++++ > > > include/linux/mtd/nand.h | 4 ++ > > > 2 files changed, 111 insertions(+) > > > > > > diff --git a/drivers/mtd/nand/core.c b/drivers/mtd/nand/core.c > > > index 872d46b5fc0f..9feb118c9f68 100644 > > > --- a/drivers/mtd/nand/core.c > > > +++ b/drivers/mtd/nand/core.c > > > @@ -207,6 +207,113 @@ int nanddev_mtd_max_bad_blocks(struct mtd_info *mtd, loff_t offs, size_t len) > > > } > > > EXPORT_SYMBOL_GPL(nanddev_mtd_max_bad_blocks); > > > > > > +/** > > > + * nanddev_find_ecc_engine() - Find a suitable ECC engine > > > + * @nand: NAND device > > > + */ > > > +static int nanddev_find_ecc_engine(struct nand_device *nand) > > > > Can we pass the conf in argument instead of reading it from > > nand->ecc.user_conf? > > I just changed the root structures, there is a > > struct nand_ecc_conf defaults; > > entry now in the nand_ecc_engine structure, which every layer/driver > can overwrite to inform the NAND core of a default value. > > Later in this function, I check user_conf (which I might call > "desires" now that we have a "defaults" and a "requirements" entries), > but if the value is missing I fallback to the "defaults" one if filled. > Having all these structures being passed as parameters does not make > sense to me so I would prefer sticking to the single "nand" parameter. > > > > > > +{ > > > + bool is_spinand = mtd_type_is_spinand(&nand->mtd); > > > > And here is the reason for the SPINAND type. > > This does not exist anymore as you suggested. > > > > > > + > > > + /* Read the user desires in terms of ECC engine/configuration */ > > > + nand_ecc_read_user_conf(nand); > > > + > > > + /* No ECC engine requestedn, let's return without error */ > > > + if (nand->ecc.user_conf.mode == NAND_ECC_NONE) > > > + return 0; > > > + > > > + /* Raw NAND default mode is hardware */ > > > + if (!is_spinand && nand->ecc.user_conf.mode < 0) > > > + nand->ecc.user_conf.mode = NAND_ECC_HW; > > > > We should let the raw NAND layer take this decision (actually, it's > > even a raw NAND controller driver decision). Please complain if > > user_conf.mode is invalid. > > This way you won't need the SPINAND type you added in one of your > > previous patch. > > See above for the solution I choose. > > > > > > + > > > + /* SPI-NAND default mode is on-die */ > > > + if (is_spinand && nand->ecc.user_conf.mode < 0) > > > + nand->ecc.user_conf.mode = NAND_ECC_ON_DIE; > > > + > > > + switch (nand->ecc.user_conf.mode) { > > > + case NAND_ECC_SOFT: > > > + nand->ecc.engine = nand_ecc_sw_get_engine(nand); > > > + break; > > > + case NAND_ECC_ON_DIE: > > > + if (is_spinand) > > > + nand->ecc.engine = spinand_ondie_ecc_get_engine(); > > > > So, maybe it's worth having the ondie ECC engine instance directly > > embedded in nand_device instead of spinand, or maybe just a pointer, so > > that you don't reserve extra space when the NAND device does not have > > on-die ECC. > > It is now: the nand_ecc_engine structure features a *engine and a > *ondie_engine pointer. > > The nand_ecc_get_ondie_engine(nand) helper just > returns nand->ecc.ondie_engine. Ack to all of this. ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/