dmaengine: xilinx_dma: Fixes and optimizations for AXIDMA and MCDMA channel management
Subsystems (2)
v2 cover dmaengine: xilinx_dma: Fixes and optimizations for AXIDMA and MCDMA channel management
This patch series addresses issues and optimizations in the Xilinx AXI DMA and MCDMA drivers:
1. Fix channel idle state management in the interrupt handlers.
2. Enable transfer chaining by removing unnecessary idle restrictions.
3. Optimize control register writes and channel start logic.
Note: The patches in this series were part of following IRQ coalescing series which is under discussion:
https://lore.kernel.org/all/[email protected]/
Changes in V2:
- Apply similar fixes and optimizations to MCDMA as well.
- Expand the 1/3 commit description with when the described issue occurs.
Suraj Gupta (3):
dmaengine: xilinx_dma: Fix channel idle state management in AXIDMA and
MCDMA interrupt handlers
dmaengine: xilinx_dma: Enable transfer chaining for AXIDMA and MCDMA
by removing idle restriction
dmaengine: xilinx_dma: Optimize control register write and channel
start logic for AXIDMA and MCDMA in corresponding start_transfer()
drivers/dma/xilinx/xilinx_dma.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/3 dmaengine: xilinx_dma: Fix channel idle state management in AXIDMA and MCDMA interrupt handlers
Fix a race condition in AXIDMA and MCDMA irq handlers where the channel could be incorrectly marked as idle and attempt spurious transfers when descriptors are still being processed.
The issue occurs when:
1. Multiple descriptors are queued and active.
2. An interrupt fires after completing some descriptors.
3. xilinx_dma_complete_descriptor() moves completed descriptors to done_list.
4. Channel is marked idle and start_transfer() is called even though active_list still contains unprocessed descriptors.
5. This leads to premature transfer attempts and potential descriptor corruption or missed completions.
Only mark the channel as idle and start new transfers when the active list is actually empty, ensuring proper channel state management and avoiding spurious transfer attempts.
--- drivers/dma/xilinx/xilinx_dma.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +8 -4
@@ -1857,8 +1857,10 @@ static irqreturn_t xilinx_mcdma_irq_handler(int irq, void *data)if (status &XILINX_MCDMA_IRQ_IOC_MASK ) {spin_lock (&chan->lock);xilinx_dma_complete_descriptor (chan); - chan->idle = true; - chan->start_transfer (chan); +if (list_empty (&chan->active_list)) { + chan->idle = true; + chan->start_transfer (chan); + }spin_unlock (&chan->lock); }
@@ -1914,8 +1916,10 @@ static irqreturn_t xilinx_dma_irq_handler(int irq, void *data) XILINX_DMA_DMASR_DLY_CNT_IRQ)) {spin_lock (&chan->lock);xilinx_dma_complete_descriptor (chan); - chan->idle = true; - chan->start_transfer (chan); +if (list_empty (&chan->active_list)) { + chan->idle = true; + chan->start_transfer (chan); + }spin_unlock (&chan->lock); }
Signature · 1 line
2.25.1
PATCH v2 3/3 dmaengine: xilinx_dma: Optimize control register write and channel start logic for AXIDMA and MCDMA in corresponding start_transfer()
In reply to Suraj GuptaOptimize AXI DMA control register programming by consolidating coalesce count and delay configuration into a single register write. Previously, the coalesce count was written separately from the delay configuration, resulting in two register writes. Combine these into one write operation to reduce bus overhead.
Additionally, avoid redundant channel starts in xilinx_dma_start_transfer() and xilinx_mcdma_start_transfer() by only calling xilinx_dma_start() when the channel is actually idle.
--- drivers/dma/xilinx/xilinx_dma.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +4 -3
@@ -1561,7 +1561,6 @@ static void xilinx_dma_start_transfer(struct xilinx_dma_chan *chan) reg &= ~XILINX_DMA_CR_COALESCE_MAX ; reg |= chan->desc_pendingcount <<XILINX_DMA_CR_COALESCE_SHIFT ; -dma_ctrl_write (chan,XILINX_DMA_REG_DMACR , reg); }if (chan->has_sg &&list_empty (&chan->active_list))
@@ -1571,7 +1570,8 @@ static void xilinx_dma_start_transfer(struct xilinx_dma_chan *chan) reg |= chan->irq_delay <<XILINX_DMA_CR_DELAY_SHIFT ;dma_ctrl_write (chan,XILINX_DMA_REG_DMACR , reg); -xilinx_dma_start (chan); +if (chan->idle) +xilinx_dma_start (chan);if (chan->err)return ;
@@ -1660,7 +1660,8 @@ static void xilinx_mcdma_start_transfer(struct xilinx_dma_chan *chan) reg |=XILINX_MCDMA_CR_RUNSTOP_MASK ;dma_ctrl_write (chan,XILINX_MCDMA_CHAN_CR_OFFSET (chan->tdest), reg); -xilinx_dma_start (chan); +if (chan->idle) +xilinx_dma_start (chan);if (chan->err)return ;
Signature · 1 line
2.25.1
PATCH v2 2/3 dmaengine: xilinx_dma: Enable transfer chaining for AXIDMA and MCDMA by removing idle restriction
In reply to Suraj GuptaRemove the restrictive idle check in xilinx_dma_start_transfer() and xilinx_mcdma_start_transfer() that prevented new transfers from being queued when the channel was busy.
Additionally, only update the CURDESC register when the channel is running in scatter-gather mode and active list is empty to avoid interfering with transfers already in progress. When the active list contains transfers, the hardware tail pointer extension mechanism handles chaining automatically.
--- drivers/dma/xilinx/xilinx_dma.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +4 -9
@@ -1548,9 +1548,6 @@ static void xilinx_dma_start_transfer(struct xilinx_dma_chan *chan)if (list_empty (&chan->pending_list))return ; -if (!chan->idle) -return ; - head_desc =list_first_entry (&chan->pending_list, struct xilinx_dma_tx_descriptor, node); tail_desc = list_last_entry(&chan->pending_list,
@@ -1567,7 +1564,7 @@ static void xilinx_dma_start_transfer(struct xilinx_dma_chan *chan)dma_ctrl_write (chan,XILINX_DMA_REG_DMACR , reg); } -if (chan->has_sg) +if (chan->has_sg &&list_empty (&chan->active_list))xilinx_write (chan,XILINX_DMA_REG_CURDESC , head_desc->async_tx.phys); reg &= ~XILINX_DMA_CR_DELAY_MAX ;
@@ -1627,9 +1624,6 @@ static void xilinx_mcdma_start_transfer(struct xilinx_dma_chan *chan)if (chan->err)return ; -if (!chan->idle) -return ; -if (list_empty (&chan->pending_list))return ;
@@ -1652,8 +1646,9 @@ static void xilinx_mcdma_start_transfer(struct xilinx_dma_chan *chan)dma_ctrl_write (chan,XILINX_MCDMA_CHAN_CR_OFFSET (chan->tdest), reg);/* Program current descriptor */ -xilinx_write (chan,XILINX_MCDMA_CHAN_CDESC_OFFSET (chan->tdest), - head_desc->async_tx.phys); +if (chan->has_sg &&list_empty (&chan->active_list)) +xilinx_write (chan,XILINX_MCDMA_CHAN_CDESC_OFFSET (chan->tdest), + head_desc->async_tx.phys);/* Program channel enable register */ reg =dma_ctrl_read (chan,XILINX_MCDMA_CHEN_OFFSET );
Signature · 1 line
2.25.1
Re: [PATCH V2 1/3] dmaengine: xilinx_dma: Fix channel idle state management in AXIDMA and MCDMA interrupt handlers
In reply to Suraj GuptaQuoted 14 lines · Suraj Gupta
Fix a race condition in AXIDMA and MCDMA irq handlers where the channel could be incorrectly marked as idle and attempt spurious transfers when descriptors are still being processed.
The issue occurs when:
1. Multiple descriptors are queued and active.
2. An interrupt fires after completing some descriptors.
3.xilinx_dma_complete_descriptor()moves completed descriptors todone_list.
4. Channel is marked idle andstart_transfer()is called even thoughactive_liststill contains unprocessed descriptors.
5. This leads to premature transfer attempts and potential descriptor corruption or missed completions.
Quoted 8 lines
Only mark the channel as idle and start new transfers when the active list is actually empty, ensuring proper channel state management and avoiding spurious transfer attempts.
Signed-off-by Suraj Gupta <[email protected]>Co-developed-by Srinivas Neeli <[email protected]>Signed-off-by Srinivas Neeli <[email protected]>Fixes c0bba3a99f07 ("dmaengine: vdma: Add Support for Xilinx AXI Direct Memory Access Engine")
For the AXIDMA code paths:
Quoted 34 lines
--- drivers/dma/xilinx/xilinx_dma.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)drivers/dma/xilinx/xilinx_dma.c +8
-4@@ -1857,8 +1857,10 @@ static irqreturn_t xilinx_mcdma_irq_handler(int irq, void *data)if (status &XILINX_MCDMA_IRQ_IOC_MASK ) {spin_lock (&chan->lock);xilinx_dma_complete_descriptor (chan); - chan->idle = true; - chan->start_transfer (chan); +if (list_empty (&chan->active_list)) { + chan->idle = true; + chan->start_transfer (chan); + }spin_unlock (&chan->lock); }@@ -1914,8 +1916,10 @@ static irqreturn_t xilinx_dma_irq_handler(int irq, void *data) XILINX_DMA_DMASR_DLY_CNT_IRQ)) {spin_lock (&chan->lock);xilinx_dma_complete_descriptor (chan); - chan->idle = true; - chan->start_transfer (chan); +if (list_empty (&chan->active_list)) { + chan->idle = true; + chan->start_transfer (chan); + }spin_unlock (&chan->lock); }
Re: [PATCH V2 2/3] dmaengine: xilinx_dma: Enable transfer chaining for AXIDMA and MCDMA by removing idle restriction
In reply to Suraj GuptaQuoted 9 lines · Suraj Gupta
Remove the restrictive idle check in
xilinx_dma_start_transfer()andxilinx_mcdma_start_transfer()that prevented new transfers from being queued when the channel was busy.
Additionally, only update the CURDESC register when the channel is running in scatter-gather mode and active list is empty to avoid interfering with transfers already in progress. When the active list contains transfers, the hardware tail pointer extension mechanism handles chaining automatically.
Quoted 3 lines
Signed-off-by Suraj Gupta <[email protected]>Co-developed-by Srinivas Neeli <[email protected]>Signed-off-by Srinivas Neeli <[email protected]>
For the AXIDMA code paths:
Quoted 49 lines
--- drivers/dma/xilinx/xilinx_dma.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)drivers/dma/xilinx/xilinx_dma.c +4
-9@@ -1548,9 +1548,6 @@ static void xilinx_dma_start_transfer(struct xilinx_dma_chan *chan)if (list_empty (&chan->pending_list))return ; -if (!chan->idle) -return ; - head_desc =list_first_entry (&chan->pending_list, struct xilinx_dma_tx_descriptor, node); tail_desc = list_last_entry(&chan->pending_list,@@ -1567,7 +1564,7 @@ static void xilinx_dma_start_transfer(struct xilinx_dma_chan *chan)dma_ctrl_write (chan,XILINX_DMA_REG_DMACR , reg); } -if (chan->has_sg) +if (chan->has_sg &&list_empty (&chan->active_list))xilinx_write (chan,XILINX_DMA_REG_CURDESC , head_desc->async_tx.phys); reg &= ~XILINX_DMA_CR_DELAY_MAX ;@@ -1627,9 +1624,6 @@ static void xilinx_mcdma_start_transfer(struct xilinx_dma_chan *chan)if (chan->err)return ; -if (!chan->idle) -return ; -if (list_empty (&chan->pending_list))return ;@@ -1652,8 +1646,9 @@ static void xilinx_mcdma_start_transfer(struct xilinx_dma_chan *chan)dma_ctrl_write (chan,XILINX_MCDMA_CHAN_CR_OFFSET (chan->tdest), reg);/* Program current descriptor */ -xilinx_write (chan,XILINX_MCDMA_CHAN_CDESC_OFFSET (chan->tdest), - head_desc->async_tx.phys); +if (chan->has_sg &&list_empty (&chan->active_list)) +xilinx_write (chan,XILINX_MCDMA_CHAN_CDESC_OFFSET (chan->tdest), + head_desc->async_tx.phys);/* Program channel enable register */ reg =dma_ctrl_read (chan,XILINX_MCDMA_CHEN_OFFSET );
Re: [PATCH V2 3/3] dmaengine: xilinx_dma: Optimize control register write and channel start logic for AXIDMA and MCDMA in corresponding start_transfer()
In reply to Suraj GuptaQuoted 9 lines · Suraj Gupta
Optimize AXI DMA control register programming by consolidating coalesce count and delay configuration into a single register write. Previously, the coalesce count was written separately from the delay configuration, resulting in two register writes. Combine these into one write operation to reduce bus overhead.
Additionally, avoid redundant channel starts inxilinx_dma_start_transfer()andxilinx_mcdma_start_transfer()by only callingxilinx_dma_start()when the channel is actually idle.
Quoted 3 lines
Signed-off-by Suraj Gupta <[email protected]>Co-developed-by Srinivas Neeli <[email protected]>Signed-off-by Srinivas Neeli <[email protected]>
For the AXIDMA code paths:
Quoted 36 lines
--- drivers/dma/xilinx/xilinx_dma.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/dma/xilinx/xilinx_dma.c +4
-3@@ -1561,7 +1561,6 @@ static void xilinx_dma_start_transfer(struct xilinx_dma_chan *chan) reg &= ~XILINX_DMA_CR_COALESCE_MAX ; reg |= chan->desc_pendingcount <<XILINX_DMA_CR_COALESCE_SHIFT ; -dma_ctrl_write (chan,XILINX_DMA_REG_DMACR , reg); }if (chan->has_sg &&list_empty (&chan->active_list))@@ -1571,7 +1570,8 @@ static void xilinx_dma_start_transfer(struct xilinx_dma_chan *chan) reg |= chan->irq_delay <<XILINX_DMA_CR_DELAY_SHIFT ;dma_ctrl_write (chan,XILINX_DMA_REG_DMACR , reg); -xilinx_dma_start (chan); +if (chan->idle) +xilinx_dma_start (chan);if (chan->err)return ;@@ -1660,7 +1660,8 @@ static void xilinx_mcdma_start_transfer(struct xilinx_dma_chan *chan) reg |=XILINX_MCDMA_CR_RUNSTOP_MASK ;dma_ctrl_write (chan,XILINX_MCDMA_CHAN_CR_OFFSET (chan->tdest), reg); -xilinx_dma_start (chan); +if (chan->idle) +xilinx_dma_start (chan);if (chan->err)return ;