From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: Peter Pan <peterpansjtu@gmail.com>,
Arnaud Mouiche <arnaud.mouiche@gmail.com>
Cc: Peter Pan <peterpandong@micron.com>,
Richard Weinberger <richard@nod.at>,
Brian Norris <computersforpeace@gmail.com>,
linux-mtd@lists.infradead.org,
"linshunquan (A)" <linshunquan1@hisilicon.com>
Subject: Re: [PATCH v2 2/6] nand: spi: add basic operations support
Date: Thu, 9 Mar 2017 07:02:13 +0100 [thread overview]
Message-ID: <20170309070213.3eaaa44e@bbrezillon> (raw)
In-Reply-To: <CAAyFOR+vSOSGH_XoZt5Tr5h1fetFUvkMFKGo-iG68obP9eNujg@mail.gmail.com>
On Thu, 9 Mar 2017 09:43:36 +0800
Peter Pan <peterpansjtu@gmail.com> wrote:
> >> +
> >> +/**
> >> + * spinand_do_read_ops - read data from flash to buffer
> >> + * @mtd: MTD device structure
> >> + * @from: offset to read from
> >> + * @ops: oob ops structure
> >> + * Description:
> >> + * Disable internal ECC before reading when MTD_OPS_RAW set.
> >> + */
> >> +static int spinand_do_read_ops(struct mtd_info *mtd, loff_t from,
> >> + struct mtd_oob_ops *ops)
> >> +{
> >> + struct spinand_device *chip = mtd_to_spinand(mtd);
> >> + struct nand_device *nand = mtd_to_nand(mtd);
> >> + int ret;
> >> + struct mtd_ecc_stats stats;
> >> + unsigned int max_bitflips = 0;
> >> + int oobreadlen = ops->ooblen;
> >> + bool ecc_off = ops->mode == MTD_OPS_RAW;
> >> + int ooblen = ops->mode == MTD_OPS_AUTO_OOB ?
> >> + mtd->oobavail : mtd->oobsize;
> >> +
> >> + if (unlikely(from >= mtd->size)) {
> >> + pr_err("%s: attempt to read beyond end of device\n",
> >> + __func__);
> >> + return -EINVAL;
> >> + }
> >
> > Again, we can an helper to check the boundaries in the generic NAND
> > code.
>
> Let's keep the code the same and move to generic NAND code later.
> What do you think Boris?
For things we know will be needed and are simple enough to provide, I'd
recommend doing the modifications now. That's a bit different when it
comes to providing a generic ECC engine infrastructure or trying to
move part of the page read/write logic into the generic NAND layer,
because we don't know where we're going yet.
>
> >
> >> + if (oobreadlen > 0) {
> >> + if (unlikely(ops->ooboffs >= ooblen)) {
> >> + pr_err("%s: attempt to start read outside oob\n",
> >> + __func__);
> >> + return -EINVAL;
> >> + }
> >> + if (unlikely(ops->ooboffs + oobreadlen >
> >> + (nand_len_to_pages(nand, mtd->size) - nand_offs_to_page(nand, from))
> >> + * ooblen)) {
> >> + pr_err("%s: attempt to read beyond end of device\n",
> >> + __func__);
> >> + return -EINVAL;
> >> + }
> >> + ooblen -= ops->ooboffs;
> >> + ops->oobretlen = 0;
> >> + }
> >> + stats = mtd->ecc_stats;
> >> + if (ecc_off)
> >> + spinand_disable_ecc(chip);
> >> + ret = spinand_read_pages(mtd, from, ops, &max_bitflips);
> >> + if (ecc_off)
> >> + spinand_enable_ecc(chip);
> >> + if (ret)
> >> + return ret;
> >> +
> >> + if (mtd->ecc_stats.failed - stats.failed)
> >> + return -EBADMSG;
> >> +
> >> + return max_bitflips;
> >> +}
> >> +
> >
> > [...]
> >
> >> diff --git a/include/linux/mtd/spinand.h b/include/linux/mtd/spinand.h
> >> index f3d0351..ee447c1 100644
> >> --- a/include/linux/mtd/spinand.h
> >> +++ b/include/linux/mtd/spinand.h
> >> @@ -135,6 +135,8 @@ struct spinand_manufacturer_ops {
> >> bool(*detect)(struct spinand_device *chip);
> >> int (*init)(struct spinand_device *chip);
> >> void (*cleanup)(struct spinand_device *chip);
> >> + void (*build_column_addr)(struct spinand_device *chip,
> >> + struct spinand_op *op, u32 page, u32 column);
> >
> > Okay, I think Arnaud was right, maybe we should have vendor specific
> > ops for basic operations like ->prepare_read/write_op(), instead of
> > having these ->get_dummy() and ->build_column_addr() hooks.
> > Or maybe just a ->prepare_op() hook that can prepare things for any
> > basic operation (read, write, ...).
>
> I prefer ->prepare_read_op() and ->prepare_write_op. Fix this in v3
I'd like to have Arnaud's feedback on this. Can you wait a bit before
sending a new version?
next prev parent reply other threads:[~2017-03-09 6:02 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-01 8:52 [PATCH v2 0/6] Introduction to SPI NAND framework Peter Pan
2017-03-01 8:52 ` [PATCH v2 1/6] nand: spi: Add init/release function Peter Pan
2017-03-01 9:58 ` Boris Brezillon
2017-03-03 8:37 ` Peter Pan
2017-03-03 9:28 ` Boris Brezillon
2017-03-03 9:37 ` Arnaud Mouiche
2017-03-03 10:00 ` Boris Brezillon
2017-03-03 10:12 ` Arnaud Mouiche
2017-03-03 10:17 ` Boris Brezillon
2017-03-10 7:50 ` Peter Pan
2017-03-10 9:13 ` Arnaud Mouiche
2017-03-01 13:21 ` Thomas Petazzoni
2017-03-03 8:40 ` Peter Pan
2017-03-01 8:52 ` [PATCH v2 2/6] nand: spi: add basic operations support Peter Pan
2017-03-07 17:57 ` Boris Brezillon
2017-03-09 1:43 ` Peter Pan
2017-03-09 6:02 ` Boris Brezillon [this message]
2017-03-09 17:09 ` Arnaud Mouiche
2017-03-10 1:58 ` Peter Pan
2017-03-10 7:50 ` Arnaud Mouiche
2017-03-01 8:52 ` [PATCH v2 3/6] nand: spi: Add bad block support Peter Pan
2017-03-08 7:23 ` Boris Brezillon
2017-03-08 7:59 ` Peter Pan
2017-03-01 8:52 ` [PATCH v2 4/6] nand: spi: Add BBT support Peter Pan
2017-03-08 8:31 ` Boris Brezillon
2017-03-09 1:58 ` Peter Pan
2017-03-09 6:12 ` Boris Brezillon
2017-03-01 8:52 ` [PATCH v2 5/6] nand: spi: add Micron spi nand support Peter Pan
2017-03-08 8:32 ` Boris Brezillon
2017-03-09 1:59 ` Peter Pan
2017-03-01 8:52 ` [PATCH v2 6/6] nand: spi: Add generic SPI controller support Peter Pan
2017-03-08 8:44 ` Boris Brezillon
2017-03-09 2:02 ` Peter Pan
2017-03-09 6:06 ` 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=20170309070213.3eaaa44e@bbrezillon \
--to=boris.brezillon@free-electrons.com \
--cc=arnaud.mouiche@gmail.com \
--cc=computersforpeace@gmail.com \
--cc=linshunquan1@hisilicon.com \
--cc=linux-mtd@lists.infradead.org \
--cc=peterpandong@micron.com \
--cc=peterpansjtu@gmail.com \
--cc=richard@nod.at \
/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