dma: pl330: Change pl330_tx_status()
RFC PATCH 1/1 dma: pl330: Change pl330_tx_status()
This patch adds possibility to read status of unfinished transfers before termination.
---
I tested patch with Exynos4 board. This is only proof of concept. Any comments are welcome.
Thanks
Lukasz
drivers/dma/pl330.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-)
drivers/dma/pl330.c +60 -1
@@ -566,6 +566,7 @@ struct dma_pl330_chan {/* For D-to-M and M-to-D channels */ int burst_sz;/* the peripheral fifo width */ int burst_len;/* the number of burst */ +int transfered;dma_addr_t fifo_addr;/* for cyclic capability */
@@ -602,6 +603,9 @@ struct dma_pl330_desc {enum desc_status status; +int bytes_requested; +int direction; +/* The channel which currently holds this desc */ struct dma_pl330_chan *pchan; };
@@ -2366,6 +2370,29 @@ static int pl330_alloc_chan_resources(struct dma_chan *chan)return 1 ; } +int pl330_get_current_xferred_count (struct dma_pl330_chan *pch, +struct dma_pl330_desc *desc) +{ +u32 val, addr; +struct pl330_thread *thrd = pch->pl330_chid; +void __iomem *regs = thrd->dmac->pinfo->base; + + val = addr =0 ; +switch (desc->direction) { +case DMA_MEM_TO_DEV : + val =readl (regs +SA (thrd->id)); + addr = desc->px.src_addr; +break ; +case DMA_DEV_TO_MEM : + val =readl (regs +DA (thrd->id)); + addr = desc->px.dst_addr; +break ; +default : +break ; + } +return val - addr; +} +static int pl330_control (struct dma_chan *chan,enum dma_ctrl_cmd cmd,unsigned long arg) {struct dma_pl330_chan *pch =to_pchan (chan);
@@ -2446,7 +2473,33 @@ static enum dma_status pl330_tx_status(struct dma_chan *chan, dma_cookie_t cookie, struct dma_tx_state *txstate) { - return dma_cookie_status(chan, cookie, txstate); + enum dma_status ret; +unsigned long flags; +struct dma_pl330_desc *desc; +struct dma_pl330_chan *pch =to_pchan (chan); +unsigned int bytes_transferred; +unsigned int residual; + +/* Check in pending list */ +spin_lock_irqsave (&pch->lock, flags); +list_for_each_entry (desc, &pch->work_list, node) { +if (desc->txd.cookie == cookie) { + bytes_transferred = +pl330_get_current_xferred_count (pch, desc); + residual = desc->bytes_requested - + bytes_transferred % desc->bytes_requested; +dma_set_residue (txstate, residual); + ret = desc->status; +spin_unlock_irqrestore (&pch->lock, flags); +return ret; + } + } +spin_unlock_irqrestore (&pch->lock, flags); + + ret =dma_cookie_status (chan, cookie, txstate); +dma_set_residue (txstate, pch->transfered); + +return ret; }static void pl330_issue_pending (struct dma_chan *chan)
@@ -2717,9 +2770,12 @@ static struct dma_async_tx_descriptor *pl330_prep_dma_cyclic(break ; } + desc->direction = direction; desc->rqcfg.brst_size = pch->burst_sz; desc->rqcfg.brst_len =1 ; + desc->bytes_requested = period_len;fill_px (&desc->px, dst, src, period_len); + pch->transfered =0 ;if (!first) first = desc;
@@ -2853,8 +2909,11 @@ pl330_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, sg_dma_address(sg), addr, sg_dma_len(sg)); } + desc->direction = direction; desc->rqcfg.brst_size = pch->burst_sz; desc->rqcfg.brst_len =1 ; + desc->bytes_requested =sg_dma_len (sg); + pch->transfered =0 ; }/* Return the last desc in the chain */
Signature · 1 line
1.7.9.5
Quoted 9 lines · Lukasz Czerwinski
This patch adds possibility to read status of unfinished transfers before termination.
Signed-off-by Lukasz Czerwinski <[email protected]>Signed-off-by Kyungmin Park <[email protected]>---
I tested patch with Exynos4 board. This is only proof of concept. Any comments are welcome.
The patch does not look as if it is going to work correctly. And I think that this can't be implemented correctly with the current structure of the driver (at least not without jumping through a couple of hoops). I do have a couple of WIP patches that restructure the driver and then implement residue reporting on top of it.
Quoted 12 lines
Thanks
Lukaszdrivers/dma/pl330.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-)drivers/dma/pl330.c +0
-0
drivers/dma/pl330.c struct dma_pl330_chan { · line 569
Quoted 4 lines
drivers/dma/pl330.c +1
-0@@ -566,6 +566,7 @@ struct dma_pl330_chan {/* For D-to-M and M-to-D channels */ int burst_sz;/* the peripheral fifo width */ int burst_len;/* the number of burst */ +int transfered;
This is always set to 0.
Quoted 51 lines
drivers/dma/pl330.c +29
-1dma_addr_t fifo_addr;/* for cyclic capability */ @@ -602,6 +603,9 @@ struct dma_pl330_desc {enum desc_status status; +int bytes_requested; +int direction; +/* The channel which currently holds this desc */ struct dma_pl330_chan *pchan; };@@ -2366,6 +2370,29 @@ static int pl330_alloc_chan_resources(struct dma_chan *chan)return 1 ; } +int pl330_get_current_xferred_count (struct dma_pl330_chan *pch, +struct dma_pl330_desc *desc) +{ +u32 val, addr; +struct pl330_thread *thrd = pch->pl330_chid; +void __iomem *regs = thrd->dmac->pinfo->base; + + val = addr =0 ; +switch (desc->direction) { +case DMA_MEM_TO_DEV : + val =readl (regs +SA (thrd->id)); + addr = desc->px.src_addr; +break ; +case DMA_DEV_TO_MEM : + val =readl (regs +DA (thrd->id)); + addr = desc->px.dst_addr; +break ; +default : +break ; + } +return val - addr; +} +static int pl330_control (struct dma_chan *chan,enum dma_ctrl_cmd cmd,unsigned long arg) {struct dma_pl330_chan *pch =to_pchan (chan);@@ -2446,7 +2473,33 @@ static enum dma_status pl330_tx_status(struct dma_chan *chan, dma_cookie_t cookie, struct dma_tx_state *txstate) { - return dma_cookie_status(chan, cookie, txstate); + enum dma_status ret; +unsigned long flags; +struct dma_pl330_desc *desc;
drivers/dma/pl330.c static enum dma_status · line 2488
Quoted 10 lines
drivers/dma/pl330.c +10
-0+struct dma_pl330_chan *pch =to_pchan (chan); +unsigned int bytes_transferred; +unsigned int residual; + +/* Check in pending list */ +spin_lock_irqsave (&pch->lock, flags); +list_for_each_entry (desc, &pch->work_list, node) { +if (desc->txd.cookie == cookie) { + bytes_transferred = +pl330_get_current_xferred_count (pch, desc);
pl330_get_current_xferred_count() will only return the correct result if it is called for the currently active transfer.
And then there is also the issue that the driver creates multiple internal descriptors for each segment in the transfer. Each of these descriptors gets different cookie. pl330_tx_submit() returns the cookie to the descriptor to the first segment in the transfer. This means if you pass that cookie to pl330_tx_status() you'll only get the residue for the first segment and not for the whole transfer, as it is supposed to be.
drivers/dma/pl330.c static enum dma_status · line 2490
Quoted 2 lines
drivers/dma/pl330.c +2
-0+ residual = desc->bytes_requested - + bytes_transferred % desc->bytes_requested;
If bytes_transferred % desc->bytes_requested != bytes_transferred there is a bug somewhere.
Quoted 14 lines
drivers/dma/pl330.c +12
-0+dma_set_residue (txstate, residual); + ret = desc->status; +spin_unlock_irqrestore (&pch->lock, flags); +return ret; + } + } +spin_unlock_irqrestore (&pch->lock, flags); + + ret =dma_cookie_status (chan, cookie, txstate); +dma_set_residue (txstate, pch->transfered); + +return ret; }
[...]
Quoted 8 lines · Lars-Peter Clausen
Quoted 7 lines · Lukasz Czerwinski
This patch adds possibility to read status of unfinished transfers before termination.
Signed-off-by Lukasz Czerwinski <[email protected]>Signed-off-by Kyungmin Park <[email protected]>---
Quoted 10 lines
Quoted 2 lines
I tested patch with Exynos4 board. This is only proof of concept. Any comments are welcome.
The patch does not look as if it is going to work correctly. And I think that this can't be implemented correctly with the current structure of the driver (at least not without jumping through a couple of hoops). I do have a couple of WIP patches that restructure the driver and then implement residue reporting on top of it.
Quoted 1 line
Thanks for your comments.
I will be waiting for your patch series then I will implement residue reporting in proper way.
br
Lukasz
Quoted 96 lines
Quoted 11 lines
Thanks
Lukaszdrivers/dma/pl330.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-)drivers/dma/pl330.c +0
-0drivers/dma/pl330.c struct dma_pl330_chan { · line 569
Quoted 4 lines
drivers/dma/pl330.c +1
-0@@ -566,6 +566,7 @@ struct dma_pl330_chan {/* For D-to-M and M-to-D channels */ int burst_sz;/* the peripheral fifo width */ int burst_len;/* the number of burst */ +int transfered;This is always set to 0.
Quoted 51 lines
drivers/dma/pl330.c +29
-1dma_addr_t fifo_addr;/* for cyclic capability */ @@ -602,6 +603,9 @@ struct dma_pl330_desc {enum desc_status status; +int bytes_requested; +int direction; +/* The channel which currently holds this desc */ struct dma_pl330_chan *pchan; };@@ -2366,6 +2370,29 @@ static int pl330_alloc_chan_resources(struct dma_chan *chan)return 1 ; } +int pl330_get_current_xferred_count (struct dma_pl330_chan *pch, +struct dma_pl330_desc *desc) +{ +u32 val, addr; +struct pl330_thread *thrd = pch->pl330_chid; +void __iomem *regs = thrd->dmac->pinfo->base; + + val = addr =0 ; +switch (desc->direction) { +case DMA_MEM_TO_DEV : + val =readl (regs +SA (thrd->id)); + addr = desc->px.src_addr; +break ; +case DMA_DEV_TO_MEM : + val =readl (regs +DA (thrd->id)); + addr = desc->px.dst_addr; +break ; +default : +break ; + } +return val - addr; +} +static int pl330_control (struct dma_chan *chan,enum dma_ctrl_cmd cmd,unsigned long arg) {struct dma_pl330_chan *pch =to_pchan (chan);@@ -2446,7 +2473,33 @@ static enum dma_status pl330_tx_status(struct dma_chan *chan, dma_cookie_t cookie, struct dma_tx_state *txstate) { - return dma_cookie_status(chan, cookie, txstate); + enum dma_status ret; +unsigned long flags; +struct dma_pl330_desc *desc;drivers/dma/pl330.c static enum dma_status · line 2488
Quoted 10 lines
drivers/dma/pl330.c +10
-0+struct dma_pl330_chan *pch =to_pchan (chan); +unsigned int bytes_transferred; +unsigned int residual; + +/* Check in pending list */ +spin_lock_irqsave (&pch->lock, flags); +list_for_each_entry (desc, &pch->work_list, node) { +if (desc->txd.cookie == cookie) { + bytes_transferred = +pl330_get_current_xferred_count (pch, desc);
pl330_get_current_xferred_count()will only return the correct result if it is called for the currently active transfer.And then there is also the issue that the driver creates multiple internal descriptors for each segment in the transfer. Each of these descriptors gets different cookie.
pl330_tx_submit()returns the cookie to the descriptor to the first segment in the transfer. This means if you pass that cookie topl330_tx_status()you'll only get the residue for the first segment and not for the whole transfer, as it is supposed to be.drivers/dma/pl330.c static enum dma_status · line 2490
Quoted 2 lines
drivers/dma/pl330.c +2
-0+ residual = desc->bytes_requested - + bytes_transferred % desc->bytes_requested;If
bytes_transferred%desc->bytes_requested!=bytes_transferredthere is a bug somewhere.
Quoted 17 lines
Quoted 4 lines
drivers/dma/pl330.c +4
-0+dma_set_residue (txstate, residual); + ret = desc->status; +spin_unlock_irqrestore (&pch->lock, flags); +return ret;drivers/dma/pl330.c static enum dma_status · line 2504
Quoted 10 lines
drivers/dma/pl330.c +8
-0+ } + } +spin_unlock_irqrestore (&pch->lock, flags); + + ret =dma_cookie_status (chan, cookie, txstate); +dma_set_residue (txstate, pch->transfered); + +return ret; }[...]
.
* English - detected
* Polish
* Polish
<javascript:void(0);>