A few fixes on imx-sdma
Subsystems (2)
cover A few fixes on imx-sdma
The patch set is to address the concerns discussed on thread below. And it's been tested on mx51 babbage board with sound driver.
"A few questions on imx-sdma"
http://article.gmane.org/gmane.linux.ports.arm.kernel/103001/
Shawn Guo (6)
drivers/dma/imx-sdma.c | 31 +++++++++++++++++++------------ 1 files changed, 19 insertions(+), 12 deletions(-)
[PATCH 1/6] dmaengine: imx-sdma: remove IMX_DMA_SG_LOOP handling in sdma_prep_slave_sg() [PATCH 2/6] dmaengine: imx-sdma: set sdmac->status to DMA_ERROR in err_out of sdma_prep_slave_sg() [PATCH 3/6] dmaengine: imx-sdma: return sdmac->status in sdma_tx_status()
[PATCH 4/6] dmaengine: imxs-sdma: correct sdmac->status in sdma_handle_channel_loop() [PATCH 5/6] dmaengine: imx-sdma: fix up param for the last BD in sdma_prep_slave_sg() [PATCH 6/6] dmaengine: imx-sdma: avoid stopping channel in the middle of a BD transfer
Regards,
Shawn
PATCH 1/6 dmaengine: imx-sdma: remove IMX_DMA_SG_LOOP handling in sdma_prep_slave_sg()
This is a leftover from the time that the driver did not have sdma_prep_dma_cyclic callback and implemented sound dma as a looped sg chain. And it can be removed now.
--- drivers/dma/imx-sdma.c | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-)
drivers/dma/imx-sdma.c +0 -6
@@ -931,12 +931,6 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg( param =BD_DONE |BD_EXTD |BD_CONT ; -if (sdmac->flags &IMX_DMA_SG_LOOP ) { - param |=BD_INTR ; -if (i +1 == sg_len) - param |=BD_WRAP ; - } -if (i +1 == sg_len) param |=BD_INTR ;
Signature · 1 line
1.7.1
PATCH 2/6 dmaengine: imx-sdma: set sdmac->status to DMA_ERROR in err_out of sdma_prep_slave_sg()
In reply to Shawn Guosdma_prep_dma_cyclic() sets sdmac->status to DMA_ERROR in err_out, and sdma_prep_slave_sg() needs to do the same. Otherwise, sdmac->status stays at DMA_IN_PROGRESS, which will make the function return immediately next time it gets called.
--- drivers/dma/imx-sdma.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/dma/imx-sdma.c +1 -0
@@ -947,6 +947,7 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg(return &sdmac->desc; err_out: + sdmac->status =DMA_ERROR ;return NULL ; }
Signature · 1 line
1.7.1
PATCH 3/6 dmaengine: imx-sdma: return sdmac->status in sdma_tx_status()
In reply to Shawn GuoThe sdmac->status was designed to reflect the status of the tx, so simply return it in sdma_tx_status(). Then dma client can call dma_async_is_tx_complete() to know the status of the tx.
--- drivers/dma/imx-sdma.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/dma/imx-sdma.c +1 -3
@@ -1061,14 +1061,12 @@ static enum dma_status sdma_tx_status(struct dma_chan *chan, {struct sdma_channel *sdmac =to_sdma_chan (chan);dma_cookie_t last_used; -enum dma_status ret; last_used = chan->cookie; - ret =dma_async_is_complete (cookie, sdmac->last_completed, last_used);dma_set_tx_state (txstate, sdmac->last_completed, last_used,0 ); -return ret; +return sdmac->status; }static void sdma_issue_pending (struct dma_chan *chan)
Signature · 1 line
1.7.1
PATCH 4/6 dmaengine: imxs-sdma: correct sdmac->status in sdma_handle_channel_loop()
In reply to Shawn Guosdma_handle_channel_loop() is the handler of cyclic tx. One period success does not really mean the success of the tx. Instead of DMA_SUCCESS, DMA_IN_PROGRESS should be the one to tell.
--- drivers/dma/imx-sdma.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/dma/imx-sdma.c +1 -1
@@ -449,7 +449,7 @@ static void sdma_handle_channel_loop(struct sdma_channel *sdmac)if (bd->mode.status &BD_RROR ) sdmac->status =DMA_ERROR ;else - sdmac->status =DMA_SUCCESS ; + sdmac->status =DMA_IN_PROGRESS ; bd->mode.status |=BD_DONE ; sdmac->buf_tail++;
Signature · 1 line
1.7.1
PATCH 5/6 dmaengine: imx-sdma: fix up param for the last BD in sdma_prep_slave_sg()
In reply to Shawn GuoAs per the reference manual, bit "L" should be set while bit "C" should be cleared for the last buffer descriptor in the non-cyclic chain, so that sdma can stop trying to find the next BD and end the transfer.
In case of sdma_prep_slave_sg(), BD_LAST needs to be set and BD_CONT be cleared for the last BD.
--- drivers/dma/imx-sdma.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
drivers/dma/imx-sdma.c +4 -1
@@ -931,8 +931,11 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg( param =BD_DONE |BD_EXTD |BD_CONT ; -if (i +1 == sg_len) +if (i +1 == sg_len) { param |=BD_INTR ; + param |=BD_LAST ; + param &= ~BD_CONT ; + } dev_dbg(sdma->dev, "entry %d: count: %d dma: 0x%08x %s%s\n", i, count, sg->dma_address,
Signature · 1 line
1.7.1
Sascha Hauer
maintainerPATCH 5/6 dmaengine: imx-sdma: fix up param for the last BD in sdma_prep_slave_sg()
Quoted 7 lines · Shawn Guo
As per the reference manual, bit "L" should be set while bit "C" should be cleared for the last buffer descriptor in the non-cyclic chain, so that sdma can stop trying to find the next BD and end the transfer.
In case of
sdma_prep_slave_sg(),BD_LASTneeds to be set andBD_CONTbe cleared for the last BD.
Did you test this patch?
Sascha
Quoted 28 lines
Signed-off-by Shawn Guo <[email protected]>--- drivers/dma/imx-sdma.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)drivers/dma/imx-sdma.c +4
-1@@ -931,8 +931,11 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg( param =BD_DONE |BD_EXTD |BD_CONT ; -if (i +1 == sg_len) +if (i +1 == sg_len) { param |=BD_INTR ; + param |=BD_LAST ; + param &= ~BD_CONT ; + } dev_dbg(sdma->dev, "entry %d: count: %d dma: 0x%08x %s%s\n", i, count, sg->dma_address,Signature · 1 line
1.7.1
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
PATCH 5/6 dmaengine: imx-sdma: fix up param for the last BD in sdma_prep_slave_sg()
Hi Sascha,
Quoted 11 lines · Sascha Hauer
Quoted 7 lines · Shawn Guo
As per the reference manual, bit "L" should be set while bit "C" should be cleared for the last buffer descriptor in the non-cyclic chain, so that sdma can stop trying to find the next BD and end the transfer.
In case of
sdma_prep_slave_sg(),BD_LASTneeds to be set andBD_CONTbe cleared for the last BD.Did you test this patch?
Would you suggest any driver on mx51 using this api? So that I can test it on my babbage board. Or you can help test it with mx27/31 mmc driver? I do not have them on my end. Thanks.
Signature · 2 lines
Regards, Shawn
Quoted 36 lines
Quoted 29 lines
Signed-off-by Shawn Guo <[email protected]>--- drivers/dma/imx-sdma.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)drivers/dma/imx-sdma.c +4
-1@@ -931,8 +931,11 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg( param =BD_DONE |BD_EXTD |BD_CONT ; -if (i +1 == sg_len) +if (i +1 == sg_len) { param |=BD_INTR ; + param |=BD_LAST ; + param &= ~BD_CONT ; + } dev_dbg(sdma->dev, "entry %d: count: %d dma: 0x%08x %s%s\n", i, count, sg->dma_address,Signature · 1 line
1.7.1Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Sascha Hauer
maintainerPATCH 5/6 dmaengine: imx-sdma: fix up param for the last BD in sdma_prep_slave_sg()
Quoted 9 lines · Shawn Guo
Hi Sascha,
Quoted 6 lines · Sascha Hauer
Quoted 5 lines · Shawn Guo
As per the reference manual, bit "L" should be set while bit "C" should be cleared for the last buffer descriptor in the non-cyclic chain, so that sdma can stop trying to find the next BD and end the transfer.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
In case of
sdma_prep_slave_sg(),BD_LASTneeds to be set andBD_CONTbe cleared for the last BD.Did you test this patch?
Would you suggest any driver on mx51 using this api? So that I can test it on my babbage board. Or you can help test it with mx27/31 mmc driver? I do not have them on my end. Thanks.
I can only suggest the imx/imx-sdma-sound-mx353ds-mx51_babbage branch, but this only uses cyclic transfers so you can't use it to test this patch.
I asked because I could add an ack to this patch if it has been tested. Without testing I'd like delaying it until I found some time testing it.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
PATCH 5/6 dmaengine: imx-sdma: fix up param for the last BD in sdma_prep_slave_sg()
Hi Sascha,
Quoted 15 lines · Sascha Hauer
Quoted 14 lines · Shawn Guo
Hi Sascha,
Quoted 11 lines · Sascha Hauer
Quoted 7 lines · Shawn Guo
As per the reference manual, bit "L" should be set while bit "C" should be cleared for the last buffer descriptor in the non-cyclic chain, so that sdma can stop trying to find the next BD and end the transfer.
In case of
sdma_prep_slave_sg(),BD_LASTneeds to be set andBD_CONTbe cleared for the last BD.Did you test this patch?
Quoted 7 lines
Quoted 3 lines
Would you suggest any driver on mx51 using this api? So that I can test it on my babbage board. Or you can help test it with mx27/31 mmc driver? I do not have them on my end. Thanks.
I can only suggest the imx/imx-sdma-sound-mx353ds-mx51_babbage branch, but this only uses cyclic transfers so you can't use it to test this patch.
Yes, I tested the patch set against imx/imx-sdma-sound-mx353ds-mx51_babbage. But the only use of sdma_prep_slave_sg I know is mxcmmc.c that you patched recently. And this driver is for mx27/31 which I do not have the setup.
Quoted 3 lines
I asked because I could add an ack to this patch if it has been tested. Without testing I'd like delaying it until I found some time testing it.
Reasonable. Thanks.
Signature · 2 lines
Regards, Shawn
PATCH 6/6 dmaengine: imx-sdma: avoid stopping channel in the middle of a BD transfer
In reply to Shawn GuoWhen STOP register bit gets set, SDMA hardware will immediately stop the channel once the current burst other than buffer descriptor transfer is done.
* Change sdma_disable_channel() to only set STOP register bit after polling the current BD done, so that the current BD transfer corruption could be avoided.
* Increment buf_tail in mxc_sdma_handle_channel_normal() as well as sdma_handle_channel_loop(), since buf_tail now is used in sdma_disable_channel() which could be called in both sg and cyclic cases.
* Return DMA_SUCCESS other than DMA_ERROR in sdma_disable_channel().
--- drivers/dma/imx-sdma.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
drivers/dma/imx-sdma.c +8 -1
@@ -481,6 +481,8 @@ static void mxc_sdma_handle_channel_normal(struct sdma_channel *sdmac)else sdmac->status =DMA_SUCCESS ; + sdmac->buf_tail++; +if (sdmac->desc.callback) sdmac->desc.callback (sdmac->desc.callback_param); sdmac->last_completed = sdmac->desc.cookie;
@@ -655,9 +657,14 @@ static void sdma_disable_channel(struct sdma_channel *sdmac) {struct sdma_engine *sdma = sdmac->sdma;int channel = sdmac->channel; +struct sdma_buffer_descriptor *bd = &sdmac->bd[sdmac->buf_tail]; + +while (bd->mode.status &BD_DONE ) +cpu_relax ();__raw_writel (1 << channel, sdma->regs +SDMA_H_STATSTOP ); - sdmac->status =DMA_ERROR ; + + sdmac->status =DMA_SUCCESS ; }static int sdma_config_channel (struct sdma_channel *sdmac)
Signature · 1 line
1.7.1
PATCH 6/6 dmaengine: imx-sdma: avoid stopping channel in the middle of a BD transfer
Quoted 37 lines · Shawn Guo
When STOP register bit gets set, SDMA hardware will immediately stop the channel once the current burst other than buffer descriptor transfer is done.
* Change
sdma_disable_channel()to only set STOP register bit after polling the current BD done, so that the current BD transfer corruption could be avoided.* Increment
buf_tailinmxc_sdma_handle_channel_normal()as well assdma_handle_channel_loop(), sincebuf_tailnow is used insdma_disable_channel()which could be called in both sg and cyclic cases.* Return
DMA_SUCCESSother thanDMA_ERRORinsdma_disable_channel().Signed-off-by Shawn Guo <[email protected]>--- drivers/dma/imx-sdma.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)drivers/dma/imx-sdma.c +2
-0@@ -481,6 +481,8 @@ static void mxc_sdma_handle_channel_normal(struct sdma_channel *sdmac)else sdmac->status =DMA_SUCCESS ; + sdmac->buf_tail++; +if (sdmac->desc.callback) sdmac->desc.callback (sdmac->desc.callback_param); sdmac->last_completed = sdmac->desc.cookie;@@ -655,9 +657,14 @@ static void sdma_disable_channel(struct sdma_channel *sdmac) {struct sdma_engine *sdma = sdmac->sdma;int channel = sdmac->channel;
drivers/dma/imx-sdma.c static void sdma_disable_channel(struct sdma_channel *sdmac) · line 668
Quoted 10 lines
drivers/dma/imx-sdma.c +6
-1+struct sdma_buffer_descriptor *bd = &sdmac->bd[sdmac->buf_tail]; + +while (bd->mode.status &BD_DONE ) +cpu_relax ();__raw_writel (1 << channel, sdma->regs +SDMA_H_STATSTOP ); - sdmac->status =DMA_ERROR ; + + sdmac->status =DMA_SUCCESS ; }
Sorry. The patch lost the change as below. Will pick it up in v2.
@@ -658,11 +658,15 @@ static void sdma_disable_channel(struct sdma_channel *sdmac)
struct sdma_engine *sdma = sdmac->sdma;
int channel = sdmac->channel;
struct sdma_buffer_descriptor *bd = &sdmac->bd[sdmac->buf_tail];+ u32 stat = __raw_readl(sdma->regs + SDMA_H_STATSTOP);
- while (bd->mode.status & BD_DONE)
- cpu_relax();
+ /* stop the channel if it's running */
+ if (stat & (1 << channel)) {
+ while (bd->mode.status & BD_DONE)
+ cpu_relax();
- __raw_writel(1 << channel, sdma->regs + SDMA_H_STATSTOP);
+ __raw_writel(1 << channel, sdma->regs + SDMA_H_STATSTOP);
+ }
sdmac->status = DMA_SUCCESS;
}
Quoted 5 lines
drivers/dma/imx-sdma.c +0
-0static int sdma_config_channel (struct sdma_channel *sdmac)Signature · 1 line
1.7.1
Signature · 2 lines
Regards, Shawn
PATCH 6/6 dmaengine: imx-sdma: avoid stopping channel in the middle of a BD transfer
Quoted 59 lines · Shawn Guo
Quoted 37 lines · Shawn Guo
When STOP register bit gets set, SDMA hardware will immediately stop the channel once the current burst other than buffer descriptor transfer is done.
* Change
sdma_disable_channel()to only set STOP register bit after polling the current BD done, so that the current BD transfer corruption could be avoided.* Increment
buf_tailinmxc_sdma_handle_channel_normal()as well assdma_handle_channel_loop(), sincebuf_tailnow is used insdma_disable_channel()which could be called in both sg and cyclic cases.* Return
DMA_SUCCESSother thanDMA_ERRORinsdma_disable_channel().Signed-off-by Shawn Guo <[email protected]>--- drivers/dma/imx-sdma.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)drivers/dma/imx-sdma.c +2
-0@@ -481,6 +481,8 @@ static void mxc_sdma_handle_channel_normal(struct sdma_channel *sdmac)else sdmac->status =DMA_SUCCESS ; + sdmac->buf_tail++; +if (sdmac->desc.callback) sdmac->desc.callback (sdmac->desc.callback_param); sdmac->last_completed = sdmac->desc.cookie;@@ -655,9 +657,14 @@ static void sdma_disable_channel(struct sdma_channel *sdmac) {struct sdma_engine *sdma = sdmac->sdma;int channel = sdmac->channel;drivers/dma/imx-sdma.c static void sdma_disable_channel(struct sdma_channel *sdmac) · line 668
Quoted 10 lines
drivers/dma/imx-sdma.c +6
-1+struct sdma_buffer_descriptor *bd = &sdmac->bd[sdmac->buf_tail]; + +while (bd->mode.status &BD_DONE ) +cpu_relax ();__raw_writel (1 << channel, sdma->regs +SDMA_H_STATSTOP ); - sdmac->status =DMA_ERROR ; + + sdmac->status =DMA_SUCCESS ; }Sorry. The patch lost the change as below. Will pick it up in v2.
(quoted diff) +1
-2@@ -658,11 +658,15 @@ static void sdma_disable_channel(struct sdma_channel *sdmac) struct sdma_engine *sdma = sdmac->sdma; int channel = sdmac->channel; struct sdma_buffer_descriptor *bd = &sdmac->bd[sdmac->buf_tail]; + u32 stat = __raw_readl(sdma->regs + SDMA_H_STATSTOP); - while (bd->mode.status & BD_DONE) - cpu_relax();
Review static void sdma_disable_channel(struct sdma_channel *sdmac) · line 671
Quoted 10 lines
(quoted diff) +6
-1+ /* stop the channel if it's running */ + if (stat & (1 << channel)) { + while (bd->mode.status & BD_DONE) + cpu_relax(); - __raw_writel(1 << channel, sdma->regs + SDMA_H_STATSTOP); + __raw_writel(1 << channel, sdma->regs + SDMA_H_STATSTOP); + } sdmac->status = DMA_SUCCESS;
NAK.
The patches has several problems.
- buf_tail is only used for cyclic transfers, so in case of non cyclic transfers you poll for an arbitrary descriptor being ready.
- Even in cyclic transfers when buf_tail points to the correct descriptor the hardware will immediatly start the next descriptor before you have a chance to set the STATSTOP bit. So you probably will corrupt the next descriptor instead of the current one which makes this patch useless.
- buf_tail is increased in the interrupt handler, so if you happen to disable the channel after the bd is done but before the interrupt handler has increased buf_tail you poll for the wrong bd being ready which again makes this patch useless.
If in non cyclic transfers we want to disable a channel we have our reasons (device error or timeout) and then the data is corrupted anyway, so no reason to poll for a descriptor getting done. Even worse, in case of an device error the descriptor might not get ready at all and we will poll for ever in the loop above.
Cyclic transfers are designed for audio and disabling a channel basically means pausing the stream. When the SDMA engine does not support pausing the stream in hardware, we have to live with the fact that we pick up the stream on the next descriptor resulting in some bytes missing in the resulting audio stream.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
PATCH 6/6 dmaengine: imx-sdma: avoid stopping channel in the middle of a BD transfer
Hi Sascha,
Quoted 6 lines · Sascha Hauer
Quoted 5 lines · Shawn Guo
Quoted 4 lines · Shawn Guo
When STOP register bit gets set, SDMA hardware will immediately stop the channel once the current burst other than buffer descriptor transfer is done.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
* Change
sdma_disable_channel()to only set STOP register bit after polling the current BD done, so that the current BD transfer corruption could be avoided.* Increment
buf_tailinmxc_sdma_handle_channel_normal()as well assdma_handle_channel_loop(), sincebuf_tailnow is used insdma_disable_channel()which could be called in both sg and cyclic cases.
As the commit message tells, buf_tail is now handled by non-cyclic too.
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
* Return
DMA_SUCCESSother thanDMA_ERRORinsdma_disable_channel().Signed-off-by Shawn Guo <[email protected]>--- drivers/dma/imx-sdma.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)drivers/dma/imx-sdma.c +0
-0@@ -481,6 +481,8 @@ static void mxc_sdma_handle_channel_normal(struct sdma_channel *sdmac)else sdmac->status =DMA_SUCCESS ;
Quoted 2 lines
Quoted 2 lines
drivers/dma/imx-sdma.c static void mxc_sdma_handle_channel_normal(struct sdma_channel *sdmac) · line 485
Quoted 2 lines
drivers/dma/imx-sdma.c +2
-0+ sdmac->buf_tail++; +
ditto
Quoted 37 lines
Quoted 37 lines
Quoted 7 lines
drivers/dma/imx-sdma.c +0
-0if (sdmac->desc.callback) sdmac->desc.callback (sdmac->desc.callback_param); sdmac->last_completed = sdmac->desc.cookie;@@ -655,9 +657,14 @@ static void sdma_disable_channel(struct sdma_channel *sdmac) {struct sdma_engine *sdma = sdmac->sdma;int channel = sdmac->channel;drivers/dma/imx-sdma.c static void sdma_disable_channel(struct sdma_channel *sdmac) · line 668
Quoted 10 lines
drivers/dma/imx-sdma.c +6
-1+struct sdma_buffer_descriptor *bd = &sdmac->bd[sdmac->buf_tail]; + +while (bd->mode.status &BD_DONE ) +cpu_relax ();__raw_writel (1 << channel, sdma->regs +SDMA_H_STATSTOP ); - sdmac->status =DMA_ERROR ; + + sdmac->status =DMA_SUCCESS ; }Sorry. The patch lost the change as below. Will pick it up in v2.
(quoted diff) +7
-3@@ -658,11 +658,15 @@ static void sdma_disable_channel(struct sdma_channel *sdmac) struct sdma_engine *sdma = sdmac->sdma; int channel = sdmac->channel; struct sdma_buffer_descriptor *bd = &sdmac->bd[sdmac->buf_tail]; + u32 stat = __raw_readl(sdma->regs + SDMA_H_STATSTOP); - while (bd->mode.status & BD_DONE) - cpu_relax(); + /* stop the channel if it's running */ + if (stat & (1 << channel)) { + while (bd->mode.status & BD_DONE) + cpu_relax(); - __raw_writel(1 << channel, sdma->regs + SDMA_H_STATSTOP); + __raw_writel(1 << channel, sdma->regs + SDMA_H_STATSTOP); + }
Quoted 9 lines
drivers/dma/imx-sdma.c static void mxc_sdma_handle_channel_normal(struct sdma_channel *sdmac) · line 482
Quoted 1 line
drivers/dma/imx-sdma.c +0
-0sdmac->status =DMA_SUCCESS ;NAK.
The patches has several problems.
-
buf_tailis only used for cyclic transfers, so in case of non cyclic transfers you poll for an arbitrary descriptor being ready.
See above.
Quoted 6 lines
- Even in cyclic transfers when
buf_tailpoints to the correct descriptor the hardware will immediatly start the next descriptor before you have a chance to set the STATSTOP bit. So you probably will corrupt the next descriptor instead of the current one which makes this patch useless.
You are right that the buf_tail will not stop immediately until next time it gets looped on. But in any case, polling BD_DONE will not corrupt any descriptor.
Quoted 9 lines
-
buf_tailis increased in the interrupt handler, so if you happen to disable the channel after the bd is done but before the interrupt handler has increasedbuf_tailyou poll for the wrong bd being ready which again makes this patch useless.If in non cyclic transfers we want to disable a channel we have our reasons (device error or timeout) and then the data is corrupted anyway, so no reason to poll for a descriptor getting done. Even worse, in case of an device error the descriptor might not get ready at all and
Hmm, we should polling (BD_DONE | BD_ERROR).
Quoted 3 lines
we will poll for ever in the loop above.
Cyclic transfers are designed for audio and disabling a channel basically means pausing the stream. When the SDMA engine does not
I thought pausing channel is different from disabling channel, or we do not need DMA_PAUSE and DMA_TERMINATE_ALL for dma_ctrl_cmd.
Quoted 1 line
support pausing the stream in hardware, we have to live with the
What about on the fly setting bit "L" of the next descriptor that's not been running? So that SDMA can stop the channel when it gets this descriptor done.
Quoted 3 lines
fact that we pick up the stream on the next descriptor resulting in some bytes missing in the resulting audio stream.
Signature · 2 lines
Regards, Shawn
Sascha Hauer
maintainerPATCH 6/6 dmaengine: imx-sdma: avoid stopping channel in the middle of a BD transfer
Quoted 108 lines · Shawn Guo
Hi Sascha,
Quoted 6 lines · Sascha Hauer
Quoted 5 lines · Shawn Guo
Quoted 4 lines · Shawn Guo
When STOP register bit gets set, SDMA hardware will immediately stop the channel once the current burst other than buffer descriptor transfer is done.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
* Change
sdma_disable_channel()to only set STOP register bit after polling the current BD done, so that the current BD transfer corruption could be avoided.* Increment
buf_tailinmxc_sdma_handle_channel_normal()as well assdma_handle_channel_loop(), sincebuf_tailnow is used insdma_disable_channel()which could be called in both sg and cyclic cases.As the commit message tells,
buf_tailis now handled by non-cyclic too.Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
* Return
DMA_SUCCESSother thanDMA_ERRORinsdma_disable_channel().Signed-off-by Shawn Guo <[email protected]>--- drivers/dma/imx-sdma.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)drivers/dma/imx-sdma.c +0
-0@@ -481,6 +481,8 @@ static void mxc_sdma_handle_channel_normal(struct sdma_channel *sdmac)else sdmac->status =DMA_SUCCESS ;Quoted 2 lines
Quoted 2 lines
drivers/dma/imx-sdma.c static void mxc_sdma_handle_channel_normal(struct sdma_channel *sdmac) · line 485
Quoted 2 lines
drivers/dma/imx-sdma.c +2
-0+ sdmac->buf_tail++; +ditto
Quoted 37 lines
Quoted 37 lines
Quoted 7 lines
drivers/dma/imx-sdma.c +0
-0if (sdmac->desc.callback) sdmac->desc.callback (sdmac->desc.callback_param); sdmac->last_completed = sdmac->desc.cookie;@@ -655,9 +657,14 @@ static void sdma_disable_channel(struct sdma_channel *sdmac) {struct sdma_engine *sdma = sdmac->sdma;int channel = sdmac->channel;drivers/dma/imx-sdma.c static void sdma_disable_channel(struct sdma_channel *sdmac) · line 668
Quoted 10 lines
drivers/dma/imx-sdma.c +6
-1+struct sdma_buffer_descriptor *bd = &sdmac->bd[sdmac->buf_tail]; + +while (bd->mode.status &BD_DONE ) +cpu_relax ();__raw_writel (1 << channel, sdma->regs +SDMA_H_STATSTOP ); - sdmac->status =DMA_ERROR ; + + sdmac->status =DMA_SUCCESS ; }Sorry. The patch lost the change as below. Will pick it up in v2.
(quoted diff) +7
-3@@ -658,11 +658,15 @@ static void sdma_disable_channel(struct sdma_channel *sdmac) struct sdma_engine *sdma = sdmac->sdma; int channel = sdmac->channel; struct sdma_buffer_descriptor *bd = &sdmac->bd[sdmac->buf_tail]; + u32 stat = __raw_readl(sdma->regs + SDMA_H_STATSTOP); - while (bd->mode.status & BD_DONE) - cpu_relax(); + /* stop the channel if it's running */ + if (stat & (1 << channel)) { + while (bd->mode.status & BD_DONE) + cpu_relax(); - __raw_writel(1 << channel, sdma->regs + SDMA_H_STATSTOP); + __raw_writel(1 << channel, sdma->regs + SDMA_H_STATSTOP); + }Quoted 9 lines
drivers/dma/imx-sdma.c static void mxc_sdma_handle_channel_normal(struct sdma_channel *sdmac) · line 482
Quoted 1 line
drivers/dma/imx-sdma.c +0
-0sdmac->status =DMA_SUCCESS ;NAK.
The patches has several problems.
-
buf_tailis only used for cyclic transfers, so in case of non cyclic transfers you poll for an arbitrary descriptor being ready.See above.
Quoted 6 lines
- Even in cyclic transfers when
buf_tailpoints to the correct descriptor the hardware will immediatly start the next descriptor before you have a chance to set the STATSTOP bit. So you probably will corrupt the next descriptor instead of the current one which makes this patch useless.You are right that the
buf_tailwill not stop immediately until next time it gets looped on. But in any case, pollingBD_DONEwill not corrupt any descriptor.Quoted 9 lines
-
buf_tailis increased in the interrupt handler, so if you happen to disable the channel after the bd is done but before the interrupt handler has increasedbuf_tailyou poll for the wrong bd being ready which again makes this patch useless.If in non cyclic transfers we want to disable a channel we have our reasons (device error or timeout) and then the data is corrupted anyway, so no reason to poll for a descriptor getting done. Even worse, in case of an device error the descriptor might not get ready at all and
Quoted 7 lines
Hmm, we should polling (
BD_DONE|BD_ERROR).Quoted 3 lines
we will poll for ever in the loop above.
Cyclic transfers are designed for audio and disabling a channel basically means pausing the stream. When the SDMA engine does notI thought pausing channel is different from disabling channel, or we do not need
DMA_PAUSEandDMA_TERMINATE_ALLfordma_ctrl_cmd.
We currently do not handle DMA_PAUSE and in case of DMA_TERMINATE_ALL we do not care about the data anyway. So just disabling the channel is the best we can do.
Quoted 5 lines
Quoted 2 lines
support pausing the stream in hardware, we have to live with the
What about on the fly setting bit "L" of the next descriptor that's not been running? So that SDMA can stop the channel when it gets this descriptor done.
I think that would be possible, but this should be implemented as DMA_PAUSE and not as DMA_TERMINATE_ALL.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
PATCH 6/6 dmaengine: imx-sdma: avoid stopping channel in the middle of a BD transfer
Hi Sascha,
Quoted 114 lines · Sascha Hauer
Quoted 113 lines · Shawn Guo
Hi Sascha,
Quoted 6 lines · Sascha Hauer
Quoted 5 lines · Shawn Guo
Quoted 4 lines · Shawn Guo
When STOP register bit gets set, SDMA hardware will immediately stop the channel once the current burst other than buffer descriptor transfer is done.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
* Change
sdma_disable_channel()to only set STOP register bit after polling the current BD done, so that the current BD transfer corruption could be avoided.* Increment
buf_tailinmxc_sdma_handle_channel_normal()as well assdma_handle_channel_loop(), sincebuf_tailnow is used insdma_disable_channel()which could be called in both sg and cyclic cases.As the commit message tells,
buf_tailis now handled by non-cyclic too.Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
* Return
DMA_SUCCESSother thanDMA_ERRORinsdma_disable_channel().Signed-off-by Shawn Guo <[email protected]>--- drivers/dma/imx-sdma.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)drivers/dma/imx-sdma.c +0
-0@@ -481,6 +481,8 @@ static void mxc_sdma_handle_channel_normal(struct sdma_channel *sdmac)else sdmac->status =DMA_SUCCESS ;Quoted 2 lines
Quoted 2 lines
drivers/dma/imx-sdma.c static void mxc_sdma_handle_channel_normal(struct sdma_channel *sdmac) · line 485
Quoted 2 lines
drivers/dma/imx-sdma.c +2
-0+ sdmac->buf_tail++; +ditto
Quoted 37 lines
Quoted 37 lines
Quoted 7 lines
drivers/dma/imx-sdma.c +0
-0if (sdmac->desc.callback) sdmac->desc.callback (sdmac->desc.callback_param); sdmac->last_completed = sdmac->desc.cookie;@@ -655,9 +657,14 @@ static void sdma_disable_channel(struct sdma_channel *sdmac) {struct sdma_engine *sdma = sdmac->sdma;int channel = sdmac->channel;drivers/dma/imx-sdma.c static void sdma_disable_channel(struct sdma_channel *sdmac) · line 668
Quoted 10 lines
drivers/dma/imx-sdma.c +6
-1+struct sdma_buffer_descriptor *bd = &sdmac->bd[sdmac->buf_tail]; + +while (bd->mode.status &BD_DONE ) +cpu_relax ();__raw_writel (1 << channel, sdma->regs +SDMA_H_STATSTOP ); - sdmac->status =DMA_ERROR ; + + sdmac->status =DMA_SUCCESS ; }Sorry. The patch lost the change as below. Will pick it up in v2.
(quoted diff) +7
-3@@ -658,11 +658,15 @@ static void sdma_disable_channel(struct sdma_channel *sdmac) struct sdma_engine *sdma = sdmac->sdma; int channel = sdmac->channel; struct sdma_buffer_descriptor *bd = &sdmac->bd[sdmac->buf_tail]; + u32 stat = __raw_readl(sdma->regs + SDMA_H_STATSTOP); - while (bd->mode.status & BD_DONE) - cpu_relax(); + /* stop the channel if it's running */ + if (stat & (1 << channel)) { + while (bd->mode.status & BD_DONE) + cpu_relax(); - __raw_writel(1 << channel, sdma->regs + SDMA_H_STATSTOP); + __raw_writel(1 << channel, sdma->regs + SDMA_H_STATSTOP); + }Quoted 9 lines
drivers/dma/imx-sdma.c static void mxc_sdma_handle_channel_normal(struct sdma_channel *sdmac) · line 482
Quoted 1 line
drivers/dma/imx-sdma.c +0
-0sdmac->status =DMA_SUCCESS ;NAK.
The patches has several problems.
-
buf_tailis only used for cyclic transfers, so in case of non cyclic transfers you poll for an arbitrary descriptor being ready.See above.
Quoted 6 lines
- Even in cyclic transfers when
buf_tailpoints to the correct descriptor the hardware will immediatly start the next descriptor before you have a chance to set the STATSTOP bit. So you probably will corrupt the next descriptor instead of the current one which makes this patch useless.You are right that the
buf_tailwill not stop immediately until next time it gets looped on. But in any case, pollingBD_DONEwill not corrupt any descriptor.Quoted 9 lines
-
buf_tailis increased in the interrupt handler, so if you happen to disable the channel after the bd is done but before the interrupt handler has increasedbuf_tailyou poll for the wrong bd being ready which again makes this patch useless.If in non cyclic transfers we want to disable a channel we have our reasons (device error or timeout) and then the data is corrupted anyway, so no reason to poll for a descriptor getting done. Even worse, in case of an device error the descriptor might not get ready at all and
Hmm, we should polling (
BD_DONE|BD_ERROR).Quoted 3 lines
we will poll for ever in the loop above.
Cyclic transfers are designed for audio and disabling a channel basically means pausing the stream. When the SDMA engine does not
Quoted 7 lines
Quoted 2 lines
I thought pausing channel is different from disabling channel, or we do not need
DMA_PAUSEandDMA_TERMINATE_ALLfordma_ctrl_cmd.We currently do not handle
DMA_PAUSEand in case ofDMA_TERMINATE_ALLwe do not care about the data anyway. So just disabling the channel is the best we can do.
OK. We can drop this patch ...
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
support pausing the stream in hardware, we have to live with the
What about on the fly setting bit "L" of the next descriptor that's not been running? So that SDMA can stop the channel when it gets this descriptor done.
I think that would be possible, but this should be implemented as
DMA_PAUSEand not asDMA_TERMINATE_ALL.
and I will try to add DMA_PAUSE support with a new patch later.
Signature · 2 lines
Regards, Shawn
cover A few fixes on imx-sdma
In reply to Shawn GuoQuoted 6 lines · Shawn Guo
The patch set is to address the concerns discussed on thread below. And it's been tested on mx51 babbage board with sound driver.
"A few questions on imx-sdma"
http://article.gmane.org/gmane.linux.ports.arm.kernel/103001/
Quoted 8 lines
Shawn Guo (6)
drivers/dma/imx-sdma.c | 31 +++++++++++++++++++------------ 1 files changed, 19 insertions(+), 12 deletions(-)[PATCH 1/6] dmaengine: imx-sdma: remove
IMX_DMA_SG_LOOPhandling insdma_prep_slave_sg()[PATCH 2/6] dmaengine: imx-sdma: setsdmac->statustoDMA_ERRORinerr_outofsdma_prep_slave_sg()[PATCH 3/6] dmaengine: imx-sdma: returnsdmac->statusinsdma_tx_status()
[PATCH 4/6] dmaengine: imxs-sdma: correctsdmac->statusinsdma_handle_channel_loop()
^^^^
This will be fixed in v2.
Quoted 3 lines
[PATCH 5/6] dmaengine: imx-sdma: fix up param for the last BD in
sdma_prep_slave_sg()[PATCH 6/6] dmaengine: imx-sdma: avoid stopping channel in the middle of a BD transfer
Signature · 2 lines
Regards, Shawn
Sascha Hauer
maintainercover A few fixes on imx-sdma
In reply to Shawn GuoQuoted 7 lines · Shawn Guo
The patch set is to address the concerns discussed on thread below. And it's been tested on mx51 babbage board with sound driver.
"A few questions on imx-sdma"
http://article.gmane.org/gmane.linux.ports.arm.kernel/103001/Shawn Guo (6)
Quoted 8 lines
drivers/dma/imx-sdma.c | 31 +++++++++++++++++++------------ 1 files changed, 19 insertions(+), 12 deletions(-)[PATCH 1/6] dmaengine: imx-sdma: remove
IMX_DMA_SG_LOOPhandling insdma_prep_slave_sg()[PATCH 2/6] dmaengine: imx-sdma: setsdmac->statustoDMA_ERRORinerr_outofsdma_prep_slave_sg()[PATCH 3/6] dmaengine: imx-sdma: returnsdmac->statusinsdma_tx_status()
[PATCH 4/6] dmaengine: imxs-sdma: correctsdmac->statusinsdma_handle_channel_loop()[PATCH 5/6] dmaengine: imx-sdma: fix up param for the last BD insdma_prep_slave_sg()
Patches 1/6 - 5/6:
Dan,
For your convenience I've set up a branch containing Shawns patches and the ones just posted here:
The following changes since commit 1bae4ce27c9c90344f23c65ea6966c50ffeae2f5:
Linux 2.6.38-rc2 (2011-01-21 19:01:34 -0800)
are available in the git repository at:
git://git.pengutronix.de/git/imx/linux-2.6 dmaengine
Sascha Hauer (11):
dmaengine i.MX sdma: set maximum segment size for our device dmaengine i.MX sdma: check sg entries for valid addresses and lengths dmaengine i.MX SDMA: do not initialize chan_id field dmaengine i.MX SDMA: initialize dma capabilities outside channel loop dmaengine i.MX SDMA: reserve channel 0 by not registering it dmaengine i.MX dma: set maximum segment size for our device dmaengine i.MX dma: check sg entries for valid addresses and lengths dmaengine i.MX DMA: do not initialize chan_id field dmaengine i.MX dma: initialize dma capabilities outside channel loop Merge branch 'dmaengine-sdma' into dmaengine
Merge branch 'dmaengine-shawn' into dmaengine
Shawn Guo (5):
dmaengine: imx-sdma: remove IMX_DMA_SG_LOOP handling in sdma_prep_slave_sg()
dmaengine: imx-sdma: set sdmac->status to DMA_ERROR in err_out of sdma_prep_slave_sg()
dmaengine: imx-sdma: return sdmac->status in sdma_tx_status()
dmaengine: imx-sdma: correct sdmac->status in sdma_handle_channel_loop()
dmaengine: imx-sdma: fix up param for the last BD in sdma_prep_slave_sg()drivers/dma/imx-dma.c | 26 ++++++++++++++-- drivers/dma/imx-sdma.c | 76 ++++++++++++++++++++++++++---------------------- 2 files changed, 63 insertions(+), 39 deletions(-)
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
cover A few fixes on imx-sdma
Quoted 17 lines · Sascha Hauer
Quoted 10 lines · Shawn Guo
The patch set is to address the concerns discussed on thread below. And it's been tested on mx51 babbage board with sound driver.
"A few questions on imx-sdma"
http://article.gmane.org/gmane.linux.ports.arm.kernel/103001/Shawn Guo (6)
?drivers/dma/imx-sdma.c | ? 31 +++++++++++++++++++------------ ?1 files changed, 19 insertions(+), 12 deletions(-)Quoted 5 lines
?[PATCH 1/6] dmaengine: imx-sdma: remove
IMX_DMA_SG_LOOPhandling insdma_prep_slave_sg()?[PATCH 2/6] dmaengine: imx-sdma: setsdmac->statustoDMA_ERRORinerr_outofsdma_prep_slave_sg()?[PATCH 3/6] dmaengine: imx-sdma: returnsdmac->statusinsdma_tx_status()
?[PATCH 4/6] dmaengine: imxs-sdma: correctsdmac->statusinsdma_handle_channel_loop()?[PATCH 5/6] dmaengine: imx-sdma: fix up param for the last BD insdma_prep_slave_sg()
Quoted 8 lines
Patches 1/6 - 5/6:
Acked-by Sascha Hauer <[email protected]>Dan,
For your convenience I've set up a branch containing Shawns patches and the ones just posted here:
Thanks, I'll take this. One nit please try to avoid one-line/subject-only commit messages.
--
Dan