linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marek Vasut <marex-ynQEQJNshbs@public.gmane.org>
To: Michal Suchanek <hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Vinod Koul <vinod.koul-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
	MTD Maling List
	<linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>,
	"linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org"
	<linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>,
	"linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"linux-spi" <linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	dmaengine <dmaengine-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH 08/11] MTD: m25p80: Add option to limit SPI transfer size.
Date: Thu, 30 Jul 2015 14:33:44 +0200	[thread overview]
Message-ID: <201507301433.45008.marex@denx.de> (raw)
In-Reply-To: <CAOMqctTQ906nu4_VjXWDRZ23uRbxEHMTKs6TpYy+g9EBAd1M7Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

On Thursday, July 30, 2015 at 02:18:09 PM, Michal Suchanek wrote:
> On 30 July 2015 at 13:24, Marek Vasut <marex-ynQEQJNshbs@public.gmane.org> wrote:
> > On Monday, July 27, 2015 at 10:43:05 PM, Michal Suchanek wrote:
> >> On 27 July 2015 at 19:43, Marek Vasut <marex-ynQEQJNshbs@public.gmane.org> wrote:
> >> > On Monday, July 27, 2015 at 11:46:25 AM, Michal Suchanek wrote:
> >> >> On 24 July 2015 at 10:34, Marek Vasut <marex-ynQEQJNshbs@public.gmane.org> wrote:
> >> >> > On Thursday, July 23, 2015 at 07:03:47 PM, Michal Suchanek wrote:
> >> >> Ok, so here is some summary.
> >> >> 
> >> >> I have a NOR flash attached to a s3c64xx SPI controller with 64byte
> >> >> fifo and a pl330 dma controller.
> >> >> 
> >> >> Normally DMA controller is used for transfers that do not fit into
> >> >> the FIFO.
> >> >> 
> >> >> I tried adding the flash memory ID to the spi-nor driver table and
> >> >> adding a DT node for it.
> >> >> 
> >> >> The flash is rated at 120MHz so I used that speed but the ID was
> >> >> bit-shifted and identification failed. There is DT property
> >> >> samsung,spi-feedback-delay for addressing this and at 120MHz it must
> >> >> be 2 or 3 on this board. 40MHz works with default value 0.
> >> >> 
> >> >> The next step after identification worked was to try reading the
> >> >> flash content. For this the DMA controller is used because data is
> >> >> transferred in blocks larger than 64 bytes. When reading the whole
> >> >> 4MB flash the transfer failed silently. I got a 4MB file of all ones
> >> >> or all zeroes.
> >> >> 
> >> >> It turns out that
> >> >> 
> >> >>  - the pl330 locks up when transfering large amount of data.
> >> >> 
> >> >> Specifically, the maximum power of 2 sized transfer at 120MHz is 128
> >> >> bytes and 64k at 40MHz. Transferring more than this results in the
> >> >> pl330 locking up and never signalling completion of the transfer.
> >> > 
> >> > Hypothesis:
> >> > I think this might just be that the controller didn't catch all the
> >> > inbound clock ticks and thus counted less inbound data than it was
> >> > set up to receive. The controller thus waits for more data.
> >> 
> >> The flash chip can transfer data as long as you keep the clock going,
> >> especially when you transfer 64k off a 4M flash.
> >> 
> >> The read command is bound just by stopping the clock. There is always
> >> more data to be had.
> > 
> > Sure, if you keep clocking the chip, the data will keep going. Is the
> > chip being clocked ?
> 
> There is always data. Like in whenever you want to read SPI data you
> sample the input pin and watever you sample is data so far as SPI bus
> is concerned.

Aren't you forgetting that the data are synchronous to the clock which you
(your SPI block) generate ?

> > Doesn't the PL330 have some kind of a counter register where you can
> > check how much data were received so far ? That should be sufficient to
> > verify this hypothesis of mine.
> 
> Could check that, yes. Maybe I could read the counter in a function
> which dmaengine client uses to tear down the dma transfer.

Might be a good idea. Check if the register is stuck for too long and
then zap the transfer.

> On a related note I enabled more prints on the spidev test program.
> 
> I have code that tests maximum transfer size up to the 4k spidev limit
> and it can transfer full 4k buffer of NOPs at 80MHz.
> 
> The recieved data is all ones except a 00 at the start. So it looks
> like read-only transfers fail but full-duplex sort of work. And it
> reproduces the 00 prefix that was seen in the dma-only setup in
> otherwise working setup :-S
> 
> An attempt to read a page of data using the fast-read command fails
> with timeout.

It would be a good idea to detail what your program exactly does on
the bus (like, "my program sends 3 bytes of data 0xf0 0x0b 0xar and
then receives 60 bytes of data").  Maybe I'm lost, but your test is
really not clear.

> >> >> Data
> >> >> is left in FIFO which causes subsequent commands to fail since
> >> >> garbage is returned instead of command reply. Also subsequent read
> >> >> may cause I/O error or or return an empty page depending on the
> >> >> garbage around.
> >> > 
> >> > So the driver for the DMA controller might need to be augmented to
> >> > handle this case -- add a timeout and in case DMA times out, drain
> >> > the FIFO to make sure subsequent transfers do not fail.
> >> 
> >> There is no way to add timeout in the DMA driver since it does not
> >> know the SPI clock.
> >> 
> >> The timeout is handled by the SPI driver and it should be possible to
> >> augment it to drain the FIFO when DMA fails so long as FIFO level is
> >> readable somewhere.
> > 
> > If the DMA doesn't complete in certain amount of time, it should time out
> > I'd say. Don't you think ?
> 
> No. The DMA  driver has no idea if the transfer is at 133MHz, 40MHz,
> 1MHz, 1kHz, whatever.

That's not really important, is it ? If the transfer doesn't finish in, say,
1 second, and it is a 4096b transfer, then it is most likely timeout.

> On the other hand, adding a flush_fifo in the SPI driver after DMA
> failure allows probing the chip reliably by realoding the driver even
> just after a failed transfer.

OK

> >> >> - the I/O errors are not checked in spi-nor at all which leads to
> >> >> silent data corruption.
> >> >> 
> >> >> On a suggestion that this may improve reliability I changed the
> >> >> s3c64xx driver to use DMA for all transfers. This caused
> >> >> identification to fail in spin-nor because the ID was prefixed with
> >> >> extra 00  byte. Testing with spidev confirmed that everything is
> >> >> prefixed with extra 00.
> >> > 
> >> > The determinism of this is in fact excellent news.
> >> > 
> >> >> Also when the DMA controller locked up no
> >> >> transfers were possible anymore. When DMA was not used for sending
> >> >> commands the controller would recover on next command. I made the
> >> >> option to always use DMA configurable and it turns out that the
> >> >> returned data is prefixed with 00 only when no transfer without DMA
> >> >> was ever made. Loading the spi-nor driver with the dma-only option
> >> >> off and then with dma-only option on results in correct operation.
> >> >> Only loading the dma-only driver first causes the 00 prefix.
> >> > 
> >> > Can we conclude that the PIO codepath somehow programs a register
> >> > somewhere which gets rid of this 0x00 prefix ? If so, this should then
> >> > also be part of the DMA codepath, or even better, this should be set
> >> > in probe() somewhere.
> >> 
> >> Yes, it looks like it.
> > 
> > Did you find what this could be please ?
> 
> The suspicious function is enable_datapath in the s3c64xx driver.
> There is even a comment about keeping the clock going on half-duplex
> transfers.
> 
> I did not get to dissecting it so far.

Good luck!
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" 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-30 12:33 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1433364398.git.hramrach@gmail.com>
2015-06-03 22:53 ` [PATCH 00/11] Enable access to SPI NOR flash on Samsung Snow board Marek Vasut
2015-06-04  4:21   ` Michal Suchanek
     [not found]     ` <CAOMqctRkoQrP7wAgXfWXHb2fbi2-6VayHRx5DgUKn6Djz0qtQQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-06-04 15:29       ` Marek Vasut
     [not found] ` <8fc4b9f5291a509c4c35782a1337bf536f1019af.1433364398.git.hramrach@gmail.com>
2015-06-03 23:03   ` [PATCH 08/11] MTD: m25p80: Add option to limit SPI transfer size Marek Vasut
     [not found]     ` <201506040103.09555.marex-ynQEQJNshbs@public.gmane.org>
2015-06-04  4:31       ` Michal Suchanek
2015-06-04 15:15         ` Marek Vasut
     [not found]   ` <8fc4b9f5291a509c4c35782a1337bf536f1019af.1433364398.git.hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-06-04  6:42     ` Geert Uytterhoeven
2015-06-04  8:31       ` Michal Suchanek
2015-06-04 17:15         ` Richard Cochran
     [not found]           ` <20150604171547.GA1530-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2015-07-15  9:45             ` Michal Suchanek
2015-07-15 11:52               ` Marek Vasut
     [not found]                 ` <201507151352.27689.marex-ynQEQJNshbs@public.gmane.org>
2015-07-15 15:59                   ` Brian Norris
2015-07-15 17:15                     ` Marek Vasut
2015-07-16  1:19                       ` Brian Norris
2015-07-16  1:44                         ` Marek Vasut
2015-07-19 19:01                     ` Michal Suchanek
2015-07-21  4:29                       ` Vinod Koul
2015-07-21  8:14                         ` Michal Suchanek
     [not found]                           ` <CAOMqctSzzUV1J8Vj03XJ3Y70R9ynVErP4RZVtbjarDcZ9JLnaw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-22  4:49                             ` Vinod Koul
2015-07-22  7:30                               ` Michal Suchanek
     [not found]                                 ` <CAOMqctQH4MnKMthOnuPgB-A5k6PCOAmhwHzJfn7gE3R4w8bufg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-22  7:33                                   ` Marek Vasut
2015-07-22  7:45                                     ` Michal Suchanek
     [not found]                                       ` <CAOMqctTmRy0gOchdUQ+VnoV-oJz0v9NpUPLi1pxO_O9QrLXsZA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-22  7:58                                         ` Marek Vasut
2015-07-22  8:18                                           ` Michal Suchanek
     [not found]                                             ` <CAOMqctQ13JE+GHyj+hU4XL3Uz4+Yt_X6BFU=NO8jXcpRtzMyzQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-22  8:24                                               ` Marek Vasut
     [not found]                                                 ` <201507221024.05496.marex-ynQEQJNshbs@public.gmane.org>
2015-07-22  8:38                                                   ` Michal Suchanek
2015-07-22  9:01                                                     ` Marek Vasut
2015-07-23 16:46                                                       ` Michal Suchanek
2015-07-23 17:03                                                         ` Michal Suchanek
2015-07-24  8:34                                                           ` Marek Vasut
2015-07-24 11:20                                                             ` Michal Suchanek
     [not found]                                                             ` <201507241034.15406.marex-ynQEQJNshbs@public.gmane.org>
2015-07-27  9:46                                                               ` Michal Suchanek
2015-07-27 17:43                                                                 ` Marek Vasut
     [not found]                                                                   ` <201507271943.32453.marex-ynQEQJNshbs@public.gmane.org>
2015-07-27 20:43                                                                     ` Michal Suchanek
2015-07-30 11:24                                                                       ` Marek Vasut
2015-07-30 12:18                                                                         ` Michal Suchanek
     [not found]                                                                           ` <CAOMqctTQ906nu4_VjXWDRZ23uRbxEHMTKs6TpYy+g9EBAd1M7Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-30 12:33                                                                             ` Marek Vasut [this message]
     [not found] ` <3234c12c90eabbeeb6d33604a324231937e309ec.1433364398.git.hramrach@gmail.com>
     [not found]   ` <3234c12c90eabbeeb6d33604a324231937e309ec.1433364398.git.hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-06-04  2:04     ` [PATCH 11/11] dt: Exynos: add Snow SPI NOR node Krzysztof Kozlowski
     [not found]   ` <556FB222.2070406@samsung.com>
2015-06-04 15:20     ` Marek Vasut
     [not found]       ` <201506041720.54666.marex-ynQEQJNshbs@public.gmane.org>
2015-06-17 12:19         ` Pavel Machek
     [not found] ` <d47abe28c751b54b839d9340269a2c06a6e23a6c.1433364398.git.hramrach@gmail.com>
     [not found]   ` <d47abe28c751b54b839d9340269a2c06a6e23a6c.1433364398.git.hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-06-04  2:05     ` [PATCH 01/11] ARM: dt: Add SPI CS on Samsung Snow board Krzysztof Kozlowski
2015-06-04  6:52     ` Javier Martinez Canillas
     [not found] ` <305830ebf9c0ae98c4f6e0ebbdec7414d6762b36.1433364398.git.hramrach@gmail.com>
2015-06-03 23:04   ` [PATCH 10/11] spi: add more debug prints in s3c64xx Marek Vasut
2015-06-04  9:16   ` Mark Brown
2015-06-04  9:30     ` Geert Uytterhoeven
     [not found]       ` <CAMuHMdWHPm6exq4O3CNvVuiZOgLHuxyCrR548BFmbOPikvNRLw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-06-04  9:42         ` Mark Brown
     [not found]     ` <20150604091634.GY14071-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-06-04  9:33       ` Michal Suchanek
2015-06-04 10:26         ` Mark Brown
2015-06-04 10:52           ` Michal Suchanek
     [not found]             ` <CAOMqctRFXWT3m8H4YBH0tzQAL3Y2NUs6XCo2LiF1R0Xz+iWUzw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-06-04 10:56               ` Mark Brown
     [not found] ` <14872fc6f86b7f4976d539b47a7899904cd954f6.1433364398.git.hramrach@gmail.com>
     [not found]   ` <14872fc6f86b7f4976d539b47a7899904cd954f6.1433364398.git.hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-06-04  2:10     ` [PATCH 09/11] dma: pl330: fix wording in mcbufsz message Krzysztof Kozlowski
2015-06-08 11:07   ` Vinod Koul
     [not found] ` <36e315552c849a4d22ac0fcff7958f6ffcafb160.1433364398.git.hramrach@gmail.com>
     [not found]   ` <36e315552c849a4d22ac0fcff7958f6ffcafb160.1433364398.git.hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-06-03 22:58     ` [PATCH 04/11] mtd: ofpart: do not fail probe when no partitions exist Marek Vasut
     [not found]       ` <201506040058.52882.marex-ynQEQJNshbs@public.gmane.org>
2015-06-04  4:54         ` Michal Suchanek
     [not found]           ` <CAOMqctTB2AYOQZUc9o-R4PF1DQ-HY0RfSw5T-T28r5uP2s=qZA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-06-04 15:28             ` Marek Vasut
2015-06-04 15:40               ` Michal Suchanek
2015-06-05 14:13                 ` Marek Vasut
2015-06-23 18:26   ` 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=201507301433.45008.marex@denx.de \
    --to=marex-ynqeqjnshbs@public.gmane.org \
    --cc=dmaengine-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=vinod.koul-ral2JQCrhuEAvxtiuMwx3w@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).