[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <59ce3620-00b9-bac1-30e1-011a29583642@arm.com>
Date: Mon, 8 Jun 2020 17:44:21 +0100
From: Robin Murphy <robin.murphy@....com>
To: Mark Brown <broonie@...nel.org>, Robin Gong <yibin.gong@....com>
Cc: "mark.rutland@....com" <mark.rutland@....com>,
"devicetree@...r.kernel.org" <devicetree@...r.kernel.org>,
"matthias.schiffer@...tq-group.com"
<matthias.schiffer@...tq-group.com>,
"martin.fuzzey@...wbird.group" <martin.fuzzey@...wbird.group>,
"catalin.marinas@....com" <catalin.marinas@....com>,
"s.hauer@...gutronix.de" <s.hauer@...gutronix.de>,
"will.deacon@....com" <will.deacon@....com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-spi@...r.kernel.org" <linux-spi@...r.kernel.org>,
"vkoul@...nel.org" <vkoul@...nel.org>,
"robh+dt@...nel.org" <robh+dt@...nel.org>,
dl-linux-imx <linux-imx@....com>,
"festevam@...il.com" <festevam@...il.com>,
"u.kleine-koenig@...gutronix.de" <u.kleine-koenig@...gutronix.de>,
"dmaengine@...r.kernel.org" <dmaengine@...r.kernel.org>,
"dan.j.williams@...el.com" <dan.j.williams@...el.com>,
"shawnguo@...nel.org" <shawnguo@...nel.org>,
"kernel@...gutronix.de" <kernel@...gutronix.de>,
"linux-arm-kernel@...ts.infradead.org"
<linux-arm-kernel@...ts.infradead.org>
Subject: Re: [PATCH v9 RESEND 01/13] spi: imx: add dma_sync_sg_for_device
after fallback from dma
On 2020-06-08 16:31, Mark Brown wrote:
> On Mon, Jun 08, 2020 at 03:08:45PM +0000, Robin Gong wrote:
>
>>>> + if (transfer->rx_sg.sgl) {
>>>> + struct device *rx_dev = spi->controller->dma_rx->device->dev;
>>>> +
>>>> + dma_sync_sg_for_device(rx_dev, transfer->rx_sg.sgl,
>>>> + transfer->rx_sg.nents, DMA_TO_DEVICE);
>>>> + }
>>>> +
>
>>> This is confusing - why are we DMA mapping to the device after doing a PIO
>>> transfer?
>
>> 'transfer->rx_sg.sgl' condition check that's the case fallback PIO after DMA transfer
>> failed. But the spi core still think the buffer should be in 'device' while spi driver
>> touch it by PIO(CPU), so sync it back to device to ensure all received data flush to DDR.
>
> So we sync it back to the device so that we can then do another sync to
> CPU? TBH I'm a bit surprised that there's a requirement that we
> explicitly undo a sync and that a redundant double sync in the same
> direction might be an issue but I've not had a need to care so I'm
> perfectly prepared to believe there is.
>
> At the very least this needs a comment.
Yeah, something's off here - at the very least, syncing with
DMA_TO_DEVICE on the Rx buffer that was mapped with DMA_FROM_DEVICE is
clearly wrong. CONFIG_DMA_API_DEBUG should scream about that.
If the device has written to the buffer at all since dma_map_sg() was
called then you do need a dma_sync_sg_for_cpu() call before touching it
from a CPU fallback path, but if nobody's going to touch it from that
point until it's unmapped then there's no point syncing it again. The
my_card_interrupt_handler() example in DMA-API_HOWTO.txt demonstrates this.
Robin.
Powered by blists - more mailing lists