mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [BUG] spi/spi-atmel: DMA rx buffer corruption with SPI_IOC_MESSAGE
@ 2013-10-08 10:44 Richard Genoud
  2013-10-08 12:13 ` Mark Brown
  2013-10-17 11:01 ` Richard Genoud
  0 siblings, 2 replies; 9+ messages in thread
From: Richard Genoud @ 2013-10-08 10:44 UTC (permalink / raw)
  To: Nicolas Ferre, Mark Brown, Wenyou Yang; +Cc: linux-spi, linux-kernel

Hi all,

I finally found the bug I saw months ago, before "[PATCH v8 3/8]
spi/spi-atmel: add dmaengine support" was merged.

Here it is:

When the ioctl SPI_IOC_MESSAGE is used with small and big buffers,
the big RX buffer is corrupted with bytes from the big TX buffer.
(Small means size < DMA_MIN_BYTES, Big means size > DMA_MIN_BYTES)

I'm attaching the test software that I used ( ./spi_test /dev/spidevx.x )

It fills 3 TX buffers with 0xAA pattern: a small, a big and a small again.
It reads in return 3 RX buffers.
The MISO pin has to be on 3.3v.

It checks if the received buffers are filled with 0xFF (they should
be, as MISO is high).
And I've got a lot of buffers filled partially with 0xAA bytes.

BUT, if you apply this patch:
---8<----
diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
index 83cf609..cde42a4 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -187,7 +187,7 @@
 /* use PIO for small transfers, avoiding DMA setup/teardown overhead and
  * cache operations; better heuristics consider wordsize and bitrate.
  */
-#define DMA_MIN_BYTES  16
+#define DMA_MIN_BYTES  0

 struct atmel_spi_dma {
        struct dma_chan                 *chan_rx;
---8<----
There's no error any more.
So there's something wrong happening when switching from/to pio
transfer to/from DMA.

We didn't saw that at the time of the merge because we did the test
with a loop on MISO/MOSI,
so the RX buffer was corrupted with identical bytes.

Best regards,
Richard.

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

* Re: [BUG] spi/spi-atmel: DMA rx buffer corruption with SPI_IOC_MESSAGE
  2013-10-08 10:44 [BUG] spi/spi-atmel: DMA rx buffer corruption with SPI_IOC_MESSAGE Richard Genoud
@ 2013-10-08 12:13 ` Mark Brown
  2013-10-08 12:34   ` Richard Genoud
  2013-10-08 12:52   ` Richard Genoud
  2013-10-17 11:01 ` Richard Genoud
  1 sibling, 2 replies; 9+ messages in thread
From: Mark Brown @ 2013-10-08 12:13 UTC (permalink / raw)
  To: Richard Genoud; +Cc: Nicolas Ferre, Wenyou Yang, linux-spi, linux-kernel

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

On Tue, Oct 08, 2013 at 12:44:16PM +0200, Richard Genoud wrote:

> I'm attaching the test software that I used ( ./spi_test /dev/spidevx.x )

Looks like the attachment got forgotten?

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [BUG] spi/spi-atmel: DMA rx buffer corruption with SPI_IOC_MESSAGE
  2013-10-08 12:13 ` Mark Brown
@ 2013-10-08 12:34   ` Richard Genoud
  2013-10-08 12:52   ` Richard Genoud
  1 sibling, 0 replies; 9+ messages in thread
From: Richard Genoud @ 2013-10-08 12:34 UTC (permalink / raw)
  To: Mark Brown; +Cc: Nicolas Ferre, Wenyou Yang, linux-spi, linux-kernel

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

2013/10/8 Mark Brown <broonie@kernel.org>:
> On Tue, Oct 08, 2013 at 12:44:16PM +0200, Richard Genoud wrote:
>
>> I'm attaching the test software that I used ( ./spi_test /dev/spidevx.x )
>
> Looks like the attachment got forgotten?
arg !!!

thanks !
here it is.

[-- Attachment #2: spi_test.c --]
[-- Type: text/x-csrc, Size: 2266 bytes --]

#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <linux/spi/spidev.h>


#define SMALL 2
#define BIG 120
#define NB 3

const int FILL_BYTE = 0xaa;
const int RX_BYTE = 0xFF;
const unsigned int MAX_LOOPS = 50;

struct spi_ioc_transfer xfer[NB];
char rx_header[SMALL];
char rx_buffer[BIG];
char rx_footer[SMALL];
char tx_header[SMALL];
char tx_buffer[BIG];
char tx_footer[SMALL];

void dump(char *buf, unsigned int len)
{
	unsigned int i;

	for (i = 0; i < len; i++) {
		printf("%2.2x ", buf[i]);
		if (((i + 1) % 16) == 0)
			printf("\n");
	}
	printf("\n");
}

/*
 * Checks if the buffer buf is filled with val bytes
 * return 0 if it is, 1 if a byte is != val
 */
int check_buf(char *buf, unsigned int len, unsigned int val)
{
	while (len--)
		if (buf[len] != RX_BYTE)
			return 1;
	return 0;
}

void usage(const char *progname)
{
	printf("Usage: %s spidev\n", progname);
}

int main(int argc, char **argv)
{
	const char *spi_dev_name;
	int err = 0;
	int fd;
	unsigned int i;
	unsigned int loops = MAX_LOOPS;

	if (argc < 2) {
		usage(argv[0]);
		err = -1;
		goto out;
	}

	spi_dev_name = argv[1];

	fd = open(spi_dev_name, O_RDWR);
	if (fd < 0) {
		perror("open");
		err = -1;
		goto out;
	}

	xfer[0].tx_buf = (unsigned long)tx_header;
	xfer[0].rx_buf = (unsigned long)rx_header;
	xfer[0].len = SMALL;
	xfer[1].tx_buf = (unsigned long)tx_buffer;
	xfer[1].rx_buf = (unsigned long)rx_buffer;
	xfer[1].len = BIG;
	xfer[2].tx_buf = (unsigned long)tx_footer;
	xfer[2].rx_buf = (unsigned long)rx_footer;
	xfer[2].len = SMALL;

	while (loops--) {
		for (i = 0; i < NB; i++) {
			memset((void *)xfer[i].tx_buf, FILL_BYTE, xfer[i].len);
			memset((void *)xfer[i].rx_buf, FILL_BYTE, xfer[i].len);
		}

		err = ioctl(fd, SPI_IOC_MESSAGE(NB), xfer);
		if (err < 0) {
			perror("ioctl");
			break;
		}
		if (err != (sizeof(rx_buffer) + sizeof(rx_footer)
			    + sizeof(rx_header))) {
			printf("message too short: %d bytes\n", err);
			break;
		}
		for (i = 0; i < NB; i++) {
			err = check_buf((char *)(xfer[i].rx_buf), xfer[i].len, RX_BYTE);
			if (err)
				dump((char *)(xfer[i].rx_buf), xfer[i].len);
		}
	}

	(void) close(fd);
out:
	return err;
}

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

* Re: [BUG] spi/spi-atmel: DMA rx buffer corruption with SPI_IOC_MESSAGE
  2013-10-08 12:13 ` Mark Brown
  2013-10-08 12:34   ` Richard Genoud
@ 2013-10-08 12:52   ` Richard Genoud
  2013-10-08 16:19     ` Mark Brown
  1 sibling, 1 reply; 9+ messages in thread
From: Richard Genoud @ 2013-10-08 12:52 UTC (permalink / raw)
  To: Mark Brown; +Cc: Nicolas Ferre, Wenyou Yang, linux-spi, linux-kernel

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

2013/10/8 Mark Brown <broonie@kernel.org>:
> On Tue, Oct 08, 2013 at 12:44:16PM +0200, Richard Genoud wrote:
>
>> I'm attaching the test software that I used ( ./spi_test /dev/spidevx.x )
>
> Looks like the attachment got forgotten?
arg !!!

thanks !
here it is. (I hope !! Since this morning, I have a *very*
discontinued internet acces with small shooting windows)

[-- Attachment #2: spi_test.c --]
[-- Type: text/x-csrc, Size: 2266 bytes --]

#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <linux/spi/spidev.h>


#define SMALL 2
#define BIG 120
#define NB 3

const int FILL_BYTE = 0xaa;
const int RX_BYTE = 0xFF;
const unsigned int MAX_LOOPS = 50;

struct spi_ioc_transfer xfer[NB];
char rx_header[SMALL];
char rx_buffer[BIG];
char rx_footer[SMALL];
char tx_header[SMALL];
char tx_buffer[BIG];
char tx_footer[SMALL];

void dump(char *buf, unsigned int len)
{
	unsigned int i;

	for (i = 0; i < len; i++) {
		printf("%2.2x ", buf[i]);
		if (((i + 1) % 16) == 0)
			printf("\n");
	}
	printf("\n");
}

/*
 * Checks if the buffer buf is filled with val bytes
 * return 0 if it is, 1 if a byte is != val
 */
int check_buf(char *buf, unsigned int len, unsigned int val)
{
	while (len--)
		if (buf[len] != RX_BYTE)
			return 1;
	return 0;
}

void usage(const char *progname)
{
	printf("Usage: %s spidev\n", progname);
}

int main(int argc, char **argv)
{
	const char *spi_dev_name;
	int err = 0;
	int fd;
	unsigned int i;
	unsigned int loops = MAX_LOOPS;

	if (argc < 2) {
		usage(argv[0]);
		err = -1;
		goto out;
	}

	spi_dev_name = argv[1];

	fd = open(spi_dev_name, O_RDWR);
	if (fd < 0) {
		perror("open");
		err = -1;
		goto out;
	}

	xfer[0].tx_buf = (unsigned long)tx_header;
	xfer[0].rx_buf = (unsigned long)rx_header;
	xfer[0].len = SMALL;
	xfer[1].tx_buf = (unsigned long)tx_buffer;
	xfer[1].rx_buf = (unsigned long)rx_buffer;
	xfer[1].len = BIG;
	xfer[2].tx_buf = (unsigned long)tx_footer;
	xfer[2].rx_buf = (unsigned long)rx_footer;
	xfer[2].len = SMALL;

	while (loops--) {
		for (i = 0; i < NB; i++) {
			memset((void *)xfer[i].tx_buf, FILL_BYTE, xfer[i].len);
			memset((void *)xfer[i].rx_buf, FILL_BYTE, xfer[i].len);
		}

		err = ioctl(fd, SPI_IOC_MESSAGE(NB), xfer);
		if (err < 0) {
			perror("ioctl");
			break;
		}
		if (err != (sizeof(rx_buffer) + sizeof(rx_footer)
			    + sizeof(rx_header))) {
			printf("message too short: %d bytes\n", err);
			break;
		}
		for (i = 0; i < NB; i++) {
			err = check_buf((char *)(xfer[i].rx_buf), xfer[i].len, RX_BYTE);
			if (err)
				dump((char *)(xfer[i].rx_buf), xfer[i].len);
		}
	}

	(void) close(fd);
out:
	return err;
}

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

* Re: [BUG] spi/spi-atmel: DMA rx buffer corruption with SPI_IOC_MESSAGE
  2013-10-08 12:52   ` Richard Genoud
@ 2013-10-08 16:19     ` Mark Brown
  0 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2013-10-08 16:19 UTC (permalink / raw)
  To: Richard Genoud; +Cc: Nicolas Ferre, Wenyou Yang, linux-spi, linux-kernel

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

On Tue, Oct 08, 2013 at 02:52:58PM +0200, Richard Genoud wrote:

> thanks !
> here it is. (I hope !! Since this morning, I have a *very*
> discontinued internet acces with small shooting windows)

Got it.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [BUG] spi/spi-atmel: DMA rx buffer corruption with SPI_IOC_MESSAGE
  2013-10-08 10:44 [BUG] spi/spi-atmel: DMA rx buffer corruption with SPI_IOC_MESSAGE Richard Genoud
  2013-10-08 12:13 ` Mark Brown
@ 2013-10-17 11:01 ` Richard Genoud
  2013-10-21  8:02   ` Yang, Wenyou
  1 sibling, 1 reply; 9+ messages in thread
From: Richard Genoud @ 2013-10-17 11:01 UTC (permalink / raw)
  To: Wenyou Yang; +Cc: linux-spi, linux-kernel, Nicolas Ferre, Mark Brown

2013/10/8 Richard Genoud <richard.genoud@gmail.com>:
> Hi all,
>
> I finally found the bug I saw months ago, before "[PATCH v8 3/8]
> spi/spi-atmel: add dmaengine support" was merged.
>
> Here it is:
>
> When the ioctl SPI_IOC_MESSAGE is used with small and big buffers,
> the big RX buffer is corrupted with bytes from the big TX buffer.
> (Small means size < DMA_MIN_BYTES, Big means size > DMA_MIN_BYTES)
>
> I'm attaching the test software that I used ( ./spi_test /dev/spidevx.x )
>
> It fills 3 TX buffers with 0xAA pattern: a small, a big and a small again.
> It reads in return 3 RX buffers.
> The MISO pin has to be on 3.3v.
>
> It checks if the received buffers are filled with 0xFF (they should
> be, as MISO is high).
> And I've got a lot of buffers filled partially with 0xAA bytes.
>
> BUT, if you apply this patch:
> ---8<----
> diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
> index 83cf609..cde42a4 100644
> --- a/drivers/spi/spi-atmel.c
> +++ b/drivers/spi/spi-atmel.c
> @@ -187,7 +187,7 @@
>  /* use PIO for small transfers, avoiding DMA setup/teardown overhead and
>   * cache operations; better heuristics consider wordsize and bitrate.
>   */
> -#define DMA_MIN_BYTES  16
> +#define DMA_MIN_BYTES  0
>
>  struct atmel_spi_dma {
>         struct dma_chan                 *chan_rx;
> ---8<----
> There's no error any more.
> So there's something wrong happening when switching from/to pio
> transfer to/from DMA.
>
> We didn't saw that at the time of the merge because we did the test
> with a loop on MISO/MOSI,
> so the RX buffer was corrupted with identical bytes.
>
> Best regards,
> Richard.

Hi Wenyou,

Did you have the opportunity to give it a test ?

Thread: https://lkml.org/lkml/2013/10/8/329

Richard.

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

* RE: [BUG] spi/spi-atmel: DMA rx buffer corruption with SPI_IOC_MESSAGE
  2013-10-17 11:01 ` Richard Genoud
@ 2013-10-21  8:02   ` Yang, Wenyou
  2013-10-21  8:26     ` Richard Genoud
  0 siblings, 1 reply; 9+ messages in thread
From: Yang, Wenyou @ 2013-10-21  8:02 UTC (permalink / raw)
  To: Richard Genoud; +Cc: linux-spi, linux-kernel, Ferre, Nicolas, Mark Brown

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 2471 bytes --]

Hi Richard,

> -----Original Message-----
> From: Richard Genoud [mailto:richard.genoud@gmail.com]
> Sent: 2013年10月17日 19:01
> To: Yang, Wenyou
> Cc: linux-spi@vger.kernel.org; linux-kernel@vger.kernel.org; Ferre, Nicolas;
> Mark Brown
> Subject: Re: [BUG] spi/spi-atmel: DMA rx buffer corruption with
> SPI_IOC_MESSAGE
> 
> 2013/10/8 Richard Genoud <richard.genoud@gmail.com>:
> > Hi all,
> >
> > I finally found the bug I saw months ago, before "[PATCH v8 3/8]
> > spi/spi-atmel: add dmaengine support" was merged.
> >
> > Here it is:
> >
> > When the ioctl SPI_IOC_MESSAGE is used with small and big buffers,
> > the big RX buffer is corrupted with bytes from the big TX buffer.
> > (Small means size < DMA_MIN_BYTES, Big means size >
> DMA_MIN_BYTES)
> >
> > I'm attaching the test software that I used ( ./spi_test /dev/spidevx.x )
> >
> > It fills 3 TX buffers with 0xAA pattern: a small, a big and a small again.
> > It reads in return 3 RX buffers.
> > The MISO pin has to be on 3.3v.
> >
> > It checks if the received buffers are filled with 0xFF (they should
> > be, as MISO is high).
> > And I've got a lot of buffers filled partially with 0xAA bytes.
> >
> > BUT, if you apply this patch:
> > ---8<----
> > diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
> > index 83cf609..cde42a4 100644
> > --- a/drivers/spi/spi-atmel.c
> > +++ b/drivers/spi/spi-atmel.c
> > @@ -187,7 +187,7 @@
> >  /* use PIO for small transfers, avoiding DMA setup/teardown overhead
> and
> >   * cache operations; better heuristics consider wordsize and bitrate.
> >   */
> > -#define DMA_MIN_BYTES  16
> > +#define DMA_MIN_BYTES  0
> >
> >  struct atmel_spi_dma {
> >         struct dma_chan                 *chan_rx;
> > ---8<----
> > There's no error any more.
> > So there's something wrong happening when switching from/to pio
> > transfer to/from DMA.
> >
> > We didn't saw that at the time of the merge because we did the test
> > with a loop on MISO/MOSI,
> > so the RX buffer was corrupted with identical bytes.
> >
> > Best regards,
> > Richard.
> 
> Hi Wenyou,
> 
> Did you have the opportunity to give it a test ?
> 
> Thread: https://lkml.org/lkml/2013/10/8/329
I tried to reproduce it with this thread, but I didn't
Which slave device did you use? 

> 
> Richard.

Best Regards,
Wenyou Yang
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

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

* Re: [BUG] spi/spi-atmel: DMA rx buffer corruption with SPI_IOC_MESSAGE
  2013-10-21  8:02   ` Yang, Wenyou
@ 2013-10-21  8:26     ` Richard Genoud
  2013-10-22  2:51       ` Yang, Wenyou
  0 siblings, 1 reply; 9+ messages in thread
From: Richard Genoud @ 2013-10-21  8:26 UTC (permalink / raw)
  To: Yang, Wenyou; +Cc: linux-spi, linux-kernel, Ferre, Nicolas, Mark Brown

2013/10/21 Yang, Wenyou <Wenyou.Yang@atmel.com>:
> Hi Richard,
>
>> -----Original Message-----
>> From: Richard Genoud [mailto:richard.genoud@gmail.com]
>> Sent: 2013年10月17日 19:01
>> To: Yang, Wenyou
>> Cc: linux-spi@vger.kernel.org; linux-kernel@vger.kernel.org; Ferre, Nicolas;
>> Mark Brown
>> Subject: Re: [BUG] spi/spi-atmel: DMA rx buffer corruption with
>> SPI_IOC_MESSAGE
>>
>> 2013/10/8 Richard Genoud <richard.genoud@gmail.com>:
>> > Hi all,
>> >
>> > I finally found the bug I saw months ago, before "[PATCH v8 3/8]
>> > spi/spi-atmel: add dmaengine support" was merged.
>> >
>> > Here it is:
>> >
>> > When the ioctl SPI_IOC_MESSAGE is used with small and big buffers,
>> > the big RX buffer is corrupted with bytes from the big TX buffer.
>> > (Small means size < DMA_MIN_BYTES, Big means size >
>> DMA_MIN_BYTES)
>> >
>> > I'm attaching the test software that I used ( ./spi_test /dev/spidevx.x )
>> >
>> > It fills 3 TX buffers with 0xAA pattern: a small, a big and a small again.
>> > It reads in return 3 RX buffers.
>> > The MISO pin has to be on 3.3v.
>> >
>> > It checks if the received buffers are filled with 0xFF (they should
>> > be, as MISO is high).
>> > And I've got a lot of buffers filled partially with 0xAA bytes.
>> >
>> > BUT, if you apply this patch:
>> > ---8<----
>> > diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
>> > index 83cf609..cde42a4 100644
>> > --- a/drivers/spi/spi-atmel.c
>> > +++ b/drivers/spi/spi-atmel.c
>> > @@ -187,7 +187,7 @@
>> >  /* use PIO for small transfers, avoiding DMA setup/teardown overhead
>> and
>> >   * cache operations; better heuristics consider wordsize and bitrate.
>> >   */
>> > -#define DMA_MIN_BYTES  16
>> > +#define DMA_MIN_BYTES  0
>> >
>> >  struct atmel_spi_dma {
>> >         struct dma_chan                 *chan_rx;
>> > ---8<----
>> > There's no error any more.
>> > So there's something wrong happening when switching from/to pio
>> > transfer to/from DMA.
>> >
>> > We didn't saw that at the time of the merge because we did the test
>> > with a loop on MISO/MOSI,
>> > so the RX buffer was corrupted with identical bytes.
>> >
>> > Best regards,
>> > Richard.
>>
>> Hi Wenyou,
>>
>> Did you have the opportunity to give it a test ?
>>
>> Thread: https://lkml.org/lkml/2013/10/8/329
> I tried to reproduce it with this thread, but I didn't
> Which slave device did you use?

Hi Wenyou,

I'm not using any slave device, I'm just setting the MISO pin to 3.3V,
then I execute the C code ( https://lkml.org/lkml/2013/10/8/329 )
So, we should only receive 0xFF in the buffer.
But i'm getting :
aa aa aa aa aa aa aa aa aa aa aa aa aa aa ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa aa aa aa aa aa aa aa aa aa ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff

Richard.

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

* RE: [BUG] spi/spi-atmel: DMA rx buffer corruption with SPI_IOC_MESSAGE
  2013-10-21  8:26     ` Richard Genoud
@ 2013-10-22  2:51       ` Yang, Wenyou
  0 siblings, 0 replies; 9+ messages in thread
From: Yang, Wenyou @ 2013-10-22  2:51 UTC (permalink / raw)
  To: Richard Genoud
  Cc: linux-spi, linux-kernel, Ferre, Nicolas, Mark Brown, Lin, JM

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 4107 bytes --]



> -----Original Message-----
> From: Richard Genoud [mailto:richard.genoud@gmail.com]
> Sent: 2013年10月21日 16:26
> To: Yang, Wenyou
> Cc: linux-spi@vger.kernel.org; linux-kernel@vger.kernel.org; Ferre, Nicolas;
> Mark Brown
> Subject: Re: [BUG] spi/spi-atmel: DMA rx buffer corruption with
> SPI_IOC_MESSAGE
> 
> 2013/10/21 Yang, Wenyou <Wenyou.Yang@atmel.com>:
> > Hi Richard,
> >
> >> -----Original Message-----
> >> From: Richard Genoud [mailto:richard.genoud@gmail.com]
> >> Sent: 2013年10月17日 19:01
> >> To: Yang, Wenyou
> >> Cc: linux-spi@vger.kernel.org; linux-kernel@vger.kernel.org; Ferre,
> Nicolas;
> >> Mark Brown
> >> Subject: Re: [BUG] spi/spi-atmel: DMA rx buffer corruption with
> >> SPI_IOC_MESSAGE
> >>
> >> 2013/10/8 Richard Genoud <richard.genoud@gmail.com>:
> >> > Hi all,
> >> >
> >> > I finally found the bug I saw months ago, before "[PATCH v8 3/8]
> >> > spi/spi-atmel: add dmaengine support" was merged.
> >> >
> >> > Here it is:
> >> >
> >> > When the ioctl SPI_IOC_MESSAGE is used with small and big buffers,
> >> > the big RX buffer is corrupted with bytes from the big TX buffer.
> >> > (Small means size < DMA_MIN_BYTES, Big means size >
> >> DMA_MIN_BYTES)
> >> >
> >> > I'm attaching the test software that I used ( ./spi_test /dev/spidevx.x )
> >> >
> >> > It fills 3 TX buffers with 0xAA pattern: a small, a big and a small again.
> >> > It reads in return 3 RX buffers.
> >> > The MISO pin has to be on 3.3v.
> >> >
> >> > It checks if the received buffers are filled with 0xFF (they should
> >> > be, as MISO is high).
> >> > And I've got a lot of buffers filled partially with 0xAA bytes.
> >> >
> >> > BUT, if you apply this patch:
> >> > ---8<----
> >> > diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
> >> > index 83cf609..cde42a4 100644
> >> > --- a/drivers/spi/spi-atmel.c
> >> > +++ b/drivers/spi/spi-atmel.c
> >> > @@ -187,7 +187,7 @@
> >> >  /* use PIO for small transfers, avoiding DMA setup/teardown
> overhead
> >> and
> >> >   * cache operations; better heuristics consider wordsize and
> bitrate.
> >> >   */
> >> > -#define DMA_MIN_BYTES  16
> >> > +#define DMA_MIN_BYTES  0
> >> >
> >> >  struct atmel_spi_dma {
> >> >         struct dma_chan                 *chan_rx;
> >> > ---8<----
> >> > There's no error any more.
> >> > So there's something wrong happening when switching from/to pio
> >> > transfer to/from DMA.
> >> >
> >> > We didn't saw that at the time of the merge because we did the test
> >> > with a loop on MISO/MOSI,
> >> > so the RX buffer was corrupted with identical bytes.
> >> >
> >> > Best regards,
> >> > Richard.
> >>
> >> Hi Wenyou,
> >>
> >> Did you have the opportunity to give it a test ?
> >>
> >> Thread: https://lkml.org/lkml/2013/10/8/329
> > I tried to reproduce it with this thread, but I didn't
> > Which slave device did you use?
> 
> Hi Wenyou,
> 
> I'm not using any slave device, I'm just setting the MISO pin to 3.3V,
> then I execute the C code ( https://lkml.org/lkml/2013/10/8/329 )
> So, we should only receive 0xFF in the buffer.
> But i'm getting :
> aa aa aa aa aa aa aa aa aa aa aa aa aa aa ff ff
> ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
> ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
> ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
> ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
> ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
> ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
> ff ff ff ff ff ff ff ff
> aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa
> aa aa aa aa aa aa aa aa aa aa aa aa aa aa ff ff
> ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
> ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
> ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
> ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
> ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
> ff ff ff ff ff ff ff ff
> 
Hi, Richard,

The bug is reproduced.
Tested on at91sam9g25ek, Linux-3.6.9.

> Richard.

Best Regards,
Wenyou Yang
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

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

end of thread, other threads:[~2013-10-22  2:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-08 10:44 [BUG] spi/spi-atmel: DMA rx buffer corruption with SPI_IOC_MESSAGE Richard Genoud
2013-10-08 12:13 ` Mark Brown
2013-10-08 12:34   ` Richard Genoud
2013-10-08 12:52   ` Richard Genoud
2013-10-08 16:19     ` Mark Brown
2013-10-17 11:01 ` Richard Genoud
2013-10-21  8:02   ` Yang, Wenyou
2013-10-21  8:26     ` Richard Genoud
2013-10-22  2:51       ` Yang, Wenyou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®