Re: [PATCH v2 2/2] dmaengine: dw: fix cyclic transfer callbacks

From: Andy Shevchenko
Date: Mon Jan 11 2016 - 10:03:58 EST


On Mon, 2016-01-11 at 13:04 +0000, Mans Rullgard wrote:
> Cyclic transfer callbacks rely on block completion interrupts which
> were
> disabled in commit ff7b05f29fd4 ("dmaengine/dw_dmac: Don't handle
> block
> interrupts").ÂÂThis re-enables block interrupts so the cyclic
> callbacks
> can work.ÂÂOther transfer types are not affected as they set the
> INT_EN
> bit only on the last block.
>
> Fixes: ff7b05f29fd4 ("dmaengine/dw_dmac: Don't handle block
> interrupts")
> Signed-off-by: Mans Rullgard <mans@xxxxxxxxx>

How did you test that?

>From my understanding the custom stuff that does cyclic interrupts
prepares a set of descriptors per period, which at the end of transfer
will generate XFER interrupt. Next period will go in the same way.

Maybe I missed something.

> ---
> Changes:
> - new patch
> ---
> Âdrivers/dma/dw/core.c | 21 +++++++++++++++------
> Â1 file changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/dma/dw/core.c b/drivers/dma/dw/core.c
> index af2b92f8501e..b92662722404 100644
> --- a/drivers/dma/dw/core.c
> +++ b/drivers/dma/dw/core.c
> @@ -156,6 +156,7 @@ static void dwc_initialize(struct dw_dma_chan
> *dwc)
> Â
> Â /* Enable interrupts */
> Â channel_set_bit(dw, MASK.XFER, dwc->mask);
> + channel_set_bit(dw, MASK.BLOCK, dwc->mask);
> Â channel_set_bit(dw, MASK.ERROR, dwc->mask);
> Â
> Â dwc->initialized = true;
> @@ -536,16 +537,17 @@ EXPORT_SYMBOL(dw_dma_get_dst_addr);
> Â
> Â/* Called with dwc->lock held and all DMAC interrupts disabled */
> Âstatic void dwc_handle_cyclic(struct dw_dma *dw, struct dw_dma_chan
> *dwc,
> - u32 status_err, u32 status_xfer)
> + u32 status_block, u32 status_err, u32 status_xfer)
> Â{
> Â unsigned long flags;
> Â
> - if (dwc->mask) {
> + if (status_block & dwc->mask) {
> Â void (*callback)(void *param);
> Â void *callback_param;
> Â
> Â dev_vdbg(chan2dev(&dwc->chan), "new cyclic period
> llp 0x%08x\n",
> Â channel_readl(dwc, LLP));
> + dma_writel(dw, CLEAR.BLOCK, dwc->mask);
> Â
> Â callback = dwc->cdesc->period_callback;
> Â callback_param = dwc->cdesc->period_callback_param;
> @@ -577,6 +579,7 @@ static void dwc_handle_cyclic(struct dw_dma *dw,
> struct dw_dma_chan *dwc,
> Â channel_writel(dwc, CTL_LO, 0);
> Â channel_writel(dwc, CTL_HI, 0);
> Â
> + dma_writel(dw, CLEAR.BLOCK, dwc->mask);
> Â dma_writel(dw, CLEAR.ERROR, dwc->mask);
> Â dma_writel(dw, CLEAR.XFER, dwc->mask);
> Â
> @@ -593,10 +596,12 @@ static void dw_dma_tasklet(unsigned long data)
> Â{
> Â struct dw_dma *dw = (struct dw_dma *)data;
> Â struct dw_dma_chan *dwc;
> + u32 status_block;
> Â u32 status_xfer;
> Â u32 status_err;
> Â int i;
> Â
> + status_block = dma_readl(dw, RAW.BLOCK);
> Â status_xfer = dma_readl(dw, RAW.XFER);
> Â status_err = dma_readl(dw, RAW.ERROR);
> Â
> @@ -605,7 +610,8 @@ static void dw_dma_tasklet(unsigned long data)
> Â for (i = 0; i < dw->dma.chancnt; i++) {
> Â dwc = &dw->chan[i];
> Â if (test_bit(DW_DMA_IS_CYCLIC, &dwc->flags))
> - dwc_handle_cyclic(dw, dwc, status_err,
> status_xfer);
> + dwc_handle_cyclic(dw, dwc, status_block,
> status_err,
> + status_xfer);
> Â else if (status_err & (1 << i))
> Â dwc_handle_error(dw, dwc);
> Â else if (status_xfer & (1 << i))
> @@ -616,6 +622,7 @@ static void dw_dma_tasklet(unsigned long data)
> Â Â* Re-enable interrupts.
> Â Â*/
> Â channel_set_bit(dw, MASK.XFER, dw->all_chan_mask);
> + channel_set_bit(dw, MASK.BLOCK, dw->all_chan_mask);
> Â channel_set_bit(dw, MASK.ERROR, dw->all_chan_mask);
> Â}
> Â
> @@ -635,6 +642,7 @@ static irqreturn_t dw_dma_interrupt(int irq, void
> *dev_id)
> Â Â* softirq handler.
> Â Â*/
> Â channel_clear_bit(dw, MASK.XFER, dw->all_chan_mask);
> + channel_clear_bit(dw, MASK.BLOCK, dw->all_chan_mask);
> Â channel_clear_bit(dw, MASK.ERROR, dw->all_chan_mask);
> Â
> Â status = dma_readl(dw, STATUS_INT);
> @@ -645,6 +653,7 @@ static irqreturn_t dw_dma_interrupt(int irq, void
> *dev_id)
> Â
> Â /* Try to recover */
> Â channel_clear_bit(dw, MASK.XFER, (1 << 8) - 1);
> + channel_clear_bit(dw, MASK.BLOCK, (1 << 8) - 1);
> Â channel_clear_bit(dw, MASK.SRC_TRAN, (1 << 8) - 1);
> Â channel_clear_bit(dw, MASK.DST_TRAN, (1 << 8) - 1);
> Â channel_clear_bit(dw, MASK.ERROR, (1 << 8) - 1);
> @@ -1111,6 +1120,7 @@ static void dw_dma_off(struct dw_dma *dw)
> Â dma_writel(dw, CFG, 0);
> Â
> Â channel_clear_bit(dw, MASK.XFER, dw->all_chan_mask);
> + channel_clear_bit(dw, MASK.BLOCK, dw->all_chan_mask);
> Â channel_clear_bit(dw, MASK.SRC_TRAN, dw->all_chan_mask);
> Â channel_clear_bit(dw, MASK.DST_TRAN, dw->all_chan_mask);
> Â channel_clear_bit(dw, MASK.ERROR, dw->all_chan_mask);
> @@ -1216,6 +1226,7 @@ static void dwc_free_chan_resources(struct
> dma_chan *chan)
> Â
> Â /* Disable interrupts */
> Â channel_clear_bit(dw, MASK.XFER, dwc->mask);
> + channel_clear_bit(dw, MASK.BLOCK, dwc->mask);
> Â channel_clear_bit(dw, MASK.ERROR, dwc->mask);
> Â
> Â spin_unlock_irqrestore(&dwc->lock, flags);
> @@ -1458,6 +1469,7 @@ void dw_dma_cyclic_free(struct dma_chan *chan)
> Â
> Â dwc_chan_disable(dw, dwc);
> Â
> + dma_writel(dw, CLEAR.BLOCK, dwc->mask);
> Â dma_writel(dw, CLEAR.ERROR, dwc->mask);
> Â dma_writel(dw, CLEAR.XFER, dwc->mask);
> Â
> @@ -1546,9 +1558,6 @@ int dw_dma_probe(struct dw_dma_chip *chip,
> struct dw_dma_platform_data *pdata)
> Â /* Force dma off, just in case */
> Â dw_dma_off(dw);
> Â
> - /* Disable BLOCK interrupts as well */
> - channel_clear_bit(dw, MASK.BLOCK, dw->all_chan_mask);
> -
> Â /* Create a pool of consistent memory blocks for hardware
> descriptors */
> Â dw->desc_pool = dmam_pool_create("dw_dmac_desc_pool", chip-
> >dev,
> Â Âsizeof(struct dw_desc), 4,
> 0);

--
Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
Intel Finland Oy