linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Richard Weinberger <richard@nod.at>
To: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Vignesh Raghavendra <vigneshr@ti.com>,
	Tudor Ambarus <Tudor.Ambarus@microchip.com>,
	Boris Brezillon <boris.brezillon@bootlin.com>,
	Boris Brezillon <boris.brezillon@collabora.com>,
	linux-mtd <linux-mtd@lists.infradead.org>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: Re: [PATCH 4/8] mtd: Add support for emulated SLC mode on MLC NANDs
Date: Thu, 9 Jan 2020 00:49:02 +0100 (CET)	[thread overview]
Message-ID: <1518112485.16967.1578527342428.JavaMail.zimbra@nod.at> (raw)
In-Reply-To: <20191230165129.11925-5-miquel.raynal@bootlin.com>

----- Ursprüngliche Mail -----
> Von: "Miquel Raynal" <miquel.raynal@bootlin.com>
> An: "richard" <richard@nod.at>, "Vignesh Raghavendra" <vigneshr@ti.com>, "Tudor Ambarus" <Tudor.Ambarus@microchip.com>,
> "linux-mtd" <linux-mtd@lists.infradead.org>
> CC: "Boris Brezillon" <boris.brezillon@collabora.com>, "Thomas Petazzoni" <thomas.petazzoni@bootlin.com>, "Boris
> Brezillon" <boris.brezillon@bootlin.com>, "Miquel Raynal" <miquel.raynal@bootlin.com>
> 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@bootlin.com>
> 
> 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@bootlin.com>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
> 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.

> +	 * 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.

> +	}
> +
> 	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.

Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2020-01-08 23:49 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-30 16:51 [PATCH 0/8] MLC in SLC mode Miquel Raynal
2019-12-30 16:51 ` [PATCH 1/8] mtd: rawnand: toshiba: Add a specific init for TC58TEG5DCLTA00 Miquel Raynal
2019-12-30 16:51 ` [PATCH 2/8] mtd: rawnand: Define the "distance 3" MLC pairing scheme Miquel Raynal
2019-12-30 16:51 ` [PATCH 3/8] mtd: rawnand: toshiba: Set the pairing scheme for TC58TEG5DCLTA00 Miquel Raynal
2019-12-30 16:51 ` [PATCH 4/8] mtd: Add support for emulated SLC mode on MLC NANDs Miquel Raynal
2020-01-08 23:49   ` Richard Weinberger [this message]
2020-01-09 18:16     ` Miquel Raynal
2020-01-09 18:39       ` Richard Weinberger
2020-01-09 19:19         ` Boris Brezillon
2020-01-09 19:22           ` Miquel Raynal
2020-01-14 10:04     ` Miquel Raynal
2019-12-30 16:51 ` [PATCH 5/8] dt-bindings: mtd: partition: Document the slc-mode property Miquel Raynal
2019-12-31  3:53   ` Florian Fainelli
2020-01-14  9:33     ` Miquel Raynal
2019-12-30 16:51 ` [PATCH 6/8] mtd: partitions: ofpart: Parse " Miquel Raynal
2019-12-30 16:51 ` [PATCH 7/8] mtd: cmdlinepart: Add an slc option to use SLC mode on a part Miquel Raynal
2019-12-30 16:51 ` [PATCH 8/8] ubi: Relax the 'no MLC' rule and allow MLCs operating in SLC mode Miquel Raynal
2020-01-08 23:50   ` Richard Weinberger

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=1518112485.16967.1578527342428.JavaMail.zimbra@nod.at \
    --to=richard@nod.at \
    --cc=Tudor.Ambarus@microchip.com \
    --cc=boris.brezillon@bootlin.com \
    --cc=boris.brezillon@collabora.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=vigneshr@ti.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).