All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@collabora.com>
To: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Mason Yang <masonccyang@mxic.com.tw>, Vignesh R <vigneshr@ti.com>,
	Tudor Ambarus <Tudor.Ambarus@microchip.com>,
	Julien Su <juliensu@mxic.com.tw>,
	Richard Weinberger <richard@nod.at>,
	Schrempf Frieder <frieder.schrempf@kontron.de>,
	Marek Vasut <marek.vasut@gmail.com>,
	linux-mtd@lists.infradead.org,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	Brian Norris <computersforpeace@gmail.com>,
	David Woodhouse <dwmw2@infradead.org>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [RFC PATCH 25/27] mtd: nand: Add helpers to manage ECC engines and configurations
Date: Mon, 25 Feb 2019 17:34:22 +0100	[thread overview]
Message-ID: <20190225173414.1836f0a8@kernel.org> (raw)
In-Reply-To: <20190225170118.62739fc4@xps13>

On Mon, 25 Feb 2019 17:01:18 +0100
Miquel Raynal <miquel.raynal@bootlin.com> wrote:

> Hi Boris,
> 
> Boris Brezillon <bbrezillon@kernel.org> wrote on Fri, 22 Feb 2019
> 15:44:31 +0100:
> 
> > On Thu, 21 Feb 2019 13:58:04 +0100
> > Miquel Raynal <miquel.raynal@bootlin.com> 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@bootlin.com>
> > > ---
> > >  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?
> >   
> > > +{
> > > +	bool is_spinand = mtd_type_is_spinand(&nand->mtd);    
> > 
> > And here is the reason for the SPINAND type.
> >   
> > > +
> > > +	/* 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.
> >   
> > > +
> > > +	/* 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.
> >   
> > > +		else
> > > +			pr_err("On-die ECC engines for non SPI devices not supported yet\n");
> > > +		break;
> > > +	case NAND_ECC_HW:
> > > +		pr_err("Hardware ECC engines not supported yet\n");
> > > +		break;
> > > +	default:
> > > +		pr_err("Missing ECC engine property\n");
> > > +	}
> > > +
> > > +	if (!nand->ecc.engine)
> > > +		return  -EINVAL;
> > > +
> > > +	return 0;
> > > +}    
> >   
> 
> I think this is the root patch were our ideas diverge. For me, each
> 'ECC engine' has a _get() helper and the NAND core decides which one to
> call to retrieve the right engine. Can you please explain what was your
> idea if this one does not fit?

Each class of ECC engine has its own way of getting a pointer to an ECC
engine instance:

- ondie: the engine is directly attached to the device and can be
  retrieved by accessing a nand_device field (nanddev->ondie_ecc?).
- sw ECC: you can create a new instance for each device and possibly
  pass the OOB layout you want to use (assuming you don't want to use
  the default one)
- HW-controller-side engine: refers to the controller device (parent
  node) or the device pointed by the ecc-engine DT prop (we'll probably
  need a way to pass this info when for non-DT platforms). For this one
  we'll add a nanddev_get_hw_ecc_engine() which will search for all
  registered HW ECC engines and try to match with some search keys (in
  case of DT, it's the ->of_node pointer address)

Clearly, for SW-based ECC, you'll need more than just the nanddev
object, as layouts can differ depending on the controller driver. So,
what I'm suggesting is to have a

	nand_create_sw_ecc_engine(algo, layout) 

funtion that returns this ECC engine instance which the driver will
then attach to the NAND device.

> 
> Also, the parsing of the DT (in nand_ecc_read_user_conf()) gives me the
> user ECC mode and algo, so I cannot let the raw NAND core (or a raw
> NAND controller driver) or the SPI NAND core decide which mode is the
> default if not provided by the user.

Except this prop is optional in most cases, and the default value is
not always the same, which is why I think this ECC engine retrieval step
should be left to each sub-layer (and sometimes to the controller driver
behind it). Maybe you can provide helpers to help with that, but I
don't think taking this decision here, based on the bus type, is a good
idea. And I also don't like the idea of adding a new SPINAND type.

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

WARNING: multiple messages have this Message-ID (diff)
From: Boris Brezillon <boris.brezillon@collabora.com>
To: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Mason Yang <masonccyang@mxic.com.tw>, Vignesh R <vigneshr@ti.com>,
	Tudor Ambarus <Tudor.Ambarus@microchip.com>,
	Julien Su <juliensu@mxic.com.tw>,
	Richard Weinberger <richard@nod.at>,
	Schrempf Frieder <frieder.schrempf@kontron.de>,
	Marek Vasut <marek.vasut@gmail.com>,
	linux-mtd@lists.infradead.org,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	Brian Norris <computersforpeace@gmail.com>,
	David Woodhouse <dwmw2@infradead.org>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [RFC PATCH 25/27] mtd: nand: Add helpers to manage ECC engines and configurations
Date: Mon, 25 Feb 2019 17:34:22 +0100	[thread overview]
Message-ID: <20190225173414.1836f0a8@kernel.org> (raw)
In-Reply-To: <20190225170118.62739fc4@xps13>

On Mon, 25 Feb 2019 17:01:18 +0100
Miquel Raynal <miquel.raynal@bootlin.com> wrote:

> Hi Boris,
> 
> Boris Brezillon <bbrezillon@kernel.org> wrote on Fri, 22 Feb 2019
> 15:44:31 +0100:
> 
> > On Thu, 21 Feb 2019 13:58:04 +0100
> > Miquel Raynal <miquel.raynal@bootlin.com> 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@bootlin.com>
> > > ---
> > >  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?
> >   
> > > +{
> > > +	bool is_spinand = mtd_type_is_spinand(&nand->mtd);    
> > 
> > And here is the reason for the SPINAND type.
> >   
> > > +
> > > +	/* 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.
> >   
> > > +
> > > +	/* 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.
> >   
> > > +		else
> > > +			pr_err("On-die ECC engines for non SPI devices not supported yet\n");
> > > +		break;
> > > +	case NAND_ECC_HW:
> > > +		pr_err("Hardware ECC engines not supported yet\n");
> > > +		break;
> > > +	default:
> > > +		pr_err("Missing ECC engine property\n");
> > > +	}
> > > +
> > > +	if (!nand->ecc.engine)
> > > +		return  -EINVAL;
> > > +
> > > +	return 0;
> > > +}    
> >   
> 
> I think this is the root patch were our ideas diverge. For me, each
> 'ECC engine' has a _get() helper and the NAND core decides which one to
> call to retrieve the right engine. Can you please explain what was your
> idea if this one does not fit?

Each class of ECC engine has its own way of getting a pointer to an ECC
engine instance:

- ondie: the engine is directly attached to the device and can be
  retrieved by accessing a nand_device field (nanddev->ondie_ecc?).
- sw ECC: you can create a new instance for each device and possibly
  pass the OOB layout you want to use (assuming you don't want to use
  the default one)
- HW-controller-side engine: refers to the controller device (parent
  node) or the device pointed by the ecc-engine DT prop (we'll probably
  need a way to pass this info when for non-DT platforms). For this one
  we'll add a nanddev_get_hw_ecc_engine() which will search for all
  registered HW ECC engines and try to match with some search keys (in
  case of DT, it's the ->of_node pointer address)

Clearly, for SW-based ECC, you'll need more than just the nanddev
object, as layouts can differ depending on the controller driver. So,
what I'm suggesting is to have a

	nand_create_sw_ecc_engine(algo, layout) 

funtion that returns this ECC engine instance which the driver will
then attach to the NAND device.

> 
> Also, the parsing of the DT (in nand_ecc_read_user_conf()) gives me the
> user ECC mode and algo, so I cannot let the raw NAND core (or a raw
> NAND controller driver) or the SPI NAND core decide which mode is the
> default if not provided by the user.

Except this prop is optional in most cases, and the default value is
not always the same, which is why I think this ECC engine retrieval step
should be left to each sub-layer (and sometimes to the controller driver
behind it). Maybe you can provide helpers to help with that, but I
don't think taking this decision here, based on the bus type, is a good
idea. And I also don't like the idea of adding a new SPINAND type.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2019-02-25 16:34 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-21 12:57 [RFC PATCH 13/27] mtd: nand: ecc: Clarify the software Hamming introductory line Miquel Raynal
2019-02-21 12:57 ` Miquel Raynal
2019-02-21 12:57 ` [RFC PATCH 14/27] mtd: nand: ecc: Turn the software Hamming implementation generic Miquel Raynal
2019-02-21 12:57   ` Miquel Raynal
2019-02-21 13:22   ` Boris Brezillon
2019-02-21 13:22     ` Boris Brezillon
2019-02-21 12:57 ` [RFC PATCH 15/27] mtd: nand: Remove useless include about software Hamming ECC Miquel Raynal
2019-02-21 12:57   ` Miquel Raynal
2019-02-21 12:57 ` [RFC PATCH 16/27] mtd: nand: ecc: Let the software BCH ECC engine be a module Miquel Raynal
2019-02-21 12:57   ` Miquel Raynal
2019-02-21 13:48   ` Adam Ford
2019-02-21 13:48     ` Adam Ford
2019-02-21 14:02     ` Miquel Raynal
2019-02-21 14:02       ` Miquel Raynal
2019-02-22 14:24       ` Boris Brezillon
2019-02-22 14:24         ` Boris Brezillon
2019-02-21 12:57 ` [RFC PATCH 17/27] mtd: nand: ecc: Let the software Hamming ECC engine be unselected Miquel Raynal
2019-02-21 12:57   ` Miquel Raynal
2019-02-21 13:20   ` Boris Brezillon
2019-02-21 13:20     ` Boris Brezillon
2019-02-21 13:35     ` Miquel Raynal
2019-02-21 13:35       ` Miquel Raynal
2019-02-21 13:41       ` Boris Brezillon
2019-02-21 13:41         ` Boris Brezillon
2019-02-21 13:46         ` Miquel Raynal
2019-02-21 13:46           ` Miquel Raynal
2019-02-21 12:57 ` [RFC PATCH 18/27] mtd: nand: ecc: Create the software BCH engine instance Miquel Raynal
2019-02-21 12:57   ` Miquel Raynal
2019-02-21 12:57 ` [RFC PATCH 19/27] mtd: nand: ecc: Create the software Hamming " Miquel Raynal
2019-02-21 12:57   ` Miquel Raynal
2019-02-21 12:57 ` [RFC PATCH 20/27] mtd: nand: Let software ECC engines be retrieved from the NAND core Miquel Raynal
2019-02-21 12:57   ` Miquel Raynal
2019-02-22 14:29   ` Boris Brezillon
2019-02-22 14:29     ` Boris Brezillon
2019-02-25 15:49     ` Miquel Raynal
2019-02-25 15:49       ` Miquel Raynal
2019-02-25 16:13       ` Boris Brezillon
2019-02-25 16:13         ` Boris Brezillon
2019-02-26 15:54         ` Miquel Raynal
2019-02-26 15:54           ` Miquel Raynal
2019-02-21 12:58 ` [RFC PATCH 21/27] mtd: spinand: Fix typo in comment Miquel Raynal
2019-02-21 12:58   ` Miquel Raynal
2019-02-22 14:31   ` Boris Brezillon
2019-02-22 14:31     ` Boris Brezillon
2019-02-21 12:58 ` [RFC PATCH 22/27] mtd: spinand: Let the SPI-NAND core flag a SPI-NAND chip Miquel Raynal
2019-02-21 12:58   ` Miquel Raynal
2019-02-22 14:33   ` Boris Brezillon
2019-02-22 14:33     ` Boris Brezillon
2019-02-21 12:58 ` [RFC PATCH 23/27] mtd: spinand: Move the ECC helper functions into a separate file Miquel Raynal
2019-02-21 12:58   ` Miquel Raynal
2019-02-21 12:58 ` [RFC PATCH 24/27] mtd: spinand: Instantiate a SPI-NAND on-die ECC engine Miquel Raynal
2019-02-21 12:58   ` Miquel Raynal
2019-02-22 14:38   ` Boris Brezillon
2019-02-22 14:38     ` Boris Brezillon
2019-02-21 12:58 ` [RFC PATCH 25/27] mtd: nand: Add helpers to manage ECC engines and configurations Miquel Raynal
2019-02-21 12:58   ` Miquel Raynal
2019-02-22 14:44   ` Boris Brezillon
2019-02-22 14:44     ` Boris Brezillon
2019-02-25 16:01     ` Miquel Raynal
2019-02-25 16:01       ` Miquel Raynal
2019-02-25 16:34       ` Boris Brezillon [this message]
2019-02-25 16:34         ` Boris Brezillon
2019-02-25 18:48         ` Boris Brezillon
2019-02-25 18:48           ` Boris Brezillon
2019-02-26 15:59           ` [RFC PATCH 25/27] mtd: nand: Add helpers to manage ECC engines and configurationsND Miquel Raynal
2019-02-26 15:59             ` Miquel Raynal
2019-02-26 16:04             ` Boris Brezillon
2019-02-26 16:04               ` Boris Brezillon
2019-02-27 14:07     ` [RFC PATCH 25/27] mtd: nand: Add helpers to manage ECC engines and configurations Miquel Raynal
2019-02-27 14:07       ` Miquel Raynal
2019-02-27 14:30       ` Boris Brezillon
2019-02-27 14:30         ` Boris Brezillon

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=20190225173414.1836f0a8@kernel.org \
    --to=boris.brezillon@collabora.com \
    --cc=Tudor.Ambarus@microchip.com \
    --cc=computersforpeace@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=frieder.schrempf@kontron.de \
    --cc=juliensu@mxic.com.tw \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marek.vasut@gmail.com \
    --cc=masonccyang@mxic.com.tw \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.