dmaengine: bcm2835: Fix polling for completion of DMA with interrupts masked.
Subsystems (3)
PATCH 1/1 dmaengine: bcm2835: Fix polling for completion of DMA with interrupts masked.
The tx_status hook is supposed to be safe to call from interrupt context, but it wouldn't ever return completion for the last transfer, meaning you couldn't poll for DMA completion with interrupts masked.
This fixes IRQ handling for bcm2835's DSI1, which requires using the DMA engine to write its registers due to a bug in the AXI bridge.
--- drivers/dma/bcm2835-dma.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
drivers/dma/bcm2835-dma.c +19 -5
@@ -570,16 +570,16 @@ static enum dma_status bcm2835_dma_tx_status(struct dma_chan *chan,struct virt_dma_desc *vd;enum dma_status ret;unsigned long flags; +u32 residue; ret =dma_cookie_status (chan, cookie, txstate); -if (ret ==DMA_COMPLETE || !txstate) +if (ret ==DMA_COMPLETE )return ret;spin_lock_irqsave (&c->vc.lock, flags); vd =vchan_find_desc (&c->vc, cookie);if (vd) { - txstate->residue = -bcm2835_dma_desc_size (to_bcm2835_dma_desc (&vd->tx)); + residue =bcm2835_dma_desc_size (to_bcm2835_dma_desc (&vd->tx)); }else if (c->desc && c->desc->vd.tx.cookie == cookie) {struct bcm2835_desc *d = c->desc;dma_addr_t pos;
@@ -591,11 +591,25 @@ static enum dma_status bcm2835_dma_tx_status(struct dma_chan *chan,else pos =0 ; - txstate->residue =bcm2835_dma_desc_size_pos (d, pos); + residue =bcm2835_dma_desc_size_pos (d, pos); + +/* +* If our non-cyclic transfer is done, then report +* complete and trigger the next tx now. This lets +* the dmaengine API be used synchronously from an IRQ +* handler. +*/ +if (!d->cyclic && residue ==0 ) { +vchan_cookie_complete (&c->desc->vd); +bcm2835_dma_start_desc (c); + ret =dma_cookie_status (chan, cookie, txstate); + } }else { - txstate->residue =0 ; + residue =0 ; } +dma_set_residue (txstate, residue); +spin_unlock_irqrestore (&c->vc.lock, flags);return ret;
Signature · 1 line
2.8.0.rc3
Quoted 3 lines · Eric Anholt
The
tx_statushook is supposed to be safe to call from interrupt context, but it wouldn't ever return completion for the last transfer, meaning you couldn't poll for DMA completion with interrupts masked.
and why is that?
Quoted 13 lines
This fixes IRQ handling for bcm2835's DSI1, which requires using the DMA engine to write its registers due to a bug in the AXI bridge.
Signed-off-by Eric Anholt <[email protected]>--- drivers/dma/bcm2835-dma.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)drivers/dma/bcm2835-dma.c +0
-0
drivers/dma/bcm2835-dma.c static enum dma_status bcm2835_dma_tx_status(struct dma_chan *chan, · line 576
Quoted 8 lines
drivers/dma/bcm2835-dma.c +2
-1@@ -570,16 +570,16 @@ static enum dma_status bcm2835_dma_tx_status(struct dma_chan *chan,struct virt_dma_desc *vd;enum dma_status ret;unsigned long flags; +u32 residue; ret =dma_cookie_status (chan, cookie, txstate); -if (ret ==DMA_COMPLETE || !txstate) +if (ret ==DMA_COMPLETE )
Why do you change this? txstate can be NULL, so no point calculating reside for those cases
Quoted 42 lines
drivers/dma/bcm2835-dma.c +17
-4return ret;spin_lock_irqsave (&c->vc.lock, flags); vd =vchan_find_desc (&c->vc, cookie);if (vd) { - txstate->residue = -bcm2835_dma_desc_size (to_bcm2835_dma_desc (&vd->tx)); + residue =bcm2835_dma_desc_size (to_bcm2835_dma_desc (&vd->tx)); }else if (c->desc && c->desc->vd.tx.cookie == cookie) {struct bcm2835_desc *d = c->desc;dma_addr_t pos;@@ -591,11 +591,25 @@ static enum dma_status bcm2835_dma_tx_status(struct dma_chan *chan,else pos =0 ; - txstate->residue =bcm2835_dma_desc_size_pos (d, pos); + residue =bcm2835_dma_desc_size_pos (d, pos); + +/* +* If our non-cyclic transfer is done, then report +* complete and trigger the next tx now. This lets +* the dmaengine API be used synchronously from an IRQ +* handler. +*/ +if (!d->cyclic && residue ==0 ) { +vchan_cookie_complete (&c->desc->vd); +bcm2835_dma_start_desc (c); + ret =dma_cookie_status (chan, cookie, txstate); + } }else { - txstate->residue =0 ; + residue =0 ; } +dma_set_residue (txstate, residue); +spin_unlock_irqrestore (&c->vc.lock, flags);return ret;Signature · 1 line
2.8.0.rc3
Signature · 1 line
~Vinod
Quoted 6 lines · Vinod Koul
Quoted 3 lines · Eric Anholt
The
tx_statushook is supposed to be safe to call from interrupt context, but it wouldn't ever return completion for the last transfer, meaning you couldn't poll for DMA completion with interrupts masked.and why is that?
Maybe this was poorly worded. How about:
The tx_status hook is supposed to be safe to call from interrupt context. However, the current transfer currently only gets marked complete by the IRQ handler, so if interrupts were masked then polling for completion would never finish.
Quoted 18 lines
Quoted 18 lines
This fixes IRQ handling for bcm2835's DSI1, which requires using the DMA engine to write its registers due to a bug in the AXI bridge.
Signed-off-by Eric Anholt <[email protected]>--- drivers/dma/bcm2835-dma.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)drivers/dma/bcm2835-dma.c +1
-0@@ -570,16 +570,16 @@ static enum dma_status bcm2835_dma_tx_status(struct dma_chan *chan,struct virt_dma_desc *vd;enum dma_status ret;unsigned long flags; +u32 residue;
Quoted 6 lines
drivers/dma/bcm2835-dma.c static enum dma_status bcm2835_dma_tx_status(struct dma_chan *chan, · line 576
Quoted 3 lines
drivers/dma/bcm2835-dma.c +1
-1ret =dma_cookie_status (chan, cookie, txstate); -if (ret ==DMA_COMPLETE || !txstate) +if (ret ==DMA_COMPLETE )Why do you change this? txstate can be NULL, so no point calculating reside for those cases
The point was to go into the "Calculate where we're at in our current
DMA (if the current DMA is the one we're asking about status for)" path,
so that we could note when the DMA is complete even when there's no
txstate passed in.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160606/dfd1d825/attachment.sig>
Quoted 7 lines · Eric Anholt
Quoted 5 lines · Vinod Koul
Quoted 3 lines · Eric Anholt
The
tx_statushook is supposed to be safe to call from interrupt context, but it wouldn't ever return completion for the last transfer, meaning you couldn't poll for DMA completion with interrupts masked.
Quoted 8 lines
Quoted 1 line
and why is that?
Maybe this was poorly worded. How about:
The
tx_statushook is supposed to be safe to call from interrupt context. However, the current transfer currently only gets marked complete by the IRQ handler, so if interrupts were masked then polling for completion would never finish.
Sound better :)
Quoted 26 lines
Quoted 19 lines
Quoted 19 lines
This fixes IRQ handling for bcm2835's DSI1, which requires using the DMA engine to write its registers due to a bug in the AXI bridge.
Signed-off-by Eric Anholt <[email protected]>--- drivers/dma/bcm2835-dma.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)drivers/dma/bcm2835-dma.c +1
-0@@ -570,16 +570,16 @@ static enum dma_status bcm2835_dma_tx_status(struct dma_chan *chan,struct virt_dma_desc *vd;enum dma_status ret;unsigned long flags; +u32 residue;Quoted 6 lines
drivers/dma/bcm2835-dma.c static enum dma_status bcm2835_dma_tx_status(struct dma_chan *chan, · line 576
Quoted 3 lines
drivers/dma/bcm2835-dma.c +1
-1ret =dma_cookie_status (chan, cookie, txstate); -if (ret ==DMA_COMPLETE || !txstate) +if (ret ==DMA_COMPLETE )Why do you change this? txstate can be NULL, so no point calculating reside for those cases
Quoted 4 lines
The point was to go into the "Calculate where we're at in our current DMA (if the current DMA is the one we're asking about status for)" path, so that we could note when the DMA is complete even when there's no txstate passed in.
Can you explain what you mean by current DMA!
The claulation is always done for 'descriptor' represnted by the cookie. So it doesnt not matter...!
Thanks
Signature · 1 line
~Vinod
Quoted 50 lines · Vinod Koul
Quoted 7 lines · Eric Anholt
Quoted 5 lines · Vinod Koul
Quoted 3 lines · Eric Anholt
The
tx_statushook is supposed to be safe to call from interrupt context, but it wouldn't ever return completion for the last transfer, meaning you couldn't poll for DMA completion with interrupts masked.Quoted 8 lines
Quoted 1 line
and why is that?
Maybe this was poorly worded. How about:
The
tx_statushook is supposed to be safe to call from interrupt context. However, the current transfer currently only gets marked complete by the IRQ handler, so if interrupts were masked then polling for completion would never finish.Sound better :)
Quoted 26 lines
Quoted 19 lines
Quoted 19 lines
This fixes IRQ handling for bcm2835's DSI1, which requires using the DMA engine to write its registers due to a bug in the AXI bridge.
Signed-off-by Eric Anholt <[email protected]>--- drivers/dma/bcm2835-dma.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)drivers/dma/bcm2835-dma.c +1
-0@@ -570,16 +570,16 @@ static enum dma_status bcm2835_dma_tx_status(struct dma_chan *chan,struct virt_dma_desc *vd;enum dma_status ret;unsigned long flags; +u32 residue;Quoted 6 lines
drivers/dma/bcm2835-dma.c static enum dma_status bcm2835_dma_tx_status(struct dma_chan *chan, · line 576
Quoted 3 lines
drivers/dma/bcm2835-dma.c +1
-1ret =dma_cookie_status (chan, cookie, txstate); -if (ret ==DMA_COMPLETE || !txstate) +if (ret ==DMA_COMPLETE )Why do you change this? txstate can be NULL, so no point calculating reside for those cases
Quoted 4 lines
The point was to go into the "Calculate where we're at in our current DMA (if the current DMA is the one we're asking about status for)" path, so that we could note when the DMA is complete even when there's no txstate passed in.
Quoted 4 lines
Can you explain what you mean by current DMA!
The claulation is always done for 'descriptor' represnted by the cookie. So it doesnt not matter...!
By current I mean the current descriptor that has been submitted to the
hardware, in bcm2835_chan->desc.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160606/8dc60835/attachment-0001.sig>
Quoted 11 lines · Eric Anholt
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
drivers/dma/bcm2835-dma.c static enum dma_status bcm2835_dma_tx_status(struct dma_chan *chan, · line 576
Quoted 2 lines
drivers/dma/bcm2835-dma.c +1
-1-if (ret ==DMA_COMPLETE || !txstate) +if (ret ==DMA_COMPLETE )Why do you change this? txstate can be NULL, so no point calculating reside for those cases
The point was to go into the "Calculate where we're at in our current DMA (if the current DMA is the one we're asking about status for)" path, so that we could note when the DMA is complete even when there's no txstate passed in.
Quoted 7 lines
Quoted 4 lines
Can you explain what you mean by current DMA!
The claulation is always done for 'descriptor' represnted by the cookie. So it doesnt not matter...!
By current I mean the current descriptor that has been submitted to the hardware, in
bcm2835_chan->desc.
As I said, you calculate for the descriptor respresnted by cookie and not the one getting processed!
Signature · 1 line
~Vinod
Quoted 14 lines · Vinod Koul
Quoted 13 lines · Eric Anholt
Quoted 13 lines
Quoted 10 lines
Quoted 5 lines
drivers/dma/bcm2835-dma.c static enum dma_status bcm2835_dma_tx_status(struct dma_chan *chan, · line 576
Quoted 2 lines
drivers/dma/bcm2835-dma.c +1
-1-if (ret ==DMA_COMPLETE || !txstate) +if (ret ==DMA_COMPLETE )Why do you change this? txstate can be NULL, so no point calculating reside for those cases
The point was to go into the "Calculate where we're at in our current DMA (if the current DMA is the one we're asking about status for)" path, so that we could note when the DMA is complete even when there's no txstate passed in.
Can you explain what you mean by current DMA!
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
The claulation is always done for 'descriptor' represnted by the cookie. So it doesnt not matter...!
By current I mean the current descriptor that has been submitted to the hardware, in
bcm2835_chan->desc.As I said, you calculate for the descriptor respresnted by cookie and not the one getting processed!
I believe I'm calculating the state for the descriptor being processed only in the case where the cookie being asked about is for the descriptor being processed. I'm confused what your objection is, so I'm going to annotate what I think is going on in the function so maybe you can point to where I've got something wrong.
spin_lock_irqsave(&c->vc.lock, flags);
vd = vchan_find_desc(&c->vc, cookie);
if (vd) {
txstate->residue =
bcm2835_dma_desc_size(to_bcm2835_dma_desc(&vd->tx));I believe this is the case for "the descriptor for the cookie being asked about hasn't been pulled off the list and submitted to the hardware yet"
} else if (c->desc && c->desc->vd.tx.cookie == cookie) {
struct bcm2835_desc *d = c->desc;
dma_addr_t pos;
if (d->dir == DMA_MEM_TO_DEV)
pos = readl(c->chan_base + BCM2835_DMA_SOURCE_AD);
else if (d->dir == DMA_DEV_TO_MEM)
pos = readl(c->chan_base + BCM2835_DMA_DEST_AD);
else
pos = 0;
txstate->residue = bcm2835_dma_desc_size_pos(d, pos);Here the descriptor for the cookie is currently being processed by the hardware. It might also be done but hasn't had its done interrupt handled yet, so this is the case where I want to effectively do the done IRQ's work of updating the status.
} else {
txstate->residue = 0;Here, it's not in the hardware and it's not queued to be submitted to the hardware, so it must be done.
}
What am I missing?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160607/b8e28b95/attachment.sig>