[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20150618094803.GH7557@n2100.arm.linux.org.uk>
Date: Thu, 18 Jun 2015 10:48:03 +0100
From: Russell King - ARM Linux <linux@....linux.org.uk>
To: Boris Brezillon <boris.brezillon@...e-electrons.com>
Cc: Herbert Xu <herbert@...dor.apana.org.au>,
Lior Amsalem <alior@...vell.com>, Andrew Lunn <andrew@...n.ch>,
Nadav Haklai <nadavh@...vell.com>,
Mark Rutland <mark.rutland@....com>,
Tawfik Bayouk <tawfik@...vell.com>,
Eran Ben-Avi <benavi@...vell.com>,
Jason Gunthorpe <jgunthorpe@...idianresearch.com>,
Sebastian Hesselbarth <sebastian.hesselbarth@...il.com>,
devicetree@...r.kernel.org, Jason Cooper <jason@...edaemon.net>,
Pawel Moll <pawel.moll@....com>,
Ian Campbell <ijc+devicetree@...lion.org.uk>,
Arnaud Ebalard <arno@...isbad.org>,
Rob Herring <robh+dt@...nel.org>,
Gregory CLEMENT <gregory.clement@...e-electrons.com>,
linux-arm-kernel@...ts.infradead.org,
Thomas Petazzoni <thomas.petazzoni@...e-electrons.com>,
linux-kernel@...r.kernel.org, linux-crypto@...r.kernel.org,
Kumar Gala <galak@...eaurora.org>,
Imre Kaloz <kaloz@...nwrt.org>,
"David S. Miller" <davem@...emloft.net>
Subject: Re: [PATCH v6 05/14] crypto: marvell/CESA: add TDMA support
On Thu, Jun 18, 2015 at 11:33:24AM +0200, Boris Brezillon wrote:
> Hi Russel,
>
> On Thu, 18 Jun 2015 10:04:00 +0100
> Russell King - ARM Linux <linux@....linux.org.uk> wrote:
>
> > On Wed, Jun 17, 2015 at 05:50:01PM +0800, Herbert Xu wrote:
> > > On Wed, Jun 17, 2015 at 09:45:33AM +0200, Boris Brezillon wrote:
> > > >
> > > > + ret = dma_map_sg(cesa_dev->dev, req->src, creq->src_nents,
> > > > + DMA_TO_DEVICE);
> > > > + if (!ret)
> > > > + return -ENOMEM;
> > > > +
> > > > + creq->src_nents = ret;
> > >
> > > DMA-API-HOWTO says that you must retain the original nents and
> > > use it when you call dma_unmap_sg. So I'm afraid one more repost
> > > is needed :)
> >
> > It's worse than that... You're right on that point, but there's an
> > additional point.
> >
> > If dma_map_sg() coalesces scatterlist entries, then ret will be smaller
> > than src_nents, and ret indicates how many scatterlist entries to be
> > walked during DMA - you should not use src_nents for that. I couldn't
> > see where the driver used that information. In fact, the driver seems
> > to be capable of walking more than src_nents/ret numbers of scatterlist
> > entries: it just keeps going with sg_next() until it hits the end of
> > the allocated scatterlist.
>
> Yes, I realized that, and I never used the value returned by
> dma_map_sg() to walk the scatterlist anyway: I was using the sg_next()
> and sg->length value (which I replaced by sg_dma_len() in v7 as
> suggested by Herbert).
> So the ->src_nents assignment to dma_map_sg() return value was just a
> silly mistake caused by an uncareful read of the DMA-API-HOWTO.
>
> Am I missing something else ?
Yes. 'ret' should be used to indicate the number of scatterlist entries
to walk for DMA purposes after the scatterlist has been mapped. For PIO
purposes, using src_nents is still acceptable.
As Herbert points out, you're stopping after the sum of transferred bytes
matches, so I suppose that's fine.
One other point though: you should use sg_dma_address() rather than
dereferencing sg->dma_address directly.
--
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists