linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arend van Spriel <arend@broadcom.com>
To: Russell King - ARM Linux <linux@arm.linux.org.uk>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Will Deacon <will.deacon@arm.com>
Cc: "linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	David Miller <davem@davemloft.net>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"brcm80211-dev-list@broadcom.com"
	<brcm80211-dev-list@broadcom.com>,
	linux-wireless <linux-wireless@vger.kernel.org>,
	Arnd Bergmann <arnd@arndb.de>
Subject: Re: using DMA-API on ARM
Date: Fri, 5 Dec 2014 13:43:01 +0100	[thread overview]
Message-ID: <5481A855.6000603@broadcom.com> (raw)
In-Reply-To: <20141205094507.GP11285@n2100.arm.linux.org.uk>

On 05-12-14 10:45, Russell King - ARM Linux wrote:
> On Fri, Dec 05, 2014 at 10:22:22AM +0100, Arend van Spriel wrote:
>> For our brcm80211 development we are working on getting brcmfmac driver
>> up and running on a Broadcom ARM-based platform. The wireless device is
>> a PCIe device, which is hooked up to the system behind a PCIe host
>> bridge, and we transfer information between host and device using a
>> descriptor ring buffer allocated using dma_alloc_coherent(). We mostly
>> tested on x86 and seen no issue. However, on this ARM platform
>> (single-core A9) we detect occasionally that the descriptor content is
>> invalid. When this occurs we do a dma_sync_single_for_cpu() and this is
>> retried a number of times if the problem persists. Actually, found out
>> that someone made a mistake by using virt_to_dma(va) to get the
>> dma_handle parameter. So probably we only provided a delay in the retry
>> loop. After fixing that a single call to dma_sync_single_for_cpu() is
>> sufficient. The DMA-API-HOWTO clearly states that:
>>
>> """
>> the hardware should guarantee that the device and the CPU can access the
>> data in parallel and will see updates made by each other without any
>> explicit software flushing.
>> """
>>
>> So it seems incorrect that we would need to do a dma_sync for this
>> memory. That we do need it seems like this memory can end up in
>> cache(?), or whatever happens, in some rare condition. Is there anyway
>> to investigate this situation either through DMA-API or some low-level
>> ARM specific functions.
>
> It's been a long while since I looked at the code, and the code for
> dma_alloc_coherent() has completely changed since then with the
> addition of CMA.  I'm afraid that anything I would say about it would
> not be accurate without research into the possible paths through that
> code - it's no longer just a simple allocator.

I know. On this particular platform we are not using CMA.

> What you say is correct however: the memory should not have any cache
> lines associated with it, if it does, there's a bug somewhere.
>
> Also, the memory will be weakly ordered, which means that writes to such
> memory can be reordered.  If ordering matters, barriers should be used.
> rmb() and wmb() can be used for this.

Ok. You already had a peek in our code checking the memory barriers, 
which does not have the dma_sync_single_for_cpu() "workaround" yet. So 
here some more background. The problem is in DMA_FROM_DEVICE direction. 
Because of the possible reordering issue we first tried using rmb() in 
the retry loop but that did not solve it. Another experiment was to 
ignore the failed ring descriptor entry and proceed. So we get interrupt 
from device and access the ring descriptor entry. This should contain 
expected value X, however we get X-1 back. When proceeding everything 
works find until hitting the same ring descriptor entry again reading 
X-1 when X+1 would be valid. This lead us to the assumption that somehow 
this entry ended up in cache lines. The issue goes away using the 
dma_sync_single_for_cpu() with DMA_FROM_DEVICE in direction parameter. 
We are not longer using virt_to_dma() so that is no longer an issue. So 
is there any function interface to verify cache status.

Regards,
Arend

> (Added Marek for comment on dma_alloc_coherent(), Will for comment on
> barrier stuff.)
>


  parent reply	other threads:[~2014-12-05 12:43 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-05  9:22 using DMA-API on ARM Arend van Spriel
2014-12-05  9:45 ` Russell King - ARM Linux
2014-12-05 12:24   ` Will Deacon
2014-12-05 12:56     ` Hante Meuleman
2014-12-05 13:23       ` Russell King - ARM Linux
2014-12-05 14:20         ` Hante Meuleman
2014-12-05 14:47           ` Arend van Spriel
2014-12-08 13:47           ` Hante Meuleman
2014-12-08 15:01             ` Arnd Bergmann
2014-12-08 15:17               ` Russell King - ARM Linux
2014-12-08 15:22                 ` Arnd Bergmann
2014-12-08 16:03               ` Catalin Marinas
2014-12-08 17:01                 ` Arend van Spriel
2014-12-09 10:19                   ` Arend van Spriel
2014-12-09 10:29                     ` Russell King - ARM Linux
2014-12-09 11:07                       ` Arend van Spriel
2014-12-09 11:54                       ` Catalin Marinas
2015-01-20 15:22                       ` Fabio Estevam
2014-12-08 16:22               ` Arend van Spriel
2014-12-08 16:38                 ` Arnd Bergmann
2014-12-08 16:47                   ` Russell King - ARM Linux
2014-12-08 16:50                   ` Catalin Marinas
2014-12-08 16:54                     ` Russell King - ARM Linux
2014-12-05 15:06         ` Russell King - ARM Linux
2014-12-05 18:28           ` Catalin Marinas
2014-12-05 19:22             ` Arend van Spriel
2014-12-05 19:25               ` Russell King - ARM Linux
2014-12-05 12:43   ` Arend van Spriel [this message]
2014-12-05 12:59     ` Russell King - ARM Linux
2014-12-05  9:52 ` Arnd Bergmann
2014-12-05 11:11   ` Russell King - ARM Linux
2014-12-05 11:49     ` Hante Meuleman
2014-12-05 17:38     ` Catalin Marinas
2014-12-05 18:24       ` Russell King - ARM Linux
2014-12-05 18:31         ` Catalin Marinas
2014-12-05 18:39 ` Catalin Marinas
2014-12-05 18:53   ` Catalin Marinas
2014-12-05 19:50     ` Arend van Spriel
2014-12-08 12:55     ` Johannes Stezenbach
2014-12-08 15:55       ` Catalin Marinas
2014-12-08 16:50         ` Johannes Stezenbach

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=5481A855.6000603@broadcom.com \
    --to=arend@broadcom.com \
    --cc=arnd@arndb.de \
    --cc=brcm80211-dev-list@broadcom.com \
    --cc=davem@davemloft.net \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=m.szyprowski@samsung.com \
    --cc=will.deacon@arm.com \
    /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).