linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: omap2-nand: avoid unaligned DMA accesses, fall back on prefetch method
@ 2012-09-20 15:44 Arnout Vandecappelle (Essensium/Mind)
  2012-09-28  3:35 ` Artem Bityutskiy
  0 siblings, 1 reply; 2+ messages in thread
From: Arnout Vandecappelle (Essensium/Mind) @ 2012-09-20 15:44 UTC (permalink / raw)
  To: linux-mtd, linux-omap, David Woodhouse, Tony Lindgren
  Cc: Arnout Vandecappelle (Essensium/Mind), Sven Krauss

From: "Arnout Vandecappelle (Essensium/Mind)" <arnout@mind.be>

The buffers given to the read_buf and write_buf methods are not
necessarily u32-aligned, while the DMA engine is configured with
32-bit accesses.  As a consequence, the DMA engine gives an error
which appears in the log as follows:

DMA misaligned error with device 4

After this, no accesses to the NAND are possible anymore because the
access never completes.  This usually means the system hangs if the
rootfs is in NAND.

To avoid this, use the prefetch method if the buffer is not aligned.

It's difficult to reproduce the error, because the buffers are
aligned most of the time.

This bug and a patch was originally reported by Sven Krauss in
http://article.gmane.org/gmane.linux.drivers.mtd/34548

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Cc: Sven Krauss <sven.krauss@web.de>
---
Perhaps a better method is to fetch the first few unaligned bytes
with the prefetch method, and then continue with DMA.  However,
since it's hard to force an unaligned buffer, it's also hard to
test that this method works.
---
 drivers/mtd/nand/omap2.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index c719b86..a313e83 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -441,7 +441,7 @@ out_copy:
  */
 static void omap_read_buf_dma_pref(struct mtd_info *mtd, u_char *buf, int len)
 {
-	if (len <= mtd->oobsize)
+	if (len <= mtd->oobsize || !IS_ALIGNED((unsigned long)buf, 4))
 		omap_read_buf_pref(mtd, buf, len);
 	else
 		/* start transfer in DMA mode */
@@ -457,7 +457,7 @@ static void omap_read_buf_dma_pref(struct mtd_info *mtd, u_char *buf, int len)
 static void omap_write_buf_dma_pref(struct mtd_info *mtd,
 					const u_char *buf, int len)
 {
-	if (len <= mtd->oobsize)
+	if (len <= mtd->oobsize || !IS_ALIGNED((unsigned long)buf, 4))
 		omap_write_buf_pref(mtd, buf, len);
 	else
 		/* start transfer in DMA mode */
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mtd: omap2-nand: avoid unaligned DMA accesses, fall back on prefetch method
  2012-09-20 15:44 [PATCH] mtd: omap2-nand: avoid unaligned DMA accesses, fall back on prefetch method Arnout Vandecappelle (Essensium/Mind)
@ 2012-09-28  3:35 ` Artem Bityutskiy
  0 siblings, 0 replies; 2+ messages in thread
From: Artem Bityutskiy @ 2012-09-28  3:35 UTC (permalink / raw)
  To: Arnout Vandecappelle (Essensium/Mind)
  Cc: linux-mtd, linux-omap, David Woodhouse, Tony Lindgren,
	Sven Krauss

[-- Attachment #1: Type: text/plain, Size: 616 bytes --]

On Thu, 2012-09-20 at 17:44 +0200, Arnout Vandecappelle (Essensium/Mind)
wrote:
> It's difficult to reproduce the error, because the buffers are
> aligned most of the time.

Can you just take one of the mtd tests (e.g., mtd_speedtest), amend it a
little and make sure it uses unaligned buffers?

> Perhaps a better method is to fetch the first few unaligned bytes
> with the prefetch method, and then continue with DMA.  However,
> since it's hard to force an unaligned buffer, it's also hard to
> test that this method works.

Yes, this would be a lot cleaner.

-- 
Best Regards,
Artem Bityutskiy

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-09-28  3:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-20 15:44 [PATCH] mtd: omap2-nand: avoid unaligned DMA accesses, fall back on prefetch method Arnout Vandecappelle (Essensium/Mind)
2012-09-28  3:35 ` Artem Bityutskiy

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).