devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lucas Stach <dev-8ppwABl0HbeELgA04lAiVw@public.gmane.org>
To: Brian Norris <computersforpeace-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: David Woodhouse <dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
	Thierry Reding
	<thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>,
	Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Pawel Moll <pawel.moll-5wv7dgnIgG8@public.gmane.org>,
	Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
	Alexandre Courbot
	<gnurou-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Boris BREZILLON
	<boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
	Ezequiel Garcia
	<ezequiel-30ULvvUtt6G51wMPkGsGjgyUoB5FGQPZ@public.gmane.org>,
	Stefan Agner <stefan-XLVq0VzYD2Y@public.gmane.org>,
	Marcel Ziswiler <marcel-mitwqZ+T+m9Wk0Htik3J/w@public.gmane.org>,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: Re: [Patch v3 2/5] mtd: nand: add NVIDIA Tegra NAND Flash controller driver
Date: Mon, 27 Jul 2015 21:12:39 +0200	[thread overview]
Message-ID: <1438024359.2313.4.camel@lynxeye.de> (raw)
In-Reply-To: <20150722231025.GB8876-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>

Hi Brian,

a bit of investigation later I have some coherent answers to your
requests. :)

Am Mittwoch, den 22.07.2015, 16:10 -0700 schrieb Brian Norris:
> Hi,
> 
> On Wed, Jul 22, 2015 at 10:42:40PM +0200, Lucas Stach wrote:
> > Am Dienstag, den 21.07.2015, 14:27 -0700 schrieb Brian Norris:
> > > On Sun, May 10, 2015 at 08:29:59PM +0200, Lucas Stach wrote:
> > > > --- /dev/null
> > > > +++ b/drivers/mtd/nand/tegra_nand.c
> > > > @@ -0,0 +1,801 @@
> ...
> > > > +static int tegra_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip,
> > > > +				uint8_t *buf, int oob_required, int page)
> > > > +{
> ...
> > > > +	value = readl(nand->regs + DEC_STATUS);
> > > > +
> > > > +	if (value & DEC_STATUS_A_ECC_FAIL) {
> > > > +		/*
> > > > +		 * The ECC isn't smart enough to figure out if a page is
> > > > +		 * completely erased and flags an error in this case. So we
> > > > +		 * check the read data here to figure out if it's a legitimate
> > > > +		 * error or a false positive.
> > > > +		 */
> > > > +		int i;
> > > > +		u32 *data = (u32 *)buf;
> > > > +		for (i = 0; i < mtd->writesize / 4; i++) {
> > > > +			if (data[i] != 0xffffffff) {
> > > > +				mtd->ecc_stats.failed++;
> > > > +				return -EBADMSG;
> > > > +			}
> > > > +		}
> > > 
> > > Hmm, what about OOB? It's possible to actually write 0xff to the entire
> > > page. This hunk means that such a data pattern would then be
> > > unprotected. You should probably check that *both* the main and OOB data
> > > are all 0xff; if there are non-0xff bytes, then that (probably, see the
> > > following) means someone intentionally wrote all 0xff to the page. [1]
> > > 
> > 
> > This check is only executed if the ECC engine flagged a non-correctable
> > error. If someone wrote all 0xff to the page there will be a proper ECC
> > checksum calculated and we won't get into this path. So to get this
> > check to wrongly paper over a legitimate error someone would need to
> > write almost all 0xff with a few bits 0, which then flip to a 1
> > afterwards, which is highly unlikely as far as I understand flash
> > technology.
> 
> On second thought, the case I mentioned is not a problem for you
> currently. You'll just have more problems once you start seeing bitflips
> in erased pages.
> 
> And I agree, the latter case you mention is probably pretty unlikely,
> though I'm not really an EE expert to tell you cannot see such a 0->1
> "stuck bit".
> 
> But anyway, why don't you check the spare area too? It turns the
> "unlikely" problem into a non-issue.
> 
If I'm using the HWECC/DMA functions I have no way to check the OOB ECC
area. The controller just skips over it and only transfers user
available OOB data into the buffer. So checking the OOB is unfortunately
not easily done.

> At the same time, I see that you don't support raw page reads/writes. Is
> it impossible? Or is it just an oversight?
> 
It's possible, but I've skipped it for now, as this would increase the
amount of testing I have to do to validate each round of those patches
even more and I don't see much benefit right now. So this remains a
TODO.

[...]
> > > > +	unsigned long rate = clk_get_rate(nand->clk) / 1000000;
> 
> ^^ conversion to MHz? Why? (comment) How about DIV_ROUND_UP, so you
> don't overestimate the clock period (and thus underestimate the number
> of clock periods needed)?
> 
> > > > +	unsigned long period = 1000000 / rate;
> 
> And period is... in picoseconds? It took me a minute to figure that out
> for sure, so IMO it deserves a comment.
> 
> > > > +	const struct nand_sdr_timings *timings;
> > > > +	u32 val, reg = 0;
> > > > +
> > > > +	timings = onfi_async_timing_mode_to_sdr_timings(mode);
> > > > +
> > > > +	val = max3(timings->tAR_min, timings->tRR_min,
> > > > +		   timings->tRC_min) / period;
> 
> DIV_ROUND_UP()? You don't want to lop off a partial timing cycle, right?
> Simliar comments apply throughout. Or please correct me if I'm wrong.
> 

I agree with the reasoning here and made those changes for v4.

> > > > +	if (val > 2)
> > > > +		val -= 3;
> > > > +	reg |= TIMING_TCR_TAR_TRR(val);
> > > > +
> > > > +	val = max(max(timings->tCS_min, timings->tCH_min),
> > > > +		  max(timings->tALS_min, timings->tALH_min)) / period;
> > > > +	if (val > 1)
> > > > +		val -= 2;
> > > > +	reg |= TIMING_TCS(val);
> > > > +
> > > > +	val = (max(timings->tRP_min, timings->tREA_max) + 6000) / period;
> > > > +	reg |= (TIMING_TRP(val) | TIMING_TRP_RESP(val));
> > > > +
> > > > +	reg |= TIMING_TWB(timings->tWB_max / period);
> > > > +	reg |= TIMING_TWHR(timings->tWHR_min / period);
> > > > +	reg |= TIMING_TWH(timings->tWH_min / period);
> > > > +	reg |= TIMING_TWP(timings->tWP_min / period);
> > > > +	reg |= TIMING_TRH(timings->tRHW_min / period);
> > > > +
> > > > +	writel(reg, nand->regs + TIMING_1);
> > > > +
> > > > +	val = timings->tADL_min / period;
> > > > +	if (val > 2)
> > > > +		val -= 3;
> > > > +	reg = TIMING_TADL(val);
> > > > +
> > > > +	writel(reg, nand->regs + TIMING_2);
> > > > +}
> 
Regards,
Lucas

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2015-07-27 19:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-10 18:29 [Patch v3 0/5] Tegra 2 NAND Flash Support Lucas Stach
     [not found] ` <1431282602-7137-1-git-send-email-dev-8ppwABl0HbeELgA04lAiVw@public.gmane.org>
2015-05-10 18:29   ` [Patch v3 1/5] mtd: nand: tegra: add devicetree binding Lucas Stach
     [not found]     ` <1431282602-7137-2-git-send-email-dev-8ppwABl0HbeELgA04lAiVw@public.gmane.org>
2015-07-21 21:05       ` Brian Norris
2015-07-22 20:15         ` Lucas Stach
     [not found]           ` <1437596129.2289.2.camel-8ppwABl0HbeELgA04lAiVw@public.gmane.org>
2015-07-22 22:32             ` Brian Norris
2015-05-10 18:29   ` [Patch v3 2/5] mtd: nand: add NVIDIA Tegra NAND Flash controller driver Lucas Stach
     [not found]     ` <1431282602-7137-3-git-send-email-dev-8ppwABl0HbeELgA04lAiVw@public.gmane.org>
2015-07-21 21:27       ` Brian Norris
     [not found]         ` <20150721212710.GN24125-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2015-07-22 20:42           ` Lucas Stach
     [not found]             ` <1437597760.2289.13.camel-8ppwABl0HbeELgA04lAiVw@public.gmane.org>
2015-07-22 23:10               ` Brian Norris
     [not found]                 ` <20150722231025.GB8876-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2015-07-27 19:12                   ` Lucas Stach [this message]
2015-07-27 19:19           ` Lucas Stach
     [not found]             ` <1438024797.2313.11.camel-8ppwABl0HbeELgA04lAiVw@public.gmane.org>
2015-07-27 20:52               ` Brian Norris
2015-05-10 18:30   ` [Patch v3 3/5] clk: tegra20: init NDFLASH clock to sensible rate Lucas Stach
2015-05-10 18:30   ` [Patch v3 4/5] ARM: tegra: add Tegra20 NAND flash controller node Lucas Stach
2015-05-10 18:30   ` [Patch v3 5/5] ARM: tegra: enable NAND flash on Colibri T20 Lucas Stach
     [not found]     ` <1431282602-7137-6-git-send-email-dev-8ppwABl0HbeELgA04lAiVw@public.gmane.org>
2015-07-21 21:07       ` Brian Norris

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=1438024359.2313.4.camel@lynxeye.de \
    --to=dev-8ppwabl0hbeelga04laivw@public.gmane.org \
    --cc=boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
    --cc=computersforpeace-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=ezequiel-30ULvvUtt6G51wMPkGsGjgyUoB5FGQPZ@public.gmane.org \
    --cc=gnurou-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=marcel-mitwqZ+T+m9Wk0Htik3J/w@public.gmane.org \
    --cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
    --cc=pawel.moll-5wv7dgnIgG8@public.gmane.org \
    --cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=stefan-XLVq0VzYD2Y@public.gmane.org \
    --cc=swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org \
    --cc=thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    /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).