linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: Arnd Bergmann <arnd@arndb.de>
Cc: linux-arm-kernel@lists.infradead.org,
	Arend van Spriel <arend@broadcom.com>,
	linux-wireless <linux-wireless@vger.kernel.org>,
	"brcm80211-dev-list@broadcom.com"
	<brcm80211-dev-list@broadcom.com>,
	David Miller <davem@davemloft.net>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: using DMA-API on ARM
Date: Fri, 5 Dec 2014 11:11:14 +0000	[thread overview]
Message-ID: <20141205111114.GQ11285@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <4565667.WCBuNmaazQ@wuerfel>

On Fri, Dec 05, 2014 at 10:52:02AM +0100, Arnd Bergmann wrote:
> I'm still puzzled why you'd need a single dma_sync_single_for_cpu()
> after dma_alloc_coherent though, you should not need any. Is it possible
> that the driver accidentally uses __raw_readl() instead of readl()
> in some places and you are just lacking an appropriate barrier?

Digging into the driver, it looks like individual DMA buffers are
allocated (via brcmf_pcie_init_dmabuffer_for_device) and registered
into a "commonring" layer.

Whenever the buffer is written to, space is first allocated via a call
to brcmf_commonring_reserve_for_write() or
brcmf_commonring_reserve_for_write_multiple(), data written to the
buffer, followed by a call to brcmf_commonring_write_complete().

brcmf_commonring_write_complete() calls two methods at that point:
cr_write_wptr() and cr_ring_bell(), which will be
brcmf_pcie_ring_mb_write_wptr() and brcmf_pcie_ring_mb_ring_bell().

The first calls brcmf_pcie_write_tcm16(), which uses iowrite16(),
which contains the appropriate barrier.  The bell ringing functions
also use ioread*/iowrite*().

So, on the write side, it looks fine from the barrier perspective.

On the read side, brcmf_commonring_get_read_ptr() is used before
a read access to the ring - which calls the cr_update_wptr() method,
which in turn uses an ioread16() call.  After the CPU has read data
from the ring, brcmf_commonring_read_complete() is used, which uses
iowrite16().

So, I don't see a barrier problem on the read side.

However, I did trip over this:

static void *
brcmf_pcie_init_dmabuffer_for_device(struct brcmf_pciedev_info *devinfo,
                                     u32 size, u32 tcm_dma_phys_addr,
                                     dma_addr_t *dma_handle)
{
        void *ring;
        long long address;

        ring = dma_alloc_coherent(&devinfo->pdev->dev, size, dma_handle,
                                  GFP_KERNEL);
        if (!ring)
                return NULL;

        address = (long long)(long)*dma_handle;

Casting to (long) will truncate the DMA handle to 32-bits on a 32-bit
architecture, even if it supports 64-bit DMA addresses.  There's a couple
of other places where this same truncation occurs:

        address = (long long)(long)devinfo->shared.scratch_dmahandle;

and

        address = (long long)(long)devinfo->shared.ringupd_dmahandle;

In any case, wouldn't using a u64 type for "address" be better - isn't
"long long" 128-bit on 64-bit architectures?

-- 
FTTC broadband for 0.8mile line: currently at 9.5Mbps down 400kbps up
according to speedtest.net.

  reply	other threads:[~2014-12-05 11:11 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
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 [this message]
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=20141205111114.GQ11285@n2100.arm.linux.org.uk \
    --to=linux@arm.linux.org.uk \
    --cc=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 \
    /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).