Hi Richard, Richard Weinberger <richard@xxxxxx> wrote on Thu, 9 Jan 2020 00:49:02 +0100 (CET): > ----- Ursprüngliche Mail ----- > > Von: "Miquel Raynal" <miquel.raynal@xxxxxxxxxxx> > > An: "richard" <richard@xxxxxx>, "Vignesh Raghavendra" <vigneshr@xxxxxx>, "Tudor Ambarus" <Tudor.Ambarus@xxxxxxxxxxxxx>, > > "linux-mtd" <linux-mtd@xxxxxxxxxxxxxxxxxxx> > > CC: "Boris Brezillon" <boris.brezillon@xxxxxxxxxxxxx>, "Thomas Petazzoni" <thomas.petazzoni@xxxxxxxxxxx>, "Boris > > Brezillon" <boris.brezillon@xxxxxxxxxxx>, "Miquel Raynal" <miquel.raynal@xxxxxxxxxxx> > > Gesendet: Montag, 30. Dezember 2019 17:51:25 > > Betreff: [PATCH 4/8] mtd: Add support for emulated SLC mode on MLC NANDs > > > From: Boris Brezillon <boris.brezillon@xxxxxxxxxxx> > > > > MLC NANDs can be made a bit more reliable if we only program the lower > > page of each pair. At least, this solves the paired-pages corruption > > issue. > > > > Signed-off-by: Boris Brezillon <boris.brezillon@xxxxxxxxxxx> > > Signed-off-by: Miquel Raynal <miquel.raynal@xxxxxxxxxxx> > > --- > > drivers/mtd/mtdcore.c | 189 ++++++++++++++++++++++++++++++--- > > drivers/mtd/mtdpart.c | 54 ++++++---- > > include/linux/mtd/mtd.h | 7 +- > > include/linux/mtd/partitions.h | 2 + > > include/uapi/mtd/mtd-abi.h | 1 + > > 5 files changed, 213 insertions(+), 40 deletions(-) > > > > diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c > > index 2916674208b3..de0a692ecb29 100644 > > --- a/drivers/mtd/mtdcore.c > > +++ b/drivers/mtd/mtdcore.c > > @@ -617,6 +617,19 @@ int add_mtd_device(struct mtd_info *mtd) > > !(mtd->flags & MTD_NO_ERASE))) > > return -EINVAL; > > > > + /* > > + * MTD_MLC_IN_SLC_MODE can only be set on partitions, when the master > > I suggest giving a name which indicates that we are actually emulating > an SLC. Maybe MTD_SLC_EMULATION? > Some MLC NANDs support SLC mode in hardware, MTD_MLC_IN_SLC_MODE reads like > this feature. You're right. What about MTD_SLC_ON_MLC_EMULATION? I like to see that we are manipulating MLC NANDs. > > > + * is an MLC NAND and has a proper pairing scheme defined. > > + * We also reject masters that implement ->_writev() for now, because > > + * NAND controller drivers don't implement this hook, and adding the > > + * SLC -> MLC address/length conversion to this path is useless if we > > + * don't have a user. > > + */ > > + if (mtd->flags & MTD_MLC_IN_SLC_MODE && > > + (!mtd_is_partition(mtd) || master->type != MTD_MLCNANDFLASH || > > + !master->pairing || master->_writev)) > > + return -EINVAL; > > + > > mutex_lock(&mtd_table_mutex); > > > > i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL); > > @@ -632,6 +645,14 @@ int add_mtd_device(struct mtd_info *mtd) > > if (mtd->bitflip_threshold == 0) > > mtd->bitflip_threshold = mtd->ecc_strength; > > > > + if (mtd->flags & MTD_MLC_IN_SLC_MODE) { > > + int ngroups = mtd_pairing_groups(master); > > + > > + mtd->erasesize /= ngroups; > > + mtd->size = (u64)mtd_div_by_eb(mtd->size, master) * > > + mtd->erasesize; > > Can we please have a helper for this? You use this formula many times. Absolutely! > > > + } > > + > > if (is_power_of_2(mtd->erasesize)) > > mtd->erasesize_shift = ffs(mtd->erasesize) - 1; > > else > > @@ -1074,9 +1095,11 @@ int mtd_erase(struct mtd_info *mtd, struct erase_info > > *instr) > > { > > struct mtd_info *master = mtd_get_master(mtd); > > u64 mst_ofs = mtd_get_master_ofs(mtd, 0); > > + struct erase_info adjinstr; > > int ret; > > > > instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN; > > + adjinstr = *instr; > > > > if (!mtd->erasesize || !master->_erase) > > return -ENOTSUPP; > > @@ -1091,12 +1114,27 @@ int mtd_erase(struct mtd_info *mtd, struct erase_info > > *instr) > > > > ledtrig_mtd_activity(); > > > > - instr->addr += mst_ofs; > > - ret = master->_erase(master, instr); > > - if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN) > > - instr->fail_addr -= mst_ofs; > > + if (mtd->flags & MTD_MLC_IN_SLC_MODE) { > > + adjinstr.addr = (loff_t)mtd_div_by_eb(instr->addr, mtd) * > > + master->erasesize; > > + adjinstr.len = ((u64)mtd_div_by_eb(instr->addr + instr->len, mtd) * > > + master->erasesize) - > > + adjinstr.addr; > > + } > > + > > + adjinstr.addr += mst_ofs; > > + > > + ret = master->_erase(master, &adjinstr); > > + > > + if (adjinstr.fail_addr != MTD_FAIL_ADDR_UNKNOWN) { > > + instr->fail_addr = adjinstr.fail_addr - mst_ofs; > > + if (mtd->flags & MTD_MLC_IN_SLC_MODE) { > > + instr->fail_addr = mtd_div_by_eb(instr->fail_addr, > > + master); > > + instr->fail_addr *= mtd->erasesize; > > + } > > + } > > > > - instr->addr -= mst_ofs; > > return ret; > > } > > EXPORT_SYMBOL_GPL(mtd_erase); > > @@ -1276,6 +1314,101 @@ static int mtd_check_oob_ops(struct mtd_info *mtd, > > loff_t offs, > > return 0; > > } > > > > +static int mtd_read_oob_std(struct mtd_info *mtd, loff_t from, > > + struct mtd_oob_ops *ops) > > +{ > > + struct mtd_info *master = mtd_get_master(mtd); > > + int ret; > > + > > + from = mtd_get_master_ofs(mtd, from); > > + if (master->_read_oob) > > + ret = master->_read_oob(master, from, ops); > > + else > > + ret = master->_read(master, from, ops->len, &ops->retlen, > > + ops->datbuf); > > + > > + return ret; > > +} > > + > > +static int mtd_write_oob_std(struct mtd_info *mtd, loff_t to, > > + struct mtd_oob_ops *ops) > > +{ > > + struct mtd_info *master = mtd_get_master(mtd); > > + int ret; > > + > > + to = mtd_get_master_ofs(mtd, to); > > + if (master->_write_oob) > > + ret = master->_write_oob(master, to, ops); > > + else > > + ret = master->_write(master, to, ops->len, &ops->retlen, > > + ops->datbuf); > > + > > + return ret; > > +} > > + > > +static int mtd_oob_io_slc(struct mtd_info *mtd, loff_t start, bool read, > > + struct mtd_oob_ops *ops) > > The name is misleading. We don't do OOB IO on a SLC NAND, > we emulate SLC. What would you recommend? mtd_oob_io_emul_slc? > > Thanks, > //richard Thanks, Miquèl ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/