DMA Engine development
 help / color / mirror / Atom feed
* Re: [RFC v6 1/6] dmaengine: Add Synopsys eDMA IP core driver
From: Vinod Koul @ 2019-05-07  5:03 UTC (permalink / raw)
  To: Gustavo Pimentel
  Cc: linux-pci@vger.kernel.org, dmaengine@vger.kernel.org,
	Dan Williams, Andy Shevchenko, Russell King, Joao Pinto
In-Reply-To: <305100E33629484CBB767107E4246BBB0A238675@de02wembxa.internal.synopsys.com>

On 06-05-19, 16:42, Gustavo Pimentel wrote:

> > > +	if (unlikely(!chunk))
> > > +		return NULL;
> > > +
> > > +	INIT_LIST_HEAD(&chunk->list);
> > > +	chunk->chan = chan;
> > > +	chunk->cb = !(desc->chunks_alloc % 2);
> > ? why %2?
> 
> I think it's explained on the patch description. CB also is known as 
> Change Bit that must be toggled in order to the HW assume a new linked 
> list is available to be consumed.
> Since desc->chunks_alloc variable is an incremental counter the remainder 
> after division by 2 will be zero (if chunks_alloc is even) or one (if 
> chunks_alloc is odd).

Okay it would be great to add a comment here to explain as well

> > > +static enum dma_status
> > > +dw_edma_device_tx_status(struct dma_chan *dchan, dma_cookie_t cookie,
> > > +			 struct dma_tx_state *txstate)
> > > +{
> > > +	struct dw_edma_chan *chan = dchan2dw_edma_chan(dchan);
> > > +	struct dw_edma_desc *desc;
> > > +	struct virt_dma_desc *vd;
> > > +	unsigned long flags;
> > > +	enum dma_status ret;
> > > +	u32 residue = 0;
> > > +
> > > +	ret = dma_cookie_status(dchan, cookie, txstate);
> > > +	if (ret == DMA_COMPLETE)
> > > +		return ret;
> > > +
> > > +	if (ret == DMA_IN_PROGRESS && chan->status == EDMA_ST_PAUSE)
> > > +		ret = DMA_PAUSED;
> > 
> > Don't you want to set residue on paused channel, how else will user know
> > the position of pause?
> 
> I didn't catch you on this. I'm only setting the dma status here. After 
> this function, the residue is calculated and set, isn't it?

Hmm I thought you returned for paused case, if not then it is okay

> > > +static struct dma_async_tx_descriptor *
> > > +dw_edma_device_transfer(struct dw_edma_transfer *xfer)
> > > +{
> > > +	struct dw_edma_chan *chan = dchan2dw_edma_chan(xfer->dchan);
> > > +	enum dma_transfer_direction direction = xfer->direction;
> > > +	phys_addr_t src_addr, dst_addr;
> > > +	struct scatterlist *sg = NULL;
> > > +	struct dw_edma_chunk *chunk;
> > > +	struct dw_edma_burst *burst;
> > > +	struct dw_edma_desc *desc;
> > > +	u32 cnt;
> > > +	int i;
> > > +
> > > +	if ((direction == DMA_MEM_TO_DEV && chan->dir == EDMA_DIR_WRITE) ||
> > > +	    (direction == DMA_DEV_TO_MEM && chan->dir == EDMA_DIR_READ))
> > > +		return NULL;
> > > +
> > > +	if (xfer->cyclic) {
> > > +		if (!xfer->xfer.cyclic.len || !xfer->xfer.cyclic.cnt)
> > > +			return NULL;
> > > +	} else {
> > > +		if (xfer->xfer.sg.len < 1)
> > > +			return NULL;
> > > +	}
> > > +
> > > +	if (!chan->configured)
> > > +		return NULL;
> > > +
> > > +	desc = dw_edma_alloc_desc(chan);
> > > +	if (unlikely(!desc))
> > > +		goto err_alloc;
> > > +
> > > +	chunk = dw_edma_alloc_chunk(desc);
> > > +	if (unlikely(!chunk))
> > > +		goto err_alloc;
> > > +
> > > +	src_addr = chan->config.src_addr;
> > > +	dst_addr = chan->config.dst_addr;
> > > +
> > > +	if (xfer->cyclic) {
> > > +		cnt = xfer->xfer.cyclic.cnt;
> > > +	} else {
> > > +		cnt = xfer->xfer.sg.len;
> > > +		sg = xfer->xfer.sg.sgl;
> > > +	}
> > > +
> > > +	for (i = 0; i < cnt; i++) {
> > > +		if (!xfer->cyclic && !sg)
> > > +			break;
> > > +
> > > +		if (chunk->bursts_alloc == chan->ll_max) {
> > > +			chunk = dw_edma_alloc_chunk(desc);
> > > +			if (unlikely(!chunk))
> > > +				goto err_alloc;
> > > +		}
> > > +
> > > +		burst = dw_edma_alloc_burst(chunk);
> > > +		if (unlikely(!burst))
> > > +			goto err_alloc;
> > > +
> > > +		if (xfer->cyclic)
> > > +			burst->sz = xfer->xfer.cyclic.len;
> > > +		else
> > > +			burst->sz = sg_dma_len(sg);
> > > +
> > > +		chunk->ll_region.sz += burst->sz;
> > > +		desc->alloc_sz += burst->sz;
> > > +
> > > +		if (direction == DMA_DEV_TO_MEM) {
> > > +			burst->sar = src_addr;
> > 
> > We are device to mem, so src is peripheral.. okay
> > 
> > > +			if (xfer->cyclic) {
> > > +				burst->dar = xfer->xfer.cyclic.paddr;
> > > +			} else {
> > > +				burst->dar = sg_dma_address(sg);
> > > +				src_addr += sg_dma_len(sg);
> > 
> > and we increment the src, doesn't make sense to me!
> > 
> > > +			}
> > > +		} else {
> > > +			burst->dar = dst_addr;
> > > +			if (xfer->cyclic) {
> > > +				burst->sar = xfer->xfer.cyclic.paddr;
> > > +			} else {
> > > +				burst->sar = sg_dma_address(sg);
> > > +				dst_addr += sg_dma_len(sg);
> > 
> > same here as well
> 
> This is hard to explain in words...
> Well, in my perspective I want to transfer a piece of memory from the 
> peripheral into local RAM

Right and most of the case RAM address (sg) needs to increment whereas
peripheral is a constant one

> Through the DMA client API I'll break this piece of memory in several 
> small parts and add all into a list (scatter-gather), right?
> Each element of the scatter-gather has the sg_dma_address (in the 
> DMA_DEV_TO_MEM case will be the destination address) and the 
> corresponding size.

Correct

> However, I still need the other address (in the DMA_DEV_TO_MEM case will 
> be the source address) for that small part of memory.
> Since I get that address from the config, I still need to increment the 
> source address in the same proportion of the destination address, in 
> other words, the increment will be the part size.

I don't think so. Typically the device address is a FIFO, which does not
increment and you keep pushing data at same address. It is not a memory

> If there is some way to set and get the address for the source (in this 
> case) into each scatter-gather element, that would be much nicer, is that 
> possible?

> > > +		case EDMA_REQ_STOP:
> > > +			list_del(&vd->node);
> > > +			vchan_cookie_complete(vd);
> > > +			chan->request = EDMA_REQ_NONE;
> > > +			chan->status = EDMA_ST_IDLE;
> > 
> > Why do we need to track request as well as status?
> 
> Since I don't actually have the PAUSE state feature available on HW, I'm 
> emulating it through software. As far as HW is concerned, it thinks that 
> it has transferred everything (no more bursts valid available), but in 
> terms of software, we still have a lot of chunks (each one containing 
> several bursts) to process.

Why do you need to emulate, if HW doesnt support so be it?
The applications should handle a device which doesnt support pause and
not a low level driver

> > > +struct dw_edma_transfer {
> > > +	struct dma_chan			*dchan;
> > > +	union Xfer {
> > 
> > no camel case please
> 
> Ok.
> 
> > 
> > It would help to run checkpatch with --strict option to find any style
> > issues and fix them as well
> 
> I usually run with that option, but for now, that option is giving some 
> warnings about macro variable names that are pure noise.

yeah that is a *guide* and to be used as guidance. If code looks worse
off then it shouldn't be used. But many of the test are helpful. Some
macros checks actually make sense, but again use your judgement :)

-- 
~Vinod

^ permalink raw reply

* Re: [RFC v6 3/6] dmaengine: Add Synopsys eDMA IP version 0 debugfs support
From: Vinod Koul @ 2019-05-07  5:11 UTC (permalink / raw)
  To: Gustavo Pimentel
  Cc: linux-pci@vger.kernel.org, dmaengine@vger.kernel.org,
	Dan Williams, Andy Shevchenko, Russell King, Joao Pinto
In-Reply-To: <305100E33629484CBB767107E4246BBB0A2386A1@de02wembxa.internal.synopsys.com>

On 06-05-19, 17:09, Gustavo Pimentel wrote:
> Hi Vinod,
> 
> On Mon, May 6, 2019 at 13:7:10, Vinod Koul <vkoul@kernel.org> wrote:
> 
> > On 23-04-19, 20:30, Gustavo Pimentel wrote:
> > 
> > >  int dw_edma_v0_core_debugfs_on(struct dw_edma_chip *chip)
> > >  {
> > > -	return 0;
> > > +	return dw_edma_v0_debugfs_on(chip);
> > 
> > who calls this?
> 
> The main driver. This was done like this for 2 reasons:
> 1) To not break the patch #1 compilation
> 2) Since the code it's to extensive, I decided to break it in another 
> patch.

Hmm I guess I missed that one. I was actually looking at usage and not
questioning split :)

> > > +static int dw_edma_debugfs_u32_get(void *data, u64 *val)
> > > +{
> > > +	if (dw->mode == EDMA_MODE_LEGACY &&
> > > +	    data >= (void *)&regs->type.legacy.ch) {
> > > +		void *ptr = (void *)&regs->type.legacy.ch;
> > > +		u32 viewport_sel = 0;
> > > +		unsigned long flags;
> > > +		u16 ch;
> > > +
> > > +		for (ch = 0; ch < dw->wr_ch_cnt; ch++)
> > > +			if (lim[0][ch].start >= data && data < lim[0][ch].end) {
> > > +				ptr += (data - lim[0][ch].start);
> > > +				goto legacy_sel_wr;
> > > +			}
> > > +
> > > +		for (ch = 0; ch < dw->rd_ch_cnt; ch++)
> > > +			if (lim[1][ch].start >= data && data < lim[1][ch].end) {
> > > +				ptr += (data - lim[1][ch].start);
> > > +				goto legacy_sel_rd;
> > > +			}
> > > +
> > > +		return 0;
> > > +legacy_sel_rd:
> > > +		viewport_sel = BIT(31);
> > > +legacy_sel_wr:
> > > +		viewport_sel |= FIELD_PREP(EDMA_V0_VIEWPORT_MASK, ch);
> > > +
> > > +		raw_spin_lock_irqsave(&dw->lock, flags);
> > > +
> > > +		writel(viewport_sel, &regs->type.legacy.viewport_sel);
> > > +		*val = readl((u32 *)ptr);
> > 
> > why do you need the cast?
> 
> I can't tell from my head, but I think checkpatch or some code analysis 
> tool was complaining about not having that.

ptr is void, so there is no need for casts to or away from void.

> > > +static int dw_edma_debugfs_regs(void)
> > > +{
> > > +	const struct debugfs_entries debugfs_regs[] = {
> > > +		REGISTER(ctrl_data_arb_prior),
> > > +		REGISTER(ctrl),
> > > +	};
> > > +	struct dentry *regs_dir;
> > > +	int nr_entries, err;
> > > +
> > > +	regs_dir = debugfs_create_dir(REGISTERS_STR, base_dir);
> > > +	if (!regs_dir)
> > > +		return -EPERM;
> > > +
> > > +	nr_entries = ARRAY_SIZE(debugfs_regs);
> > > +	err = dw_edma_debugfs_create_x32(debugfs_regs, nr_entries, regs_dir);
> > > +	if (err)
> > > +		return err;
> > > +
> > > +	err = dw_edma_debugfs_regs_wr(regs_dir);
> > > +	if (err)
> > > +		return err;
> > > +
> > > +	err = dw_edma_debugfs_regs_rd(regs_dir);
> > > +	if (err)
> > > +		return err;
> > > +
> > > +	return 0;
> > 
> > single return err would suffice right?
> 
> By looking now to this code, I decided to remove the err variable and 
> perform the if immediately on the function, if the result is different 
> from 0 it goes directly to a return -EPERM. 

And one more things, we do not need to check errors on debugfs calls,
and if it fails it fails...

-- 
~Vinod

^ permalink raw reply

* Re: [PATCH 2/2] dmaengine: milbeaut: Add Milbeaut AXI DMA controller
From: Kazuhiro Kasai @ 2019-05-07  5:39 UTC (permalink / raw)
  To: Vinod Koul
  Cc: robh+dt, mark.rutland, dmaengine, devicetree, orito.takao,
	sugaya.taichi, kanematsu.shinji, jaswinder.singh,
	masami.hiramatsu, linux-kernel, kasai.kazuhiro
In-Reply-To: <20190426114629.GU28103@vkoul-mobl>


Thank you very much for reviewing my patch.
Sorry for my late reply. Japan was in Spring Vacation.

On Fri, Apr 26, 2019 at 17:16 +0530, Vinod Koul wrote:
> On 25-03-19, 13:15, Kazuhiro Kasai wrote:
> > Add Milbeaut AXI DMA controller. This DMA controller has
> > only capable of memory to memory transfer.
>
> Have you tested this with dmatest?
Yes, I have tested this with dmatest.

I use dmatest with the following parameter.
>echo 10 > iterations
>echo "" > channel
>echo 1 > run

And I got the below report from dmatest.
[11675.231268] dmatest: dma0chan0-copy0: summary 10 tests, 0 failures 6910.84 iops 67035 KB/s (0)
[ 5646.689234] dmatest: dma0chan1-copy0: summary 10 tests, 0 failures 7949.12 iops 59618 KB/s (0)
[12487.712996] dmatest: dma0chan2-copy0: summary 10 tests, 0 failures 1493.87 iops 15088 KB/s (0)
[12487.733932] dmatest: dma1chan0-copy0: summary 10 tests, 0 failures 490.98 iops 3142 KB/s (0)
[11675.282428] dmatest: dma1chan2-copy0: summary 10 tests, 0 failures 7112.37 iops 56187 KB/s (0)
[ 5646.754230] dmatest: dma1chan3-copy0: summary 10 tests, 0 failures 6609.38 iops 61467 KB/s (0)
[ 5043.009255] dmatest: dma0chan3-copy0: summary 10 tests, 0 failures 498.08 iops 4183 KB/s (0)
[ 5043.018385] dmatest: dma1chan1-copy0: summary 10 tests, 0 failures 350.62 iops 3155 KB/s (0)

>
> > +struct m10v_dma_chan {
> > +	struct dma_chan chan;
> > +	struct m10v_dma_device *mdmac;
> > +	void __iomem *regs;
> > +	int irq;
> > +	struct m10v_dma_desc mdesc;
>
> So there is a *single* descriptor? Not a list??

Yes, single descriptor.

>
> > +static void m10v_xdmac_disable_dma(struct m10v_dma_device *mdmac)
> > +{
> > +	unsigned int val;
> > +
> > +	val = readl(mdmac->regs + M10V_XDACS);
> > +	val &= ~M10V_XDACS_XE;
> > +	val |= FIELD_PREP(M10V_XDACS_XE, 0);
> > +	writel(val, mdmac->regs + M10V_XDACS);
>
> Why not create a modifyl() macro and use it here

Thank you for advise, I will creat modifyl() macro and use it in next version.

>
> > +static void m10v_xdmac_issue_pending(struct dma_chan *chan)
> > +{
> > +	struct m10v_dma_chan *mchan = to_m10v_dma_chan(chan);
> > +
> > +	m10v_xdmac_config_chan(mchan);
> > +
> > +	m10v_xdmac_enable_chan(mchan);
>
> You dont check if anything is already running or not?

Yes, I think I don't need check if dma is running or not.
Because there's a single descriptor.

>
> > +static dma_cookie_t m10v_xdmac_tx_submit(struct dma_async_tx_descriptor *txd)
> > +{
> > +	struct m10v_dma_chan *mchan = to_m10v_dma_chan(txd->chan);
> > +	dma_cookie_t cookie;
> > +	unsigned long flags;
> > +
> > +	spin_lock_irqsave(&mchan->lock, flags);
> > +	cookie = dma_cookie_assign(txd);
> > +	spin_unlock_irqrestore(&mchan->lock, flags);
> > +
> > +	return cookie;
>
> sounds like vchan_tx_submit() i think you can use virt-dma layer and then
> get rid of artificial limit in driver and be able to queue up the txn on
> dmaengine.

OK, I will try to use virt-dma layer in next version.

>
> > +static struct dma_async_tx_descriptor *
> > +m10v_xdmac_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dst,
> > +			   dma_addr_t src, size_t len, unsigned long flags)
> > +{
> > +	struct m10v_dma_chan *mchan = to_m10v_dma_chan(chan);
> > +
> > +	dma_async_tx_descriptor_init(&mchan->mdesc.txd, chan);
> > +	mchan->mdesc.txd.tx_submit = m10v_xdmac_tx_submit;
> > +	mchan->mdesc.txd.callback = NULL;
> > +	mchan->mdesc.txd.flags = flags;
> > +	mchan->mdesc.txd.cookie = -EBUSY;
> > +
> > +	mchan->mdesc.len = len;
> > +	mchan->mdesc.src = src;
> > +	mchan->mdesc.dst = dst;
> > +
> > +	return &mchan->mdesc.txd;
>
> So you support single descriptor and dont check if this has been already
> configured. So I guess this has been tested by doing txn one at a time
> and not submitted bunch of txn and wait for them to complete. Please fix
> that to really enable dmaengine capabilities.

Thank you for advice. I want to fix it and I have 2 questions.

1. Does virt-dma layer help to fix this?
2. Can dmatest test that dmaengine capabilities?

>
> > +static int m10v_xdmac_remove(struct platform_device *pdev)
> > +{
> > +	struct m10v_dma_chan *mchan;
> > +	struct m10v_dma_device *mdmac = platform_get_drvdata(pdev);
> > +	int i;
> > +
> > +	m10v_xdmac_disable_dma(mdmac);
> > +
> > +	for (i = 0; i < mdmac->channels; i++) {
> > +		mchan = &mdmac->mchan[i];
> > +		devm_free_irq(&pdev->dev, mchan->irq, mchan);
> > +	}
>
> No call to dma_async_device_unregister()?

Thank you, I will call dma_async_device_unregister in next version.

Thanks,
Kasai


^ permalink raw reply

* [PATCH AUTOSEL 5.0 76/99] dmaengine: bcm2835: Avoid GFP_KERNEL in device_prep_slave_sg
From: Sasha Levin @ 2019-05-07  5:32 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Stefan Wahren, Aaro Koskinen, Vinod Koul, Sasha Levin, dmaengine
In-Reply-To: <20190507053235.29900-1-sashal@kernel.org>

From: Stefan Wahren <stefan.wahren@i2se.com>

[ Upstream commit f147384774a7b24dda4783a3dcd61af272757ea8 ]

The commit af19b7ce76ba ("mmc: bcm2835: Avoid possible races on
data requests") introduces a possible circular locking dependency,
which is triggered by swapping to the sdhost interface.

So instead of reintroduce the race condition again, we could also
avoid this situation by using GFP_NOWAIT for the allocation of the
DMA buffer descriptors.

Reported-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
Fixes: af19b7ce76ba ("mmc: bcm2835: Avoid possible races on data requests")
Link: http://lists.infradead.org/pipermail/linux-rpi-kernel/2019-March/008615.html
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/dma/bcm2835-dma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/bcm2835-dma.c b/drivers/dma/bcm2835-dma.c
index ae10f5614f95..bf5119203637 100644
--- a/drivers/dma/bcm2835-dma.c
+++ b/drivers/dma/bcm2835-dma.c
@@ -674,7 +674,7 @@ static struct dma_async_tx_descriptor *bcm2835_dma_prep_slave_sg(
 	d = bcm2835_dma_create_cb_chain(chan, direction, false,
 					info, extra,
 					frames, src, dst, 0, 0,
-					GFP_KERNEL);
+					GFP_NOWAIT);
 	if (!d)
 		return NULL;
 
-- 
2.20.1


^ permalink raw reply related

* [PATCH 0/8] Add matching device node validation in DMA engine core
From: Baolin Wang @ 2019-05-07  6:09 UTC (permalink / raw)
  To: dan.j.williams, vkoul
  Cc: thierry.reding, jonathanh, linux-tegra, shawnguo, s.hauer, kernel,
	festevam, linux-imx, Zubair.Kakakhel, wsa+renesas, jroedel,
	vincent.guittot, baolin.wang, dmaengine, linux-kernel,
	linux-arm-kernel

Hi,

This patch set adds a device node validation in DMA engine core, that will
help some drivers to remove the duplicate device node validation in each
driver.

Any comments are welcome. Thanks.

Baolin Wang (8):
  dmaengine: Add matching device node validation in
    __dma_request_channel()
  soc: tegra: fuse: Change to the correct __dma_request_channel()
    prototype
  dmaengine: imx-sdma: Let the core do the device node validation
  dmaengine: dma-jz4780: Let the core do the device node validation
  dmaengine: mmp_tdma: Let the core do the device node validation
  dmaengine: mxs-dma: Let the core do the device node validation
  dmaengine: sh: rcar-dmac: Let the core do the device node validation
  dmaengine: sh: usb-dmac: Let the core do the device node validation

 drivers/dma/dma-jz4780.c              |    7 ++-----
 drivers/dma/dmaengine.c               |   10 ++++++++--
 drivers/dma/imx-sdma.c                |    9 ++-------
 drivers/dma/mmp_tdma.c                |   10 ++--------
 drivers/dma/mxs-dma.c                 |    8 ++------
 drivers/dma/of-dma.c                  |    4 ++--
 drivers/dma/sh/rcar-dmac.c            |    6 +++---
 drivers/dma/sh/usb-dmac.c             |    6 ++----
 drivers/soc/tegra/fuse/fuse-tegra20.c |    2 +-
 include/linux/dmaengine.h             |   12 ++++++++----
 include/linux/platform_data/dma-imx.h |    1 -
 11 files changed, 32 insertions(+), 43 deletions(-)

-- 
1.7.9.5


^ permalink raw reply

* [PATCH 1/8] dmaengine: Add matching device node validation in __dma_request_channel()
From: Baolin Wang @ 2019-05-07  6:09 UTC (permalink / raw)
  To: dan.j.williams, vkoul
  Cc: thierry.reding, jonathanh, linux-tegra, shawnguo, s.hauer, kernel,
	festevam, linux-imx, Zubair.Kakakhel, wsa+renesas, jroedel,
	vincent.guittot, baolin.wang, dmaengine, linux-kernel,
	linux-arm-kernel
In-Reply-To: <cover.1557206859.git.baolin.wang@linaro.org>

When user try to request one DMA channel by __dma_request_channel(), it won't
validate if it is the correct DMA device to request, that will lead each DMA
engine driver to validate the correct device node in their filter function
if it is necessary.

Thus we can add the matching device node validation in the DMA engine core,
to remove all of device node validation in the drivers.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 drivers/dma/dmaengine.c   |   10 ++++++++--
 drivers/dma/of-dma.c      |    4 ++--
 include/linux/dmaengine.h |   12 ++++++++----
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 3a11b10..610080c 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -641,11 +641,13 @@ struct dma_chan *dma_get_any_slave_channel(struct dma_device *device)
  * @mask: capabilities that the channel must satisfy
  * @fn: optional callback to disposition available channels
  * @fn_param: opaque parameter to pass to dma_filter_fn
+ * @np: device node to look for DMA channels
  *
  * Returns pointer to appropriate DMA channel on success or NULL.
  */
 struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
-				       dma_filter_fn fn, void *fn_param)
+				       dma_filter_fn fn, void *fn_param,
+				       struct device_node *np)
 {
 	struct dma_device *device, *_d;
 	struct dma_chan *chan = NULL;
@@ -653,6 +655,10 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
 	/* Find a channel */
 	mutex_lock(&dma_list_mutex);
 	list_for_each_entry_safe(device, _d, &dma_device_list, global_node) {
+		/* Finds a DMA controller with matching device node */
+		if (np && device->dev->of_node && np != device->dev->of_node)
+			continue;
+
 		chan = find_candidate(device, mask, fn, fn_param);
 		if (!IS_ERR(chan))
 			break;
@@ -769,7 +775,7 @@ struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask)
 	if (!mask)
 		return ERR_PTR(-ENODEV);
 
-	chan = __dma_request_channel(mask, NULL, NULL);
+	chan = __dma_request_channel(mask, NULL, NULL, NULL);
 	if (!chan) {
 		mutex_lock(&dma_list_mutex);
 		if (list_empty(&dma_device_list))
diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c
index 91fd395..6b43d04 100644
--- a/drivers/dma/of-dma.c
+++ b/drivers/dma/of-dma.c
@@ -316,8 +316,8 @@ struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec,
 	if (count != 1)
 		return NULL;
 
-	return dma_request_channel(info->dma_cap, info->filter_fn,
-			&dma_spec->args[0]);
+	return __dma_request_channel(&info->dma_cap, info->filter_fn,
+				     &dma_spec->args[0], dma_spec->np);
 }
 EXPORT_SYMBOL_GPL(of_dma_simple_xlate);
 
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index d49ec5c..504085b 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -1314,7 +1314,8 @@ static inline enum dma_status dma_async_is_complete(dma_cookie_t cookie,
 enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx);
 void dma_issue_pending_all(void);
 struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
-					dma_filter_fn fn, void *fn_param);
+				       dma_filter_fn fn, void *fn_param,
+				       struct device_node *np);
 struct dma_chan *dma_request_slave_channel(struct device *dev, const char *name);
 
 struct dma_chan *dma_request_chan(struct device *dev, const char *name);
@@ -1339,7 +1340,9 @@ static inline void dma_issue_pending_all(void)
 {
 }
 static inline struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
-					      dma_filter_fn fn, void *fn_param)
+						     dma_filter_fn fn,
+						     void *fn_param,
+						     struct device_node *np)
 {
 	return NULL;
 }
@@ -1411,7 +1414,8 @@ static inline int dmaengine_desc_free(struct dma_async_tx_descriptor *desc)
 void dma_run_dependencies(struct dma_async_tx_descriptor *tx);
 struct dma_chan *dma_get_slave_channel(struct dma_chan *chan);
 struct dma_chan *dma_get_any_slave_channel(struct dma_device *device);
-#define dma_request_channel(mask, x, y) __dma_request_channel(&(mask), x, y)
+#define dma_request_channel(mask, x, y) \
+	__dma_request_channel(&(mask), x, y, NULL)
 #define dma_request_slave_channel_compat(mask, x, y, dev, name) \
 	__dma_request_slave_channel_compat(&(mask), x, y, dev, name)
 
@@ -1429,6 +1433,6 @@ static inline int dmaengine_desc_free(struct dma_async_tx_descriptor *desc)
 	if (!fn || !fn_param)
 		return NULL;
 
-	return __dma_request_channel(mask, fn, fn_param);
+	return __dma_request_channel(mask, fn, fn_param, NULL);
 }
 #endif /* DMAENGINE_H */
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 2/8] soc: tegra: fuse: Change to the correct __dma_request_channel() prototype
From: Baolin Wang @ 2019-05-07  6:09 UTC (permalink / raw)
  To: dan.j.williams, vkoul
  Cc: thierry.reding, jonathanh, linux-tegra, shawnguo, s.hauer, kernel,
	festevam, linux-imx, Zubair.Kakakhel, wsa+renesas, jroedel,
	vincent.guittot, baolin.wang, dmaengine, linux-kernel,
	linux-arm-kernel
In-Reply-To: <cover.1557206859.git.baolin.wang@linaro.org>

Since we've introduced one device node parameter for __dma_request_channel(),
thus change to the correct function prototype.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 drivers/soc/tegra/fuse/fuse-tegra20.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/soc/tegra/fuse/fuse-tegra20.c b/drivers/soc/tegra/fuse/fuse-tegra20.c
index 49ff017..e2571b6 100644
--- a/drivers/soc/tegra/fuse/fuse-tegra20.c
+++ b/drivers/soc/tegra/fuse/fuse-tegra20.c
@@ -110,7 +110,7 @@ static int tegra20_fuse_probe(struct tegra_fuse *fuse)
 	dma_cap_zero(mask);
 	dma_cap_set(DMA_SLAVE, mask);
 
-	fuse->apbdma.chan = __dma_request_channel(&mask, dma_filter, NULL);
+	fuse->apbdma.chan = __dma_request_channel(&mask, dma_filter, NULL, NULL);
 	if (!fuse->apbdma.chan)
 		return -EPROBE_DEFER;
 
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 3/8] dmaengine: imx-sdma: Let the core do the device node validation
From: Baolin Wang @ 2019-05-07  6:09 UTC (permalink / raw)
  To: dan.j.williams, vkoul
  Cc: thierry.reding, jonathanh, linux-tegra, shawnguo, s.hauer, kernel,
	festevam, linux-imx, Zubair.Kakakhel, wsa+renesas, jroedel,
	vincent.guittot, baolin.wang, dmaengine, linux-kernel,
	linux-arm-kernel
In-Reply-To: <cover.1557206859.git.baolin.wang@linaro.org>

Let the DMA engine core do the device node validation instead of drivers.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 drivers/dma/imx-sdma.c                |    9 ++-------
 include/linux/platform_data/dma-imx.h |    1 -
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 5f3c137..1a11118 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -1921,16 +1921,11 @@ static int sdma_init(struct sdma_engine *sdma)
 static bool sdma_filter_fn(struct dma_chan *chan, void *fn_param)
 {
 	struct sdma_channel *sdmac = to_sdma_chan(chan);
-	struct sdma_engine *sdma = sdmac->sdma;
 	struct imx_dma_data *data = fn_param;
 
 	if (!imx_dma_is_general_purpose(chan))
 		return false;
 
-	/* return false if it's not the right device */
-	if (sdma->dev->of_node != data->of_node)
-		return false;
-
 	sdmac->data = *data;
 	chan->private = &sdmac->data;
 
@@ -1958,9 +1953,9 @@ static struct dma_chan *sdma_xlate(struct of_phandle_args *dma_spec,
 	 * be set to sdmac->event_id1.
 	 */
 	data.dma_request2 = 0;
-	data.of_node = ofdma->of_node;
 
-	return dma_request_channel(mask, sdma_filter_fn, &data);
+	return __dma_request_channel(&mask, sdma_filter_fn, &data,
+				     ofdma->of_node);
 }
 
 static int sdma_probe(struct platform_device *pdev)
diff --git a/include/linux/platform_data/dma-imx.h b/include/linux/platform_data/dma-imx.h
index 9daea8d..7d964e7 100644
--- a/include/linux/platform_data/dma-imx.h
+++ b/include/linux/platform_data/dma-imx.h
@@ -55,7 +55,6 @@ struct imx_dma_data {
 	int dma_request2; /* secondary DMA request line */
 	enum sdma_peripheral_type peripheral_type;
 	int priority;
-	struct device_node *of_node;
 };
 
 static inline int imx_dma_is_ipu(struct dma_chan *chan)
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 4/8] dmaengine: dma-jz4780: Let the core do the device node validation
From: Baolin Wang @ 2019-05-07  6:09 UTC (permalink / raw)
  To: dan.j.williams, vkoul
  Cc: thierry.reding, jonathanh, linux-tegra, shawnguo, s.hauer, kernel,
	festevam, linux-imx, Zubair.Kakakhel, wsa+renesas, jroedel,
	vincent.guittot, baolin.wang, dmaengine, linux-kernel,
	linux-arm-kernel
In-Reply-To: <cover.1557206859.git.baolin.wang@linaro.org>

Let the DMA engine core do the device node validation instead of drivers.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 drivers/dma/dma-jz4780.c |    7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/dma/dma-jz4780.c b/drivers/dma/dma-jz4780.c
index 9ce0a38..7e1d381 100644
--- a/drivers/dma/dma-jz4780.c
+++ b/drivers/dma/dma-jz4780.c
@@ -160,7 +160,6 @@ struct jz4780_dma_dev {
 };
 
 struct jz4780_dma_filter_data {
-	struct device_node *of_node;
 	uint32_t transfer_type;
 	int channel;
 };
@@ -765,8 +764,6 @@ static bool jz4780_dma_filter_fn(struct dma_chan *chan, void *param)
 	struct jz4780_dma_dev *jzdma = jz4780_dma_chan_parent(jzchan);
 	struct jz4780_dma_filter_data *data = param;
 
-	if (jzdma->dma_device.dev->of_node != data->of_node)
-		return false;
 
 	if (data->channel > -1) {
 		if (data->channel != jzchan->id)
@@ -790,7 +787,6 @@ static struct dma_chan *jz4780_of_dma_xlate(struct of_phandle_args *dma_spec,
 	if (dma_spec->args_count != 2)
 		return NULL;
 
-	data.of_node = ofdma->of_node;
 	data.transfer_type = dma_spec->args[0];
 	data.channel = dma_spec->args[1];
 
@@ -815,7 +811,8 @@ static struct dma_chan *jz4780_of_dma_xlate(struct of_phandle_args *dma_spec,
 		return dma_get_slave_channel(
 			&jzdma->chan[data.channel].vchan.chan);
 	} else {
-		return dma_request_channel(mask, jz4780_dma_filter_fn, &data);
+		return __dma_request_channel(&mask, jz4780_dma_filter_fn, &data,
+					     ofdma->of_node);
 	}
 }
 
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 5/8] dmaengine: mmp_tdma: Let the core do the device node validation
From: Baolin Wang @ 2019-05-07  6:09 UTC (permalink / raw)
  To: dan.j.williams, vkoul
  Cc: thierry.reding, jonathanh, linux-tegra, shawnguo, s.hauer, kernel,
	festevam, linux-imx, Zubair.Kakakhel, wsa+renesas, jroedel,
	vincent.guittot, baolin.wang, dmaengine, linux-kernel,
	linux-arm-kernel
In-Reply-To: <cover.1557206859.git.baolin.wang@linaro.org>

Let the DMA engine core do the device node validation instead of drivers.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 drivers/dma/mmp_tdma.c |   10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/dma/mmp_tdma.c b/drivers/dma/mmp_tdma.c
index 0c56faa0..e76858b 100644
--- a/drivers/dma/mmp_tdma.c
+++ b/drivers/dma/mmp_tdma.c
@@ -586,18 +586,12 @@ static int mmp_tdma_chan_init(struct mmp_tdma_device *tdev,
 }
 
 struct mmp_tdma_filter_param {
-	struct device_node *of_node;
 	unsigned int chan_id;
 };
 
 static bool mmp_tdma_filter_fn(struct dma_chan *chan, void *fn_param)
 {
 	struct mmp_tdma_filter_param *param = fn_param;
-	struct mmp_tdma_chan *tdmac = to_mmp_tdma_chan(chan);
-	struct dma_device *pdma_device = tdmac->chan.device;
-
-	if (pdma_device->dev->of_node != param->of_node)
-		return false;
 
 	if (chan->chan_id != param->chan_id)
 		return false;
@@ -615,13 +609,13 @@ static struct dma_chan *mmp_tdma_xlate(struct of_phandle_args *dma_spec,
 	if (dma_spec->args_count != 1)
 		return NULL;
 
-	param.of_node = ofdma->of_node;
 	param.chan_id = dma_spec->args[0];
 
 	if (param.chan_id >= TDMA_CHANNEL_NUM)
 		return NULL;
 
-	return dma_request_channel(mask, mmp_tdma_filter_fn, &param);
+	return __dma_request_channel(&mask, mmp_tdma_filter_fn, &param,
+				     ofdma->of_node);
 }
 
 static const struct of_device_id mmp_tdma_dt_ids[] = {
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 6/8] dmaengine: mxs-dma: Let the core do the device node validation
From: Baolin Wang @ 2019-05-07  6:09 UTC (permalink / raw)
  To: dan.j.williams, vkoul
  Cc: thierry.reding, jonathanh, linux-tegra, shawnguo, s.hauer, kernel,
	festevam, linux-imx, Zubair.Kakakhel, wsa+renesas, jroedel,
	vincent.guittot, baolin.wang, dmaengine, linux-kernel,
	linux-arm-kernel
In-Reply-To: <cover.1557206859.git.baolin.wang@linaro.org>

Let the DMA engine core do the device node validation instead of drivers.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 drivers/dma/mxs-dma.c |    8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/dma/mxs-dma.c b/drivers/dma/mxs-dma.c
index 22cc7f6..8ce5e79 100644
--- a/drivers/dma/mxs-dma.c
+++ b/drivers/dma/mxs-dma.c
@@ -716,7 +716,6 @@ static int __init mxs_dma_init(struct mxs_dma_engine *mxs_dma)
 }
 
 struct mxs_dma_filter_param {
-	struct device_node *of_node;
 	unsigned int chan_id;
 };
 
@@ -727,9 +726,6 @@ static bool mxs_dma_filter_fn(struct dma_chan *chan, void *fn_param)
 	struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
 	int chan_irq;
 
-	if (mxs_dma->dma_device.dev->of_node != param->of_node)
-		return false;
-
 	if (chan->chan_id != param->chan_id)
 		return false;
 
@@ -752,13 +748,13 @@ static struct dma_chan *mxs_dma_xlate(struct of_phandle_args *dma_spec,
 	if (dma_spec->args_count != 1)
 		return NULL;
 
-	param.of_node = ofdma->of_node;
 	param.chan_id = dma_spec->args[0];
 
 	if (param.chan_id >= mxs_dma->nr_channels)
 		return NULL;
 
-	return dma_request_channel(mask, mxs_dma_filter_fn, &param);
+	return __dma_request_channel(&mask, mxs_dma_filter_fn, &param,
+				     ofdma->of_node);
 }
 
 static int __init mxs_dma_probe(struct platform_device *pdev)
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 7/8] dmaengine: sh: rcar-dmac: Let the core do the device node validation
From: Baolin Wang @ 2019-05-07  6:09 UTC (permalink / raw)
  To: dan.j.williams, vkoul
  Cc: thierry.reding, jonathanh, linux-tegra, shawnguo, s.hauer, kernel,
	festevam, linux-imx, Zubair.Kakakhel, wsa+renesas, jroedel,
	vincent.guittot, baolin.wang, dmaengine, linux-kernel,
	linux-arm-kernel
In-Reply-To: <cover.1557206859.git.baolin.wang@linaro.org>

Let the DMA engine core do the device node validation instead of drivers.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 drivers/dma/sh/rcar-dmac.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c
index 2b4f256..9474d5b 100644
--- a/drivers/dma/sh/rcar-dmac.c
+++ b/drivers/dma/sh/rcar-dmac.c
@@ -1632,8 +1632,7 @@ static bool rcar_dmac_chan_filter(struct dma_chan *chan, void *arg)
 	 * Forcing it to call dma_request_channel() and iterate through all
 	 * channels from all controllers is just pointless.
 	 */
-	if (chan->device->device_config != rcar_dmac_device_config ||
-	    dma_spec->np != chan->device->dev->of_node)
+	if (chan->device->device_config != rcar_dmac_device_config)
 		return false;
 
 	return !test_and_set_bit(dma_spec->args[0], dmac->modules);
@@ -1653,7 +1652,8 @@ static struct dma_chan *rcar_dmac_of_xlate(struct of_phandle_args *dma_spec,
 	dma_cap_zero(mask);
 	dma_cap_set(DMA_SLAVE, mask);
 
-	chan = dma_request_channel(mask, rcar_dmac_chan_filter, dma_spec);
+	chan = __dma_request_channel(&mask, rcar_dmac_chan_filter, dma_spec,
+				     ofdma->of_node);
 	if (!chan)
 		return NULL;
 
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 8/8] dmaengine: sh: usb-dmac: Let the core do the device node validation
From: Baolin Wang @ 2019-05-07  6:09 UTC (permalink / raw)
  To: dan.j.williams, vkoul
  Cc: thierry.reding, jonathanh, linux-tegra, shawnguo, s.hauer, kernel,
	festevam, linux-imx, Zubair.Kakakhel, wsa+renesas, jroedel,
	vincent.guittot, baolin.wang, dmaengine, linux-kernel,
	linux-arm-kernel
In-Reply-To: <cover.1557206859.git.baolin.wang@linaro.org>

Let the DMA engine core do the device node validation instead of drivers.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 drivers/dma/sh/usb-dmac.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/sh/usb-dmac.c b/drivers/dma/sh/usb-dmac.c
index 59403f6..0afabf3 100644
--- a/drivers/dma/sh/usb-dmac.c
+++ b/drivers/dma/sh/usb-dmac.c
@@ -636,9 +636,6 @@ static bool usb_dmac_chan_filter(struct dma_chan *chan, void *arg)
 	struct usb_dmac_chan *uchan = to_usb_dmac_chan(chan);
 	struct of_phandle_args *dma_spec = arg;
 
-	if (dma_spec->np != chan->device->dev->of_node)
-		return false;
-
 	/* USB-DMAC should be used with fixed usb controller's FIFO */
 	if (uchan->index != dma_spec->args[0])
 		return false;
@@ -659,7 +656,8 @@ static struct dma_chan *usb_dmac_of_xlate(struct of_phandle_args *dma_spec,
 	dma_cap_zero(mask);
 	dma_cap_set(DMA_SLAVE, mask);
 
-	chan = dma_request_channel(mask, usb_dmac_chan_filter, dma_spec);
+	chan = __dma_request_channel(&mask, usb_dmac_chan_filter, dma_spec,
+				     ofdma->of_node);
 	if (!chan)
 		return NULL;
 
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH] dmaengine: stm32-dma: Fix redundant call to platform_get_irq
From: Amelie Delaunay @ 2019-05-07  7:54 UTC (permalink / raw)
  To: Dan Williams, Vinod Koul, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel,
	Amelie Delaunay

Commit c6504be53972 ("dmaengine: stm32-dma: Fix unsigned variable compared
with zero") duplicated the call to platform_get_irq.
So remove the first call to platform_get_irq.

Fixes: c6504be53972 ("dmaengine: stm32-dma: Fix unsigned variable compared with zero")
Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/dma/stm32-dma.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index 88d9c6c..67fdd02 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -1366,7 +1366,6 @@ static int stm32_dma_probe(struct platform_device *pdev)
 
 	for (i = 0; i < STM32_DMA_MAX_CHANNELS; i++) {
 		chan = &dmadev->chan[i];
-		chan->irq = platform_get_irq(pdev, i);
 		ret = platform_get_irq(pdev, i);
 		if (ret < 0)  {
 			if (ret != -EPROBE_DEFER)
-- 
2.7.4


^ permalink raw reply related

* Re: [PATCH 07/16] dmaengine: Add function to request slave channel from a dma_device
From: Peter Ujfalusi @ 2019-05-07  8:37 UTC (permalink / raw)
  To: vkoul, robh+dt, nm, ssantosh
  Cc: dan.j.williams, dmaengine, linux-arm-kernel, devicetree,
	linux-kernel, grygorii.strashko, lokeshvutla, t-kristo, tony
In-Reply-To: <20190506123456.6777-8-peter.ujfalusi@ti.com>



On 06/05/2019 15.34, Peter Ujfalusi wrote:
> dma_get_any_slave_channel() would skip using the filter function, which
> in some cases needed to be executed before the alloc_chan_resources
> callback to make sure that all parameters are provided for the slave
> channel.

This can be dropped in favor of
https://patchwork.kernel.org/patch/10932299/
from Baolin Wangm and using __dma_request_channel() in the k3-udma driver.

- Péter

> 
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
> ---
>  drivers/dma/dmaengine.c   | 7 ++++---
>  include/linux/dmaengine.h | 5 ++++-
>  2 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index 8eed5ff0fc01..7ec93be12088 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -617,7 +617,8 @@ struct dma_chan *dma_get_slave_channel(struct dma_chan *chan)
>  }
>  EXPORT_SYMBOL_GPL(dma_get_slave_channel);
>  
> -struct dma_chan *dma_get_any_slave_channel(struct dma_device *device)
> +struct dma_chan *dmadev_get_slave_channel(struct dma_device *device,
> +					  dma_filter_fn fn, void *fn_param)
>  {
>  	dma_cap_mask_t mask;
>  	struct dma_chan *chan;
> @@ -628,13 +629,13 @@ struct dma_chan *dma_get_any_slave_channel(struct dma_device *device)
>  	/* lock against __dma_request_channel */
>  	mutex_lock(&dma_list_mutex);
>  
> -	chan = find_candidate(device, &mask, NULL, NULL);
> +	chan = find_candidate(device, &mask, fn, fn_param);
>  
>  	mutex_unlock(&dma_list_mutex);
>  
>  	return IS_ERR(chan) ? NULL : chan;
>  }
> -EXPORT_SYMBOL_GPL(dma_get_any_slave_channel);
> +EXPORT_SYMBOL_GPL(dmadev_get_slave_channel);
>  
>  /**
>   * __dma_request_channel - try to allocate an exclusive channel
> diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
> index c1486564a314..4774b66f2064 100644
> --- a/include/linux/dmaengine.h
> +++ b/include/linux/dmaengine.h
> @@ -1541,7 +1541,10 @@ int dmaenginem_async_device_register(struct dma_device *device);
>  void dma_async_device_unregister(struct dma_device *device);
>  void dma_run_dependencies(struct dma_async_tx_descriptor *tx);
>  struct dma_chan *dma_get_slave_channel(struct dma_chan *chan);
> -struct dma_chan *dma_get_any_slave_channel(struct dma_device *device);
> +struct dma_chan *dmadev_get_slave_channel(struct dma_device *device,
> +					  dma_filter_fn fn, void *fn_param);
> +#define dma_get_any_slave_channel(device) \
> +	dmadev_get_slave_channel(device, NULL, NULL)
>  #define dma_request_channel(mask, x, y) __dma_request_channel(&(mask), x, y)
>  #define dma_request_slave_channel_compat(mask, x, y, dev, name) \
>  	__dma_request_slave_channel_compat(&(mask), x, y, dev, name)
> 

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

^ permalink raw reply

* Re: [PATCH 1/8] dmaengine: Add matching device node validation in __dma_request_channel()
From: Peter Ujfalusi @ 2019-05-07  8:37 UTC (permalink / raw)
  To: Baolin Wang, dan.j.williams, vkoul
  Cc: thierry.reding, jonathanh, linux-tegra, shawnguo, s.hauer, kernel,
	festevam, linux-imx, Zubair.Kakakhel, wsa+renesas, jroedel,
	vincent.guittot, dmaengine, linux-kernel, linux-arm-kernel
In-Reply-To: <17a22052fdb759ae6129e30f9bd8862f23a03ad9.1557206859.git.baolin.wang@linaro.org>

Hi,

On 07/05/2019 9.09, Baolin Wang wrote:
> When user try to request one DMA channel by __dma_request_channel(), it won't
> validate if it is the correct DMA device to request, that will lead each DMA
> engine driver to validate the correct device node in their filter function
> if it is necessary.
> 
> Thus we can add the matching device node validation in the DMA engine core,
> to remove all of device node validation in the drivers.

I have picked this patch to my TI UDMA series and with
__dma_request_channel() it works as expected - picking the channel from
the correct DMA device.

Tested-by: Peter Ujfalusi <peter.ujfalusi@ti.com>

> 
> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
> ---
>  drivers/dma/dmaengine.c   |   10 ++++++++--
>  drivers/dma/of-dma.c      |    4 ++--
>  include/linux/dmaengine.h |   12 ++++++++----
>  3 files changed, 18 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index 3a11b10..610080c 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -641,11 +641,13 @@ struct dma_chan *dma_get_any_slave_channel(struct dma_device *device)
>   * @mask: capabilities that the channel must satisfy
>   * @fn: optional callback to disposition available channels
>   * @fn_param: opaque parameter to pass to dma_filter_fn
> + * @np: device node to look for DMA channels
>   *
>   * Returns pointer to appropriate DMA channel on success or NULL.
>   */
>  struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
> -				       dma_filter_fn fn, void *fn_param)
> +				       dma_filter_fn fn, void *fn_param,
> +				       struct device_node *np)
>  {
>  	struct dma_device *device, *_d;
>  	struct dma_chan *chan = NULL;
> @@ -653,6 +655,10 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
>  	/* Find a channel */
>  	mutex_lock(&dma_list_mutex);
>  	list_for_each_entry_safe(device, _d, &dma_device_list, global_node) {
> +		/* Finds a DMA controller with matching device node */
> +		if (np && device->dev->of_node && np != device->dev->of_node)
> +			continue;
> +
>  		chan = find_candidate(device, mask, fn, fn_param);
>  		if (!IS_ERR(chan))
>  			break;
> @@ -769,7 +775,7 @@ struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask)
>  	if (!mask)
>  		return ERR_PTR(-ENODEV);
>  
> -	chan = __dma_request_channel(mask, NULL, NULL);
> +	chan = __dma_request_channel(mask, NULL, NULL, NULL);
>  	if (!chan) {
>  		mutex_lock(&dma_list_mutex);
>  		if (list_empty(&dma_device_list))
> diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c
> index 91fd395..6b43d04 100644
> --- a/drivers/dma/of-dma.c
> +++ b/drivers/dma/of-dma.c
> @@ -316,8 +316,8 @@ struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec,
>  	if (count != 1)
>  		return NULL;
>  
> -	return dma_request_channel(info->dma_cap, info->filter_fn,
> -			&dma_spec->args[0]);
> +	return __dma_request_channel(&info->dma_cap, info->filter_fn,
> +				     &dma_spec->args[0], dma_spec->np);
>  }
>  EXPORT_SYMBOL_GPL(of_dma_simple_xlate);
>  
> diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
> index d49ec5c..504085b 100644
> --- a/include/linux/dmaengine.h
> +++ b/include/linux/dmaengine.h
> @@ -1314,7 +1314,8 @@ static inline enum dma_status dma_async_is_complete(dma_cookie_t cookie,
>  enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx);
>  void dma_issue_pending_all(void);
>  struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
> -					dma_filter_fn fn, void *fn_param);
> +				       dma_filter_fn fn, void *fn_param,
> +				       struct device_node *np);
>  struct dma_chan *dma_request_slave_channel(struct device *dev, const char *name);
>  
>  struct dma_chan *dma_request_chan(struct device *dev, const char *name);
> @@ -1339,7 +1340,9 @@ static inline void dma_issue_pending_all(void)
>  {
>  }
>  static inline struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
> -					      dma_filter_fn fn, void *fn_param)
> +						     dma_filter_fn fn,
> +						     void *fn_param,
> +						     struct device_node *np)
>  {
>  	return NULL;
>  }
> @@ -1411,7 +1414,8 @@ static inline int dmaengine_desc_free(struct dma_async_tx_descriptor *desc)
>  void dma_run_dependencies(struct dma_async_tx_descriptor *tx);
>  struct dma_chan *dma_get_slave_channel(struct dma_chan *chan);
>  struct dma_chan *dma_get_any_slave_channel(struct dma_device *device);
> -#define dma_request_channel(mask, x, y) __dma_request_channel(&(mask), x, y)
> +#define dma_request_channel(mask, x, y) \
> +	__dma_request_channel(&(mask), x, y, NULL)
>  #define dma_request_slave_channel_compat(mask, x, y, dev, name) \
>  	__dma_request_slave_channel_compat(&(mask), x, y, dev, name)
>  
> @@ -1429,6 +1433,6 @@ static inline int dmaengine_desc_free(struct dma_async_tx_descriptor *desc)
>  	if (!fn || !fn_param)
>  		return NULL;
>  
> -	return __dma_request_channel(mask, fn, fn_param);
> +	return __dma_request_channel(mask, fn, fn_param, NULL);
>  }
>  #endif /* DMAENGINE_H */
> 

- Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

^ permalink raw reply

* RE: [RFC v6 1/6] dmaengine: Add Synopsys eDMA IP core driver
From: Gustavo Pimentel @ 2019-05-07  9:08 UTC (permalink / raw)
  To: Vinod Koul, Gustavo Pimentel
  Cc: linux-pci@vger.kernel.org, dmaengine@vger.kernel.org,
	Dan Williams, Andy Shevchenko, Russell King, Joao Pinto
In-Reply-To: <20190507050310.GA16052@vkoul-mobl>

On Tue, May 7, 2019 at 6:3:10, Vinod Koul <vkoul@kernel.org> wrote:

> On 06-05-19, 16:42, Gustavo Pimentel wrote:
> 
> > > > +	if (unlikely(!chunk))
> > > > +		return NULL;
> > > > +
> > > > +	INIT_LIST_HEAD(&chunk->list);
> > > > +	chunk->chan = chan;
> > > > +	chunk->cb = !(desc->chunks_alloc % 2);
> > > ? why %2?
> > 
> > I think it's explained on the patch description. CB also is known as 
> > Change Bit that must be toggled in order to the HW assume a new linked 
> > list is available to be consumed.
> > Since desc->chunks_alloc variable is an incremental counter the remainder 
> > after division by 2 will be zero (if chunks_alloc is even) or one (if 
> > chunks_alloc is odd).
> 
> Okay it would be great to add a comment here to explain as well

Ok, I'll add it.

> 
> > > > +static enum dma_status
> > > > +dw_edma_device_tx_status(struct dma_chan *dchan, dma_cookie_t cookie,
> > > > +			 struct dma_tx_state *txstate)
> > > > +{
> > > > +	struct dw_edma_chan *chan = dchan2dw_edma_chan(dchan);
> > > > +	struct dw_edma_desc *desc;
> > > > +	struct virt_dma_desc *vd;
> > > > +	unsigned long flags;
> > > > +	enum dma_status ret;
> > > > +	u32 residue = 0;
> > > > +
> > > > +	ret = dma_cookie_status(dchan, cookie, txstate);
> > > > +	if (ret == DMA_COMPLETE)
> > > > +		return ret;
> > > > +
> > > > +	if (ret == DMA_IN_PROGRESS && chan->status == EDMA_ST_PAUSE)
> > > > +		ret = DMA_PAUSED;
> > > 
> > > Don't you want to set residue on paused channel, how else will user know
> > > the position of pause?
> > 
> > I didn't catch you on this. I'm only setting the dma status here. After 
> > this function, the residue is calculated and set, isn't it?
> 
> Hmm I thought you returned for paused case, if not then it is okay

No, I'm just setting the dma status in pause case, then I calculate the 
residue.

> 
> > > > +static struct dma_async_tx_descriptor *
> > > > +dw_edma_device_transfer(struct dw_edma_transfer *xfer)
> > > > +{
> > > > +	struct dw_edma_chan *chan = dchan2dw_edma_chan(xfer->dchan);
> > > > +	enum dma_transfer_direction direction = xfer->direction;
> > > > +	phys_addr_t src_addr, dst_addr;
> > > > +	struct scatterlist *sg = NULL;
> > > > +	struct dw_edma_chunk *chunk;
> > > > +	struct dw_edma_burst *burst;
> > > > +	struct dw_edma_desc *desc;
> > > > +	u32 cnt;
> > > > +	int i;
> > > > +
> > > > +	if ((direction == DMA_MEM_TO_DEV && chan->dir == EDMA_DIR_WRITE) ||
> > > > +	    (direction == DMA_DEV_TO_MEM && chan->dir == EDMA_DIR_READ))
> > > > +		return NULL;
> > > > +
> > > > +	if (xfer->cyclic) {
> > > > +		if (!xfer->xfer.cyclic.len || !xfer->xfer.cyclic.cnt)
> > > > +			return NULL;
> > > > +	} else {
> > > > +		if (xfer->xfer.sg.len < 1)
> > > > +			return NULL;
> > > > +	}
> > > > +
> > > > +	if (!chan->configured)
> > > > +		return NULL;
> > > > +
> > > > +	desc = dw_edma_alloc_desc(chan);
> > > > +	if (unlikely(!desc))
> > > > +		goto err_alloc;
> > > > +
> > > > +	chunk = dw_edma_alloc_chunk(desc);
> > > > +	if (unlikely(!chunk))
> > > > +		goto err_alloc;
> > > > +
> > > > +	src_addr = chan->config.src_addr;
> > > > +	dst_addr = chan->config.dst_addr;
> > > > +
> > > > +	if (xfer->cyclic) {
> > > > +		cnt = xfer->xfer.cyclic.cnt;
> > > > +	} else {
> > > > +		cnt = xfer->xfer.sg.len;
> > > > +		sg = xfer->xfer.sg.sgl;
> > > > +	}
> > > > +
> > > > +	for (i = 0; i < cnt; i++) {
> > > > +		if (!xfer->cyclic && !sg)
> > > > +			break;
> > > > +
> > > > +		if (chunk->bursts_alloc == chan->ll_max) {
> > > > +			chunk = dw_edma_alloc_chunk(desc);
> > > > +			if (unlikely(!chunk))
> > > > +				goto err_alloc;
> > > > +		}
> > > > +
> > > > +		burst = dw_edma_alloc_burst(chunk);
> > > > +		if (unlikely(!burst))
> > > > +			goto err_alloc;
> > > > +
> > > > +		if (xfer->cyclic)
> > > > +			burst->sz = xfer->xfer.cyclic.len;
> > > > +		else
> > > > +			burst->sz = sg_dma_len(sg);
> > > > +
> > > > +		chunk->ll_region.sz += burst->sz;
> > > > +		desc->alloc_sz += burst->sz;
> > > > +
> > > > +		if (direction == DMA_DEV_TO_MEM) {
> > > > +			burst->sar = src_addr;
> > > 
> > > We are device to mem, so src is peripheral.. okay
> > > 
> > > > +			if (xfer->cyclic) {
> > > > +				burst->dar = xfer->xfer.cyclic.paddr;
> > > > +			} else {
> > > > +				burst->dar = sg_dma_address(sg);
> > > > +				src_addr += sg_dma_len(sg);
> > > 
> > > and we increment the src, doesn't make sense to me!
> > > 
> > > > +			}
> > > > +		} else {
> > > > +			burst->dar = dst_addr;
> > > > +			if (xfer->cyclic) {
> > > > +				burst->sar = xfer->xfer.cyclic.paddr;
> > > > +			} else {
> > > > +				burst->sar = sg_dma_address(sg);
> > > > +				dst_addr += sg_dma_len(sg);
> > > 
> > > same here as well
> > 
> > This is hard to explain in words...
> > Well, in my perspective I want to transfer a piece of memory from the 
> > peripheral into local RAM
> 
> Right and most of the case RAM address (sg) needs to increment whereas
> peripheral is a constant one
> 
> > Through the DMA client API I'll break this piece of memory in several 
> > small parts and add all into a list (scatter-gather), right?
> > Each element of the scatter-gather has the sg_dma_address (in the 
> > DMA_DEV_TO_MEM case will be the destination address) and the 
> > corresponding size.
> 
> Correct
> 
> > However, I still need the other address (in the DMA_DEV_TO_MEM case will 
> > be the source address) for that small part of memory.
> > Since I get that address from the config, I still need to increment the 
> > source address in the same proportion of the destination address, in 
> > other words, the increment will be the part size.
> 
> I don't think so. Typically the device address is a FIFO, which does not
> increment and you keep pushing data at same address. It is not a memory

In my use case, it's a memory, perhaps that is what is causing this 
confusing.
I'm copying "plain and flat" data from point A to B, with the 
particularity that the peripheral memory is always continuous and the CPU 
memory can be constituted by scatter-gather chunks of contiguous memory

> 
> > If there is some way to set and get the address for the source (in this 
> > case) into each scatter-gather element, that would be much nicer, is that 
> > possible?
> 
> > > > +		case EDMA_REQ_STOP:
> > > > +			list_del(&vd->node);
> > > > +			vchan_cookie_complete(vd);
> > > > +			chan->request = EDMA_REQ_NONE;
> > > > +			chan->status = EDMA_ST_IDLE;
> > > 
> > > Why do we need to track request as well as status?
> > 
> > Since I don't actually have the PAUSE state feature available on HW, I'm 
> > emulating it through software. As far as HW is concerned, it thinks that 
> > it has transferred everything (no more bursts valid available), but in 
> > terms of software, we still have a lot of chunks (each one containing 
> > several bursts) to process.
> 
> Why do you need to emulate, if HW doesnt support so be it?
> The applications should handle a device which doesnt support pause and
> not a low level driver

In this case, since I've to refill the eDMA memory and retrigger the HW 
block each time the transfer is completed, it's easy to emulate a pause 
state, by holding or not refilling the eDMA memory.
I thought that this could be a nice and easy feature to have.

> 
> > > > +struct dw_edma_transfer {
> > > > +	struct dma_chan			*dchan;
> > > > +	union Xfer {
> > > 
> > > no camel case please
> > 
> > Ok.
> > 
> > > 
> > > It would help to run checkpatch with --strict option to find any style
> > > issues and fix them as well
> > 
> > I usually run with that option, but for now, that option is giving some 
> > warnings about macro variable names that are pure noise.
> 
> yeah that is a *guide* and to be used as guidance. If code looks worse
> off then it shouldn't be used. But many of the test are helpful. Some
> macros checks actually make sense, but again use your judgement :)

Sure.

> 
> -- 
> ~Vinod

Regards,
Gustavo


^ permalink raw reply

* [PATCH v3 00/14] add ecspi ERR009165 for i.mx6/7 soc family
From: Robin Gong @ 2019-05-07  9:15 UTC (permalink / raw)
  To: robh@kernel.org, broonie@kernel.org, shawnguo@kernel.org,
	s.hauer@pengutronix.de, festevam@gmail.com, mark.rutland@arm.com,
	u.kleine-koenig@pengutronix.de, plyatov@gmail.com,
	vkoul@kernel.org, dan.j.williams@intel.com,
	catalin.marinas@arm.com, will.deacon@arm.com,
	l.stach@pengutronix.de
  Cc: dl-linux-imx, linux-spi@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org,
	devicetree@vger.kernel.org, kernel@pengutronix.de

  There is ecspi ERR009165 on i.mx6/7 soc family, which cause FIFO
transfer to be send twice in DMA mode. Please get more information from:
https://www.nxp.com/docs/en/errata/IMX6DQCE.pdf. The workaround is adding
new sdma ram script which works in XCH  mode as PIO inside sdma instead
of SMC mode, meanwhile, 'TX_THRESHOLD' should be 0. The issue should be
exist on all legacy i.mx6/7 soc family before i.mx6ul.
NXP fix this design issue from i.mx6ul, so newer chips including i.mx6ul/
6ull/6sll do not need this workaroud anymore. All other i.mx6/7/8 chips
still need this workaroud. This patch set add new 'fsl,imx6ul-ecspi'
for ecspi driver and 'ecspi_fixed' in sdma driver to choose if need errata
or not.
  The first two reverted patches should be the same issue, though, it
seems 'fixed' by changing to other shp script. Hope Sean or Sascha could
have the chance to test this patch set if could fix their issues.
  Besides, enable sdma support for i.mx8mm/8mq and fix ecspi1 not work
on i.mx8mm because the event id is zero.

PS:
  Please get sdma firmware from below linux-firmware and copy it to your
local rootfs /lib/firmware/imx/sdma.
https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/imx/sdma

v2:
  1. add commit log for reverted patches.
  2. add comment for 'ecspi_fixed' in sdma driver.
  3. add 'fsl,imx6sll-ecspi' compatible instead of 'fsl,imx6ul-ecspi'
     rather than remove.
v3:
  1. confirm with design team make sure ERR009165 fixed on i.mx6ul/i.mx6ull
  /i.mx6sll, not fixed on i.mx8m/8mm and other i.mx6/7 legacy chips.
  Correct dts related dts patch in v2.
  2. clean eratta information in binding doc and new 'tx_glitch_fixed' flag
  in spi-imx driver to state ERR009165 fixed or not.
  3. Enlarge burst size to fifo size for tx since tx_wml set to 0 in the
  errata workaroud, thus improve performance as possible.

Robin Gong (14):
  Revert "ARM: dts: imx6q: Use correct SDMA script for SPI5 core"
  Revert "ARM: dts: imx6: Use correct SDMA script for SPI cores"
  Revert "dmaengine: imx-sdma: refine to load context only once"
  dmaengine: imx-sdma: remove dupilicated sdma_load_context
  dmaengine: imx-sdma: add mcu_2_ecspi script
  spi: imx: fix ERR009165
  spi: imx: remove ERR009165 workaround on i.mx6ul
  dt-bindings: spi: imx: add new i.mx6ul compatible name
  dmaengine: imx-sdma: remove ERR009165 on i.mx6ul
  dt-bindings: dma: imx-sdma: add i.mx6ul/6sx compatible name
  dmaengine: imx-sdma: fix ecspi1 rx dma not work on i.mx8mm
  ARM: dts: imx6ul: add dma support on ecspi
  ARM: dts: imx6sll: correct sdma compatible
  arm64: defconfig: Enable SDMA on i.mx8mq/8mm

 .../devicetree/bindings/dma/fsl-imx-sdma.txt       |  2 +
 .../devicetree/bindings/spi/fsl-imx-cspi.txt       |  1 +
 arch/arm/boot/dts/imx6q.dtsi                       |  2 +-
 arch/arm/boot/dts/imx6qdl.dtsi                     |  8 +--
 arch/arm/boot/dts/imx6sll.dtsi                     |  2 +-
 arch/arm/boot/dts/imx6ul.dtsi                      |  8 +++
 arch/arm64/configs/defconfig                       |  3 +
 drivers/dma/imx-sdma.c                             | 78 ++++++++++++++++------
 drivers/spi/spi-imx.c                              | 61 ++++++++++++++---
 include/linux/platform_data/dma-imx-sdma.h         |  1 +
 10 files changed, 132 insertions(+), 34 deletions(-)

-- 
2.7.4


^ permalink raw reply

* [PATCH v3 01/14] Revert "ARM: dts: imx6q: Use correct SDMA script for SPI5 core"
From: Robin Gong @ 2019-05-07  9:15 UTC (permalink / raw)
  To: robh@kernel.org, broonie@kernel.org, shawnguo@kernel.org,
	s.hauer@pengutronix.de, festevam@gmail.com, mark.rutland@arm.com,
	u.kleine-koenig@pengutronix.de, plyatov@gmail.com,
	vkoul@kernel.org, dan.j.williams@intel.com,
	catalin.marinas@arm.com, will.deacon@arm.com,
	l.stach@pengutronix.de
  Cc: dl-linux-imx, linux-spi@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org,
	devicetree@vger.kernel.org, kernel@pengutronix.de
In-Reply-To: <1557249513-4903-1-git-send-email-yibin.gong@nxp.com>

  There are two ways for SDMA accessing SPBA devices: one is SDMA->AIPS
->SPBA(masterA port), another is SDMA->SPBA(masterC port). Please refer
to the 'Figure 58-1. i.MX 6Dual/6Quad SPBA connectivity' of i.mx6DQ
Reference Manual. SDMA provide the corresponding app_2_mcu/mcu_2_app and
shp_2_mcu/mcu_2_shp script for such two options. So both AIPS and SPBA
scripts should keep the same behaviour, the issue only caught in AIPS
script sounds not solide.
  The issue is more likely as the ecspi errata
ERR009165(http://www.nxp.com/docs/en/errata/IMX6DQCE.pdf):
eCSPI: TXFIFO empty flag glitch can cause the current FIFO transfer to
       be sent twice
So revert commit 'df07101e1c4a' firstly.

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
---
 arch/arm/boot/dts/imx6q.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/imx6q.dtsi b/arch/arm/boot/dts/imx6q.dtsi
index d038f41..7175898 100644
--- a/arch/arm/boot/dts/imx6q.dtsi
+++ b/arch/arm/boot/dts/imx6q.dtsi
@@ -172,7 +172,7 @@
 					clocks = <&clks IMX6Q_CLK_ECSPI5>,
 						 <&clks IMX6Q_CLK_ECSPI5>;
 					clock-names = "ipg", "per";
-					dmas = <&sdma 11 8 1>, <&sdma 12 8 2>;
+					dmas = <&sdma 11 7 1>, <&sdma 12 7 2>;
 					dma-names = "rx", "tx";
 					status = "disabled";
 				};
-- 
2.7.4


^ permalink raw reply related

* [PATCH v3 02/14] Revert "ARM: dts: imx6: Use correct SDMA script for SPI cores"
From: Robin Gong @ 2019-05-07  9:15 UTC (permalink / raw)
  To: robh@kernel.org, broonie@kernel.org, shawnguo@kernel.org,
	s.hauer@pengutronix.de, festevam@gmail.com, mark.rutland@arm.com,
	u.kleine-koenig@pengutronix.de, plyatov@gmail.com,
	vkoul@kernel.org, dan.j.williams@intel.com,
	catalin.marinas@arm.com, will.deacon@arm.com,
	l.stach@pengutronix.de
  Cc: dl-linux-imx, linux-spi@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org,
	devicetree@vger.kernel.org, kernel@pengutronix.de
In-Reply-To: <1557249513-4903-1-git-send-email-yibin.gong@nxp.com>

  There are two ways for SDMA accessing SPBA devices: one is SDMA->AIPS
->SPBA(masterA port), another is SDMA->SPBA(masterC port). Please refer
to the 'Figure 58-1. i.MX 6Dual/6Quad SPBA connectivity' of i.mx6DQ
Reference Manual. SDMA provide the corresponding app_2_mcu/mcu_2_app and
shp_2_mcu/mcu_2_shp script for such two options. So both AIPS and SPBA
scripts should keep the same behaviour, the issue only caught in AIPS
script sounds not solide.
  The issue is more likely as the ecspi errata
ERR009165(http://www.nxp.com/docs/en/errata/IMX6DQCE.pdf):
eCSPI: TXFIFO empty flag glitch can cause the current FIFO transfer to
           be sent twice
So revert commit 'dd4b487b32a3' firstly.

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
---
 arch/arm/boot/dts/imx6qdl.dtsi | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boot/dts/imx6qdl.dtsi b/arch/arm/boot/dts/imx6qdl.dtsi
index b3a77bc..a90f217 100644
--- a/arch/arm/boot/dts/imx6qdl.dtsi
+++ b/arch/arm/boot/dts/imx6qdl.dtsi
@@ -339,7 +339,7 @@
 					clocks = <&clks IMX6QDL_CLK_ECSPI1>,
 						 <&clks IMX6QDL_CLK_ECSPI1>;
 					clock-names = "ipg", "per";
-					dmas = <&sdma 3 8 1>, <&sdma 4 8 2>;
+					dmas = <&sdma 3 7 1>, <&sdma 4 7 2>;
 					dma-names = "rx", "tx";
 					status = "disabled";
 				};
@@ -353,7 +353,7 @@
 					clocks = <&clks IMX6QDL_CLK_ECSPI2>,
 						 <&clks IMX6QDL_CLK_ECSPI2>;
 					clock-names = "ipg", "per";
-					dmas = <&sdma 5 8 1>, <&sdma 6 8 2>;
+					dmas = <&sdma 5 7 1>, <&sdma 6 7 2>;
 					dma-names = "rx", "tx";
 					status = "disabled";
 				};
@@ -367,7 +367,7 @@
 					clocks = <&clks IMX6QDL_CLK_ECSPI3>,
 						 <&clks IMX6QDL_CLK_ECSPI3>;
 					clock-names = "ipg", "per";
-					dmas = <&sdma 7 8 1>, <&sdma 8 8 2>;
+					dmas = <&sdma 7 7 1>, <&sdma 8 7 2>;
 					dma-names = "rx", "tx";
 					status = "disabled";
 				};
@@ -381,7 +381,7 @@
 					clocks = <&clks IMX6QDL_CLK_ECSPI4>,
 						 <&clks IMX6QDL_CLK_ECSPI4>;
 					clock-names = "ipg", "per";
-					dmas = <&sdma 9 8 1>, <&sdma 10 8 2>;
+					dmas = <&sdma 9 7 1>, <&sdma 10 7 2>;
 					dma-names = "rx", "tx";
 					status = "disabled";
 				};
-- 
2.7.4


^ permalink raw reply related

* [PATCH v3 03/14] Revert "dmaengine: imx-sdma: refine to load context only once"
From: Robin Gong @ 2019-05-07  9:15 UTC (permalink / raw)
  To: robh@kernel.org, broonie@kernel.org, shawnguo@kernel.org,
	s.hauer@pengutronix.de, festevam@gmail.com, mark.rutland@arm.com,
	u.kleine-koenig@pengutronix.de, plyatov@gmail.com,
	vkoul@kernel.org, dan.j.williams@intel.com,
	catalin.marinas@arm.com, will.deacon@arm.com,
	l.stach@pengutronix.de
  Cc: dl-linux-imx, linux-spi@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org,
	devicetree@vger.kernel.org, kernel@pengutronix.de
In-Reply-To: <1557249513-4903-1-git-send-email-yibin.gong@nxp.com>

This reverts commit ad0d92d7ba6aecbe2705907c38ff8d8be4da1e9c, because
in spi-imx case, burst length may be changed dynamically.

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
---
 drivers/dma/imx-sdma.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 99d9f43..407a56e 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -377,7 +377,6 @@ struct sdma_channel {
 	unsigned long			watermark_level;
 	u32				shp_addr, per_addr;
 	enum dma_status			status;
-	bool				context_loaded;
 	struct imx_dma_data		data;
 	struct work_struct		terminate_worker;
 };
@@ -988,9 +987,6 @@ static int sdma_load_context(struct sdma_channel *sdmac)
 	int ret;
 	unsigned long flags;
 
-	if (sdmac->context_loaded)
-		return 0;
-
 	if (sdmac->direction == DMA_DEV_TO_MEM)
 		load_address = sdmac->pc_from_device;
 	else if (sdmac->direction == DMA_DEV_TO_DEV)
@@ -1033,8 +1029,6 @@ static int sdma_load_context(struct sdma_channel *sdmac)
 
 	spin_unlock_irqrestore(&sdma->channel_0_lock, flags);
 
-	sdmac->context_loaded = true;
-
 	return ret;
 }
 
@@ -1074,7 +1068,6 @@ static void sdma_channel_terminate_work(struct work_struct *work)
 	sdmac->desc = NULL;
 	spin_unlock_irqrestore(&sdmac->vc.lock, flags);
 	vchan_dma_desc_free_list(&sdmac->vc, &head);
-	sdmac->context_loaded = false;
 }
 
 static int sdma_disable_channel_async(struct dma_chan *chan)
-- 
2.7.4


^ permalink raw reply related

* [PATCH v3 04/14] dmaengine: imx-sdma: remove dupilicated sdma_load_context
From: Robin Gong @ 2019-05-07  9:16 UTC (permalink / raw)
  To: robh@kernel.org, broonie@kernel.org, shawnguo@kernel.org,
	s.hauer@pengutronix.de, festevam@gmail.com, mark.rutland@arm.com,
	u.kleine-koenig@pengutronix.de, plyatov@gmail.com,
	vkoul@kernel.org, dan.j.williams@intel.com,
	catalin.marinas@arm.com, will.deacon@arm.com,
	l.stach@pengutronix.de
  Cc: dl-linux-imx, linux-spi@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org,
	devicetree@vger.kernel.org, kernel@pengutronix.de
In-Reply-To: <1557249513-4903-1-git-send-email-yibin.gong@nxp.com>

Since sdma_transfer_init() will do sdma_load_context before any
sdma transfer, no need once more in sdma_config_channel().

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
---
 drivers/dma/imx-sdma.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 407a56e..86a31b4 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -1134,7 +1134,6 @@ static void sdma_set_watermarklevel_for_p2p(struct sdma_channel *sdmac)
 static int sdma_config_channel(struct dma_chan *chan)
 {
 	struct sdma_channel *sdmac = to_sdma_chan(chan);
-	int ret;
 
 	sdma_disable_channel(chan);
 
@@ -1174,9 +1173,7 @@ static int sdma_config_channel(struct dma_chan *chan)
 		sdmac->watermark_level = 0; /* FIXME: M3_BASE_ADDRESS */
 	}
 
-	ret = sdma_load_context(sdmac);
-
-	return ret;
+	return 0;
 }
 
 static int sdma_set_channel_priority(struct sdma_channel *sdmac,
-- 
2.7.4


^ permalink raw reply related

* [PATCH v3 05/14] dmaengine: imx-sdma: add mcu_2_ecspi script
From: Robin Gong @ 2019-05-07  9:16 UTC (permalink / raw)
  To: robh@kernel.org, broonie@kernel.org, shawnguo@kernel.org,
	s.hauer@pengutronix.de, festevam@gmail.com, mark.rutland@arm.com,
	u.kleine-koenig@pengutronix.de, plyatov@gmail.com,
	vkoul@kernel.org, dan.j.williams@intel.com,
	catalin.marinas@arm.com, will.deacon@arm.com,
	l.stach@pengutronix.de
  Cc: dl-linux-imx, linux-spi@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org,
	devicetree@vger.kernel.org, kernel@pengutronix.de
In-Reply-To: <1557249513-4903-1-git-send-email-yibin.gong@nxp.com>

Add mcu_2_ecspi script to fix ecspi errata ERR009165.

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
---
 drivers/dma/imx-sdma.c                     | 3 +++
 include/linux/platform_data/dma-imx-sdma.h | 1 +
 2 files changed, 4 insertions(+)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 86a31b4..352b0d5 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -924,6 +924,9 @@ static void sdma_get_pc(struct sdma_channel *sdmac,
 		emi_2_per = sdma->script_addrs->mcu_2_ata_addr;
 		break;
 	case IMX_DMATYPE_CSPI:
+		per_2_emi = sdma->script_addrs->app_2_mcu_addr;
+		emi_2_per = sdma->script_addrs->mcu_2_ecspi_addr;
+		break;
 	case IMX_DMATYPE_EXT:
 	case IMX_DMATYPE_SSI:
 	case IMX_DMATYPE_SAI:
diff --git a/include/linux/platform_data/dma-imx-sdma.h b/include/linux/platform_data/dma-imx-sdma.h
index 6eaa53c..f794fee 100644
--- a/include/linux/platform_data/dma-imx-sdma.h
+++ b/include/linux/platform_data/dma-imx-sdma.h
@@ -51,6 +51,7 @@ struct sdma_script_start_addrs {
 	/* End of v2 array */
 	s32 zcanfd_2_mcu_addr;
 	s32 zqspi_2_mcu_addr;
+	s32 mcu_2_ecspi_addr;
 	/* End of v3 array */
 };
 
-- 
2.7.4


^ permalink raw reply related

* [PATCH v3 08/14] dt-bindings: spi: imx: add new i.mx6ul compatible name
From: Robin Gong @ 2019-05-07  9:16 UTC (permalink / raw)
  To: robh@kernel.org, broonie@kernel.org, shawnguo@kernel.org,
	s.hauer@pengutronix.de, festevam@gmail.com, mark.rutland@arm.com,
	u.kleine-koenig@pengutronix.de, plyatov@gmail.com,
	vkoul@kernel.org, dan.j.williams@intel.com,
	catalin.marinas@arm.com, will.deacon@arm.com,
	l.stach@pengutronix.de
  Cc: dl-linux-imx, linux-spi@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org,
	devicetree@vger.kernel.org, kernel@pengutronix.de
In-Reply-To: <1557249513-4903-1-git-send-email-yibin.gong@nxp.com>

ERR009165 fixed from i.mx6ul, add its compatible name.

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
---
 Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt b/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt
index 2d32641..b3d02a3 100644
--- a/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt
+++ b/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt
@@ -10,6 +10,7 @@ Required properties:
   - "fsl,imx35-cspi" for SPI compatible with the one integrated on i.MX35
   - "fsl,imx51-ecspi" for SPI compatible with the one integrated on i.MX51
   - "fsl,imx53-ecspi" for SPI compatible with the one integrated on i.MX53 and later Soc
+  - "fsl,imx6ul-ecspi" for SPI compatible with the one integrated on i.MX6UL and later Soc
   - "fsl,imx8mq-ecspi" for SPI compatible with the one integrated on i.MX8M
 - reg : Offset and length of the register set for the device
 - interrupts : Should contain CSPI/eCSPI interrupt
-- 
2.7.4


^ permalink raw reply related

* [PATCH v3 09/14] dmaengine: imx-sdma: remove ERR009165 on i.mx6ul
From: Robin Gong @ 2019-05-07  9:16 UTC (permalink / raw)
  To: robh@kernel.org, broonie@kernel.org, shawnguo@kernel.org,
	s.hauer@pengutronix.de, festevam@gmail.com, mark.rutland@arm.com,
	u.kleine-koenig@pengutronix.de, plyatov@gmail.com,
	vkoul@kernel.org, dan.j.williams@intel.com,
	catalin.marinas@arm.com, will.deacon@arm.com,
	l.stach@pengutronix.de
  Cc: dl-linux-imx, linux-spi@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org,
	devicetree@vger.kernel.org, kernel@pengutronix.de
In-Reply-To: <1557249513-4903-1-git-send-email-yibin.gong@nxp.com>

ECSPI issue fixed from i.mx6ul at hardware level, no need
ERR009165 anymore on those chips such as i.mx8mq. Add i.mx6sx
from where i.mx6ul source.

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
---
 drivers/dma/imx-sdma.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 50 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 352b0d5..a495c7f 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -419,6 +419,13 @@ struct sdma_driver_data {
 	int num_events;
 	struct sdma_script_start_addrs	*script_addrs;
 	bool check_ratio;
+	/*
+	 * ecspi ERR009165 fixed should be done in sdma script
+	 * and it has been fixed in soc from i.mx6ul.
+	 * please get more information from the below link:
+	 * https://www.nxp.com/docs/en/errata/IMX6DQCE.pdf
+	 */
+	bool ecspi_fixed;
 };
 
 struct sdma_engine {
@@ -539,6 +546,31 @@ static struct sdma_driver_data sdma_imx6q = {
 	.script_addrs = &sdma_script_imx6q,
 };
 
+static struct sdma_script_start_addrs sdma_script_imx6sx = {
+	.ap_2_ap_addr = 642,
+	.uart_2_mcu_addr = 817,
+	.mcu_2_app_addr = 747,
+	.uartsh_2_mcu_addr = 1032,
+	.mcu_2_shp_addr = 960,
+	.app_2_mcu_addr = 683,
+	.shp_2_mcu_addr = 891,
+	.spdif_2_mcu_addr = 1100,
+	.mcu_2_spdif_addr = 1134,
+};
+
+static struct sdma_driver_data sdma_imx6sx = {
+	.chnenbl0 = SDMA_CHNENBL0_IMX35,
+	.num_events = 48,
+	.script_addrs = &sdma_script_imx6sx,
+};
+
+static struct sdma_driver_data sdma_imx6ul = {
+	.chnenbl0 = SDMA_CHNENBL0_IMX35,
+	.num_events = 48,
+	.script_addrs = &sdma_script_imx6sx,
+	.ecspi_fixed = true,
+};
+
 static struct sdma_script_start_addrs sdma_script_imx7d = {
 	.ap_2_ap_addr = 644,
 	.uart_2_mcu_addr = 819,
@@ -584,9 +616,15 @@ static const struct platform_device_id sdma_devtypes[] = {
 		.name = "imx6q-sdma",
 		.driver_data = (unsigned long)&sdma_imx6q,
 	}, {
+		.name = "imx6sx-sdma",
+		.driver_data = (unsigned long)&sdma_imx6sx,
+	}, {
 		.name = "imx7d-sdma",
 		.driver_data = (unsigned long)&sdma_imx7d,
 	}, {
+		.name = "imx6ul-sdma",
+		.driver_data = (unsigned long)&sdma_imx6ul,
+	}, {
 		.name = "imx8mq-sdma",
 		.driver_data = (unsigned long)&sdma_imx8mq,
 	}, {
@@ -602,7 +640,9 @@ static const struct of_device_id sdma_dt_ids[] = {
 	{ .compatible = "fsl,imx35-sdma", .data = &sdma_imx35, },
 	{ .compatible = "fsl,imx31-sdma", .data = &sdma_imx31, },
 	{ .compatible = "fsl,imx25-sdma", .data = &sdma_imx25, },
+	{ .compatible = "fsl,imx6sx-sdma", .data = &sdma_imx6sx, },
 	{ .compatible = "fsl,imx7d-sdma", .data = &sdma_imx7d, },
+	{ .compatible = "fsl,imx6ul-sdma", .data = &sdma_imx6ul, },
 	{ .compatible = "fsl,imx8mq-sdma", .data = &sdma_imx8mq, },
 	{ /* sentinel */ }
 };
@@ -1166,8 +1206,17 @@ static int sdma_config_channel(struct dma_chan *chan)
 			if (sdmac->peripheral_type == IMX_DMATYPE_ASRC_SP ||
 			    sdmac->peripheral_type == IMX_DMATYPE_ASRC)
 				sdma_set_watermarklevel_for_p2p(sdmac);
-		} else
+		} else {
+			/*
+			 * ERR009165 fixed from i.mx6ul, no errata need,
+			 * set bit31 to let sdma script skip the errata.
+			 */
+			if (sdmac->peripheral_type == IMX_DMATYPE_CSPI &&
+			    sdmac->direction == DMA_MEM_TO_DEV &&
+			    sdmac->sdma->drvdata->ecspi_fixed)
+				__set_bit(31, &sdmac->watermark_level);
 			__set_bit(sdmac->event_id0, sdmac->event_mask);
+		}
 
 		/* Address */
 		sdmac->shp_addr = sdmac->per_address;
-- 
2.7.4


^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox