From: Ned Forrester <nforrester-/d+BM93fTQY@public.gmane.org>
To: "J. Scott Merritt" <merrij3-IL7dBOYR4Vg@public.gmane.org>
Cc: david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org,
spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
linux-arm-kernel-xIg/pKzrS19vn6HldHNs0ANdhmdF6hFW@public.gmane.org,
stephen-nl6u4wocdmy51APUEpUfAkEOCMrvLtNR@public.gmane.org
Subject: Re: PXA270 SSP DMA Corruption
Date: Wed, 12 Nov 2008 20:59:12 -0500 [thread overview]
Message-ID: <491B89F0.7070805@whoi.edu> (raw)
In-Reply-To: <491B8783.9050800-/d+BM93fTQY@public.gmane.org>
Ned Forrester wrote:
> J. Scott Merritt wrote:
>> On Wed, 12 Nov 2008 18:10:01 -0500
>> Ned Forrester <nforrester-/d+BM93fTQY@public.gmane.org> wrote:
>>
>>> 2. spidev uses the same buffer for tx and rx. That is supposed to be
>>> allowed, but I don't think pxa2xx_spi handles this case correctly.
>>> pxa2xx_spi handles NULL buffers (for uni-directional transfers), and it
>>> uses dma_map_single to map the rx buffers as DMA_FROM_DEVICE, and the tx
>>> buffer as DMA_TO_DEVICE, without checking whether the rx and tx buffers
>>> are the same. Thus if they are the same, the memory is mapped twice.
>>> "Linux Device Drivers", Corbet, et al. does not address this
>>> possibility, but I bet it is not a good thing to do.
>>>
>>> If you are willing, it looks simple to modify spidev to use two buffers,
>>> and test whether that works better. I agree that spidev should work
>>> either way, but this would be a quick test. If that works, I will
>>> submit a patch for pxa2xx_spi to fix the case of same buffers.
>>>
>>> Alternatively, you might prefer to try fixing map_dma_buffers() and
>>> unmap_dma_buffers() in pxa2xx_spi.c to test this theory. If it works,
>>> that would be the proper fix, anyway. Basically it needs to trap the
>>> case of same address (or even overlapping ranges) and do one
>>> dma_map_single using the DMA_BIDIRECTIONAL flag. Unmapping has to use
>>> the same flag. I think I would choose to make it fail on overlapped but
>>> unequal ranges, and perform correctly for the cases of separate or equal.
>>>
>> [snip performance suggestions]
>>
>> Ned, Thank for your thorough and thoughtful review.
>>
>> It looks like your concerns regarding the duplicate mapping of the
>> overlapping buffers were correct. I tried both suggestions - namely,
>> using two buffers in spidev, as well as cutting back to a single buffer
>> mapped with DMA_BIDIRECTIONAL in pxa2xx_spi.c. Each of these changes
>> (by themselves) seemed to eliminate the data corruption in my simple
>> test program !
>
> That's good. I will write a patch for pxa2xx_spi, unless you would
> rather do it.
>
>> However, I have some lingering concerns regarding the latter solution.
>> >From what little I have read, it appears the DMA-BIDIRECTIONAL is intended
>> for situations where the transfer direction is not know ... it is not
>> immediately clear (to me) that it also handles our case, which might be
>> better described as DMA_SIMULTANEOUS. It is possible that using
>> DMA_BIDIRECTIONAL is sufficient, but without a much deeper understanding
>> of the buffering and caching that is going on between the two independent
>> DMA channel it is difficult for me to speculate.
>
> According to "Linux Device Drivers":
>
> "If data can move in either direction, use DMA_BIDIRECTIONAL."
>
> and
>
> "Incidentally, bounce buffers are one reason why it is important to get
> the direction right. DMA_BIDIRECTIONAL bounce buffers are copied both
> before and after the operation, which is often an unnecessary waste of
> CPU cycles."
>
>>From the general discussion in the book, it is clear that dma mapping
> takes care of issues like flushing cache (for DMA_TO_DEVICE),
> invalidating cache (for DMA_FROM_DEVICE), setting up any I/O memory
> mapping and scatter/gather, etc. Once stream mapped (which
> dma_map_single() does), the CPU is not allowed to touch the memory, and
> once unmapped, the device cannot touch the memory. I think it is clear
> that DMA_BIDIRECTIONAL is for exactly the case where the device will do
> some DMA in each direction before giving the memory back to the CPU.
I should have added that the logic of SPI is that for every byte written
DMA tx), there is a byte read (DMA rx). Because the clocks that read
are generated by the clocks that transmit, the tx word has to be in the
FIFO before the rx word is returned to the FIFO. Thus the tx and rx DMA
channels will never access the same word at the same time, if the tx and
rx buffers start at the same address.
--
Ned Forrester nforrester-/d+BM93fTQY@public.gmane.org
Oceanographic Systems Lab 508-289-2226
Applied Ocean Physics and Engineering Dept.
Woods Hole Oceanographic Institution Woods Hole, MA 02543, USA
http://www.whoi.edu/sbl/liteSite.do?litesiteid=7212
http://www.whoi.edu/hpb/Site.do?id=1532
http://www.whoi.edu/page.do?pid=10079
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
next prev parent reply other threads:[~2008-11-13 1:59 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-11 22:43 PXA270 SSPSFRM gates chip select ? J. Scott Merritt
[not found] ` <20080211174339.73ca7ed5.merrij3-IL7dBOYR4Vg@public.gmane.org>
2008-02-11 22:54 ` Zik Saleeba
[not found] ` <33e9dd1c0802111454k5deeaa38o9d21cee610b79da7-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-02-12 2:51 ` David Brownell
[not found] ` <200802111851.10155.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-02-12 3:15 ` Zik Saleeba
[not found] ` <33e9dd1c0802111915q48cb80ecxb33461a9263f9295-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-02-12 4:02 ` David Brownell
2008-02-12 3:24 ` Ned Forrester
[not found] ` <47B11178.6090904-/d+BM93fTQY@public.gmane.org>
2008-02-12 3:48 ` Zik Saleeba
[not found] ` <33e9dd1c0802111948u2256d0adj8caa478073795d78-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-02-12 4:16 ` David Brownell
2008-02-12 4:19 ` Zik Saleeba
2008-02-12 4:43 ` Ned Forrester
[not found] ` <47B12406.9040208-/d+BM93fTQY@public.gmane.org>
2008-02-12 5:24 ` Zik Saleeba
[not found] ` <33e9dd1c0802112124y5ae8dd39ua9078f2b3878a018-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-02-12 20:48 ` Zik Saleeba
2008-02-12 4:20 ` David Brownell
2008-02-11 23:26 ` Ned Forrester
[not found] ` <47B0D9A4.6080104-/d+BM93fTQY@public.gmane.org>
2008-02-12 4:08 ` Ned Forrester
2008-11-07 16:43 ` PXA270 SSP DMA Corruption J. Scott Merritt
[not found] ` <20081107114312.2f34b389.merrij3-IL7dBOYR4Vg@public.gmane.org>
2008-11-07 18:59 ` Ned Forrester
2008-11-07 19:00 ` PXA270 SSP DMA Corruption - correction J. Scott Merritt
[not found] ` <20081107184819.54baa679.merrij3@rpi.edu>
[not found] ` <491B6249.7070407@whoi.edu>
[not found] ` <491B6249.7070407-/d+BM93fTQY@public.gmane.org>
2008-11-13 1:24 ` PXA270 SSP DMA Corruption J. Scott Merritt
[not found] ` <20081112202438.61c28cf4.merrij3-IL7dBOYR4Vg@public.gmane.org>
2008-11-13 1:48 ` Ned Forrester
[not found] ` <491B8783.9050800-/d+BM93fTQY@public.gmane.org>
2008-11-13 1:59 ` Ned Forrester [this message]
[not found] ` <20081112213403.402948b9.merrij3@rpi.edu>
[not found] ` <20081112213403.402948b9.merrij3-IL7dBOYR4Vg@public.gmane.org>
2008-11-13 3:19 ` Ned Forrester
[not found] ` <20081113120134.70d533c8.merrij3@rpi.edu>
[not found] ` <20081113120134.70d533c8.merrij3-IL7dBOYR4Vg@public.gmane.org>
2008-11-13 18:54 ` Ned Forrester
-- strict thread matches above, loose matches on Subject: below --
2008-11-12 23:14 Ned Forrester
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=491B89F0.7070805@whoi.edu \
--to=nforrester-/d+bm93ftqy@public.gmane.org \
--cc=david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org \
--cc=linux-arm-kernel-xIg/pKzrS19vn6HldHNs0ANdhmdF6hFW@public.gmane.org \
--cc=merrij3-IL7dBOYR4Vg@public.gmane.org \
--cc=spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
--cc=stephen-nl6u4wocdmy51APUEpUfAkEOCMrvLtNR@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.