This patch series fixes below bugs in DMA and VDMA IP's
---> Do not start VDMA until frame buffer is processed by the h/w
---> Fix bug in Multi frame sotres handling in VDMA
---> Fix issues w.r.to multi frame descriptors submit with AXI DMA S2MM(recv) Side.
Kedareswara rao Appana (3):
dmaengine: xilinx_dma: Check for channel idle state before submitting
dma descriptor
dmaeninge: xilinx_dma: Fix bug in multiple frame stores scenario in
vdma
dmaengine: xilinx_dma: Fix race condition in the driver for multiple
descriptor scenario
drivers/dma/xilinx/xilinx_dma.c | 185 +++++++++++++++++++++++++---------------
1 file changed, 118 insertions(+), 67 deletions(-)
--
2.1.2
When driver is handling AXI DMA SoftIP
When user submits multiple descriptors back to back on the S2MM(recv)
side with the current driver flow the last buffer descriptor next bd
points to a invalid location resulting the invalid data or errors in the
DMA engine.
This patch fixes this issue by creating a BD Chain during
channel allocation itself and use those BD's.
Signed-off-by: Kedareswara rao Appana <redacted>
---
drivers/dma/xilinx/xilinx_dma.c | 133 +++++++++++++++++++++++++---------------
1 file changed, 83 insertions(+), 50 deletions(-)
@@ -711,16 +734,26 @@ static void xilinx_dma_free_descriptors(struct xilinx_dma_chan *chan)staticvoidxilinx_dma_free_chan_resources(structdma_chan*dchan){structxilinx_dma_chan*chan=to_xilinx_chan(dchan);+unsignedlongflags;dev_dbg(chan->dev,"Free all channel resources.\n");xilinx_dma_free_descriptors(chan);+if(chan->xdev->dma_config->dmatype==XDMA_TYPE_AXIDMA){-xilinx_dma_free_tx_segment(chan,chan->cyclic_seg_v);-xilinx_dma_free_tx_segment(chan,chan->seg_v);+spin_lock_irqsave(&chan->lock,flags);+INIT_LIST_HEAD(&chan->free_seg_list);+spin_unlock_irqrestore(&chan->lock,flags);++/* Free Memory that is allocated for cyclic DMA Mode */+dma_free_coherent(chan->dev,sizeof(*chan->cyclic_seg_v),+chan->cyclic_seg_v,chan->cyclic_seg_p);+}++if(chan->xdev->dma_config->dmatype!=XDMA_TYPE_AXIDMA){+dma_pool_destroy(chan->desc_pool);+chan->desc_pool=NULL;}-dma_pool_destroy(chan->desc_pool);-chan->desc_pool=NULL;}/**
@@ -803,6 +836,7 @@ static void xilinx_dma_do_tasklet(unsigned long data)staticintxilinx_dma_alloc_chan_resources(structdma_chan*dchan){structxilinx_dma_chan*chan=to_xilinx_chan(dchan);+inti;/* Has this channel already been allocated? */if(chan->desc_pool)
@@ -813,11 +847,30 @@ static int xilinx_dma_alloc_chan_resources(struct dma_chan *dchan)*formeetingXilinxVDMAspecificationrequirement.*/if(chan->xdev->dma_config->dmatype==XDMA_TYPE_AXIDMA){-chan->desc_pool=dma_pool_create("xilinx_dma_desc_pool",-chan->dev,-sizeof(structxilinx_axidma_tx_segment),-__alignof__(structxilinx_axidma_tx_segment),-0);+/* Allocate the buffer descriptors. */+chan->seg_v=dma_zalloc_coherent(chan->dev,+sizeof(*chan->seg_v)*+XILINX_DMA_NUM_DESCS,+&chan->seg_p,GFP_KERNEL);+if(!chan->seg_v){+dev_err(chan->dev,+"unable to allocate channel %d descriptors\n",+chan->id);+return-ENOMEM;+}++for(i=0;i<XILINX_DMA_NUM_DESCS;i++){+chan->seg_v[i].hw.next_desc=+lower_32_bits(chan->seg_p+sizeof(*chan->seg_v)*+((i+1)%XILINX_DMA_NUM_DESCS));+chan->seg_v[i].hw.next_desc_msb=+upper_32_bits(chan->seg_p+sizeof(*chan->seg_v)*+((i+1)%XILINX_DMA_NUM_DESCS));+chan->seg_v[i].phys=chan->seg_p++sizeof(*chan->seg_v)*i;+list_add_tail(&chan->seg_v[i].node,+&chan->free_seg_list);+}}elseif(chan->xdev->dma_config->dmatype==XDMA_TYPE_CDMA){chan->desc_pool=dma_pool_create("xilinx_cdma_desc_pool",chan->dev,
@@ -832,7 +885,8 @@ static int xilinx_dma_alloc_chan_resources(struct dma_chan *dchan)0);}-if(!chan->desc_pool){+if(!chan->desc_pool&&+(chan->xdev->dma_config->dmatype!=XDMA_TYPE_AXIDMA)){dev_err(chan->dev,"unable to allocate channel %d descriptor pool\n",chan->id);
@@ -841,22 +895,20 @@ static int xilinx_dma_alloc_chan_resources(struct dma_chan *dchan)if(chan->xdev->dma_config->dmatype==XDMA_TYPE_AXIDMA){/*-*ForAXIDMAcaseaftersubmittingapending_list,keep-*anextrasegmentallocatedsothatthe"next descriptor"-*pointeronthetaildescriptoralwayspointstoa-*validdescriptor,evenwhenpausedafterreachingtaildesc.-*Thisway,itispossibletoissueadditional-*transferswithouthaltingandrestartingthechannel.-*/-chan->seg_v=xilinx_axidma_alloc_tx_segment(chan);--/**ForcyclicDMAmodeweneedtoprogramthetailDescriptor*registerwithavaluewhichisnotapartoftheBDchain*soallocatingadescsegmentduringchannelallocationfor*programmingtaildescriptor.*/-chan->cyclic_seg_v=xilinx_axidma_alloc_tx_segment(chan);+chan->cyclic_seg_v=dma_zalloc_coherent(chan->dev,+sizeof(*chan->cyclic_seg_v),+&chan->cyclic_seg_p,GFP_KERNEL);+if(!chan->cyclic_seg_v){+dev_err(chan->dev,+"unable to allocate desc segment for cyclic DMA\n");+return-ENOMEM;+}+chan->cyclic_seg_v->phys=chan->cyclic_seg_p;}dma_cookie_init(dchan);
@@ -1806,7 +1839,6 @@ static struct dma_async_tx_descriptor *xilinx_dma_prep_slave_sg(segment=list_first_entry(&desc->segments,structxilinx_axidma_tx_segment,node);desc->async_tx.phys=segment->phys;-prev->hw.next_desc=segment->phys;/* For the last DMA_MEM_TO_DEV transfer, set EOP */if(chan->direction==DMA_MEM_TO_DEV){
@@ -2350,6 +2382,7 @@ static int xilinx_dma_chan_probe(struct xilinx_dma_device *xdev,INIT_LIST_HEAD(&chan->pending_list);INIT_LIST_HEAD(&chan->done_list);INIT_LIST_HEAD(&chan->active_list);+INIT_LIST_HEAD(&chan->free_seg_list);/* Retrieve the channel properties from the device tree */has_dre=of_property_read_bool(node,"xlnx,include-dre");
When VDMA is configured for more than one frame in the h/w
for example h/w is configured for n number of frames and user
Submits n number of frames and triggered the DMA using issue_pending API.
In the current driver flow we are submitting one frame at a time
but we should submit all the n number of frames at one time as the h/w
Is configured for n number of frames.
This patch fixes this issue.
Signed-off-by: Kedareswara rao Appana <redacted>
---
drivers/dma/xilinx/xilinx_dma.c | 43 +++++++++++++++++++++++++----------------
1 file changed, 26 insertions(+), 17 deletions(-)
From: Jose Abreu <Jose.Abreu@synopsys.com> Date: 2016-12-15 15:46:05
Hi Kedar,
On 15-12-2016 15:11, Kedareswara rao Appana wrote:
quoted hunk
Add channel idle state to ensure that dma descriptor is not
submitted when VDMA engine is in progress.
Signed-off-by: Kedareswara rao Appana <redacted>
---
drivers/dma/xilinx/xilinx_dma.c | 9 +++++++++
1 file changed, 9 insertions(+)
@@ -2327,6 +2335,7 @@ static int xilinx_dma_chan_probe(struct xilinx_dma_device *xdev,chan->has_sg=xdev->has_sg;chan->desc_pendingcount=0x0;chan->ext_addr=xdev->ext_addr;+chan->idle=true;spin_lock_init(&chan->lock);INIT_LIST_HEAD(&chan->pending_list);
I think there is missing a set to true in idle when a channel
reset is performed.
Otherwise: Reviewed-by: Jose Abreu [off-list ref]
Best regards,
Jose Miguel Abreu
Add channel idle state to ensure that dma descriptor is not
submitted when VDMA engine is in progress.
Signed-off-by: Kedareswara rao Appana <redacted>
---
drivers/dma/xilinx/xilinx_dma.c | 9 +++++++++
1 file changed, 9 insertions(+)
From: Jose Abreu <Jose.Abreu@synopsys.com> Date: 2016-12-15 16:11:14
Hi Kedar,
On 15-12-2016 15:11, Kedareswara rao Appana wrote:
quoted hunk
When VDMA is configured for more than one frame in the h/w
for example h/w is configured for n number of frames and user
Submits n number of frames and triggered the DMA using issue_pending API.
In the current driver flow we are submitting one frame at a time
but we should submit all the n number of frames at one time as the h/w
Is configured for n number of frames.
This patch fixes this issue.
Signed-off-by: Kedareswara rao Appana <redacted>
---
drivers/dma/xilinx/xilinx_dma.c | 43 +++++++++++++++++++++++++----------------
1 file changed, 26 insertions(+), 17 deletions(-)
But if i is non zero and pending_list has more than num_frms then
i will not wrap-around as it should and will write to invalid
framebuffer location, right?
quoted hunk
+ if (list_empty(&chan->pending_list))+ break;+ desc = list_first_entry(&chan->pending_list,+ struct xilinx_dma_tx_descriptor,+ node); } if (!last)
Maybe a check that all framebuffers contain valid addresses
should be done before programming vsize so that VDMA does not try
to write to invalid addresses.
But if i is non zero and pending_list has more than num_frms then i will not
wrap-around as it should and will write to invalid framebuffer location, right?
Yep will fix in v2...
If (if (list_empty(&chan->pending_list)) || (i == chan->num_frms)
break;
Above condition is sufficient right???
quoted
+ if (list_empty(&chan->pending_list))+ break;+ desc = list_first_entry(&chan->pending_list,+ struct
Maybe a check that all framebuffers contain valid addresses should be done
before programming vsize so that VDMA does not try to write to invalid
addresses.
Do we really need to check for valid address???
I didn't get you what to do you mean by invalid address could you please explain???
In the driver we are reading form the pending_list which will be updated by pep_interleaved_dma
Call so we are under assumption that user sends the proper address right???
"desc_submitcount >= chan->num_frms would be safer here.
Sure will fix in v2...
Regards,
Kedar.
quoted
} else {
Best regards,
Jose Miguel Abreu
--
To unsubscribe from this list: send the line "unsubscribe dmaengine" in the body
of a message to majordomo at vger.kernel.org More majordomo info at
http://vger.kernel.org/majordomo-info.html
Hmm, is it possible to submit more than one segment? If so, then i and j will get
out of sync.
If h/w is configured for more than 1 frame buffer and user submits more than one frame buffer
We can submit more than one frame/ segment to hw right??
I'm not sure. When I used VDMA driver I always submitted only one
segment and multiple descriptors. But the problem is, for example:
If you have:
descriptor1 (2 segments)
descriptor2 (2 segments)
And you have 3 frame buffers in the HW.
Then:
1st frame buffer will have: descriptor1 -> segment1
2nd frame buffer will have: descriptor1 -> segment2
3rd frame buffer will have: descriptor2 -> segment1
but, 4th frame buffer will have: descriptor2 -> segment2 <----
INVALID because there is only 3 frame buffers
So, maybe a check inside the loop "list_for_each_entry(segment,
&desc->segments, node)" could be a nice to have.
But if i is non zero and pending_list has more than num_frms then i will not
wrap-around as it should and will write to invalid framebuffer location, right?
Yep will fix in v2...
If (if (list_empty(&chan->pending_list)) || (i == chan->num_frms)
break;
Above condition is sufficient right???
Looks ok.
quoted
quoted
+ if (list_empty(&chan->pending_list))+ break;+ desc = list_first_entry(&chan->pending_list,+ struct
Maybe a check that all framebuffers contain valid addresses should be done
before programming vsize so that VDMA does not try to write to invalid
addresses.
Do we really need to check for valid address???
I didn't get you what to do you mean by invalid address could you please explain???
In the driver we are reading form the pending_list which will be updated by pep_interleaved_dma
Call so we are under assumption that user sends the proper address right???
What I mean by valid address is to check that i variable has
already been incremented by num_frms at least once since a VDMA
reset. This way you know that you have programmed all the
addresses of the frame buffers with an address and they are non-zero.
Best regards,
Jose Miguel Abreu
"desc_submitcount >= chan->num_frms would be safer here.
Sure will fix in v2...
Regards,
Kedar.
quoted
quoted
} else {
Best regards,
Jose Miguel Abreu
--
To unsubscribe from this list: send the line "unsubscribe dmaengine" in the body
of a message to majordomo at vger.kernel.org More majordomo info at
http://vger.kernel.org/majordomo-info.html
Hi Kedareswara,
Thank you for the patch.
On Thursday 15 Dec 2016 20:41:20 Kedareswara rao Appana wrote:
quoted hunk
Add channel idle state to ensure that dma descriptor is not
submitted when VDMA engine is in progress.
Signed-off-by: Kedareswara rao Appana <redacted>
---
drivers/dma/xilinx/xilinx_dma.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/dma/xilinx/xilinx_dma.c
b/drivers/dma/xilinx/xilinx_dma.c index 8288fe4..736c2a3 100644
xilinx_dma_chan *chan)
if (chan->err)
return;
+ if (!chan->idle)
+ return;
Don't you need to perform the same check for the DMA and CDMA channels ? If
so, shouldn't this be moved to common code ?
There's another problem (not strictly introduced by this patch) I wanted to
mention. The append_desc_queue() function, called from your tx_submit handler,
appends descriptors to the pending_list. The DMA engine API states that a
transfer submitted by tx_submit will not be executed until .issue_pending() is
called. However, if a transfer is in progress at tx_submit time, I believe
that the IRQ handler, at transfer completion, will start the next transfer
from the pending_list even if .issue_pending() hasn't been called for it.
if (list_empty(&chan->pending_list))
return;
Now that you catch busy channels with a software flag, do you still need the
xilinx_dma_is_running() and xilinx_dma_is_idle() checks ? Three different
checks for the same or very similar conditions are confusing, if you really
need them you should document clearly how they differ.
Hi Kedareswara,
Thank you for the patch.
On Thursday 15 Dec 2016 20:41:21 Kedareswara rao Appana wrote:
quoted hunk
When VDMA is configured for more than one frame in the h/w
for example h/w is configured for n number of frames and user
Submits n number of frames and triggered the DMA using issue_pending API.
In the current driver flow we are submitting one frame at a time
but we should submit all the n number of frames at one time as the h/w
Is configured for n number of frames.
This patch fixes this issue.
Signed-off-by: Kedareswara rao Appana <redacted>
---
drivers/dma/xilinx/xilinx_dma.c | 43 ++++++++++++++++++++++----------------
1 file changed, 26 insertions(+), 17 deletions(-)
diff --git a/drivers/dma/xilinx/xilinx_dma.c
b/drivers/dma/xilinx/xilinx_dma.c index 736c2a3..4f3fa94 100644
xilinx_dma_chan *chan)
tail_segment->phys);
} else {
struct xilinx_vdma_tx_segment *segment, *last = NULL;
- int i = 0;
+ int i = 0, j = 0;
if (chan->desc_submitcount < chan->num_frms)
i = chan->desc_submitcount;
I don't get this. i seems to index into a segment start address array, but
gets initialized with a variable documented as "Descriptor h/w submitted
count". I'm not familiar with the hardware, but it makes no sense to me.
I assume the size of the start address array to be limited by the hardware,
but I don't see how this code prevents from overflowing this.
The whole function is very difficult to understand, it probably requires a
rewrite.
quoted hunk
+ last = segment;+ }+ list_del(&desc->node);+ list_add_tail(&desc->node, &chan->active_list);+ j++;+ if (list_empty(&chan->pending_list))+ break;+ desc = list_first_entry(&chan->pending_list,+ struct
While at it, can you merge this into the previous if (chan->has_sg) { ... }
else { ... } ? Having them separate is confusing.
--
Regards,
Laurent Pinchart
+ int i = 0, j = 0; if (chan->desc_submitcount < chan->num_frms) i = chan->desc_submitcount;
I don't get this. i seems to index into a segment start address array, but gets
initialized with a variable documented as "Descriptor h/w submitted count". I'm
not familiar with the hardware, but it makes no sense to me.
Here i is the h/w buffer address.
For ex: If the h/w is configured for 3 frame buffers and user submits 4 desc's
Then we need to submit only 3 frame buffers to the h/w and the next desc will be submitted
After there is a room for buffers I mean when the free buffer is available.
I assume the size of the start address array to be limited by the hardware, but I
don't see how this code prevents from overflowing this.
The whole function is very difficult to understand, it probably requires a rewrite.
Will fix it in v2...
quoted
+ last = segment;+ }+ list_del(&desc->node);+ list_add_tail(&desc->node, &chan->active_list);+ j++;+ if (list_empty(&chan->pending_list))+ break;+ desc = list_first_entry(&chan->pending_list,+ struct
Don't you need to perform the same check for the DMA and CDMA channels ? If
so, shouldn't this be moved to common code ?
Will fix it in v2...
There's another problem (not strictly introduced by this patch) I wanted to
mention. The append_desc_queue() function, called from your tx_submit
handler, appends descriptors to the pending_list. The DMA engine API states
that a transfer submitted by tx_submit will not be executed until .issue_pending()
is called. However, if a transfer is in progress at tx_submit time, I believe that
the IRQ handler, at transfer completion, will start the next transfer from the
pending_list even if .issue_pending() hasn't been called for it.
quoted
if (list_empty(&chan->pending_list))
return;
If user submits more than h/w limit then that case only driver will process
The descriptors from the pending_list for other cases the pending_list will be
Empty so driver just returns from there.
Now that you catch busy channels with a software flag, do you still need the
xilinx_dma_is_running() and xilinx_dma_is_idle() checks ? Three different checks
for the same or very similar conditions are confusing, if you really need them
you should document clearly how they differ.
Will remove the xilinx_dma_is_running and xilinx_dmais_idle() checks and will use
Chan->idle check across all the IP's. Will fix it v2...
Hmm, is it possible to submit more than one segment? If so, then i
and j will get out of sync.
If h/w is configured for more than 1 frame buffer and user submits
more than one frame buffer We can submit more than one frame/ segment to
hw right??
I'm not sure. When I used VDMA driver I always submitted only one segment and
multiple descriptors. But the problem is, for example:
If you have:
descriptor1 (2 segments)
descriptor2 (2 segments)
And you have 3 frame buffers in the HW.
Then:
1st frame buffer will have: descriptor1 -> segment1 2nd frame buffer will have:
descriptor1 -> segment2 3rd frame buffer will have: descriptor2 -> segment1
but, 4th frame buffer will have: descriptor2 -> segment2 <---- INVALID because
there is only 3 frame buffers
So, maybe a check inside the loop "list_for_each_entry(segment, &desc-
quoted
segments, node)" could be a nice to have.
With the current driver flow user can submit only 1 segment per descriptor
That's why didn't checked the list_for_each_entry for each descriptors...
Hope it clarifies your query...
Maybe a check that all framebuffers contain valid addresses should be
done before programming vsize so that VDMA does not try to write to
invalid addresses.
Do we really need to check for valid address???
I didn't get you what to do you mean by invalid address could you please
explain???
quoted
In the driver we are reading form the pending_list which will be
updated by pep_interleaved_dma Call so we are under assumption that user
sends the proper address right???
What I mean by valid address is to check that i variable has already been
incremented by num_frms at least once since a VDMA reset. This way you know
that you have programmed all the addresses of the frame buffers with an
address and they are non-zero.
Hi Kedar,
On Monday 19 Dec 2016 15:39:43 Appana Durga Kedareswara Rao wrote:
Hi Laurent Pinchart,
Thanks for the review...
quoted
quoted
+ if (!chan->idle)
+ return;
Don't you need to perform the same check for the DMA and CDMA channels ?
If so, shouldn't this be moved to common code ?
Will fix it in v2...
quoted
There's another problem (not strictly introduced by this patch) I wanted
to mention. The append_desc_queue() function, called from your tx_submit
handler, appends descriptors to the pending_list. The DMA engine API
states that a transfer submitted by tx_submit will not be executed until
.issue_pending() is called. However, if a transfer is in progress at
tx_submit time, I believe that the IRQ handler, at transfer completion,
will start the next transfer from the pending_list even if
.issue_pending() hasn't been called for it.
quoted
if (list_empty(&chan->pending_list))
return;
If user submits more than h/w limit then that case only driver will process
The descriptors from the pending_list for other cases the pending_list will
be Empty so driver just returns from there.
I understand that, but that's not the problem. Your .tx_submit() handler calls
append_desc_queue() which adds the tx descriptor to the pending_list. If a
transfer is in progress at that time, I believe the transfer completion IRQ
handler will take the next descriptor from the pending_list and process it,
even though issue_pending() hasn't been called for it.
quoted
Now that you catch busy channels with a software flag, do you still need
the xilinx_dma_is_running() and xilinx_dma_is_idle() checks ? Three
different checks for the same or very similar conditions are confusing,
if you really need them you should document clearly how they differ.
Will remove the xilinx_dma_is_running and xilinx_dmais_idle() checks and
will use Chan->idle check across all the IP's. Will fix it v2...
Hi Laurent Pinchart,
Sorry for the delay in the reply.
Thanks for the review...
Hi Kedar,
On Monday 19 Dec 2016 15:39:43 Appana Durga Kedareswara Rao wrote:
quoted
Hi Laurent Pinchart,
Thanks for the review...
quoted
quoted
+ if (!chan->idle)
+ return;
Don't you need to perform the same check for the DMA and CDMA channels
?
quoted
quoted
If so, shouldn't this be moved to common code ?
Will fix it in v2...
quoted
There's another problem (not strictly introduced by this patch) I
wanted to mention. The append_desc_queue() function, called from
your tx_submit handler, appends descriptors to the pending_list. The
DMA engine API states that a transfer submitted by tx_submit will
not be executed until
.issue_pending() is called. However, if a transfer is in progress at
tx_submit time, I believe that the IRQ handler, at transfer
completion, will start the next transfer from the pending_list even
if
.issue_pending() hasn't been called for it.
quoted
if (list_empty(&chan->pending_list))
return;
If user submits more than h/w limit then that case only driver will
process The descriptors from the pending_list for other cases the
pending_list will be Empty so driver just returns from there.
I understand that, but that's not the problem. Your .tx_submit() handler calls
append_desc_queue() which adds the tx descriptor to the pending_list. If a
transfer is in progress at that time, I believe the transfer completion IRQ handler
will take the next descriptor from the pending_list and process it, even though
issue_pending() hasn't been called for it.
Thanks for the explanation...
Agree will keep this my to-do list...
Regards,
Kedar.