dmaengine: dw-edma: Fixes and interrupt-path groundwork
Subsystems (2)
v5 cover dmaengine: dw-edma: Fixes and interrupt-path groundwork
Hi,
This series collects dw-edma fixes and interrupt-path groundwork, mostly split from v1 of the "Support dynamic LL appends" series.
Apart from minor adjustments to patches 4 and 8 for the new base, the only change is Frank's Reviewed-by tag on patch 2.
v4: https://lore.kernel.org/r/[email protected]/
v3: https://lore.kernel.org/r/[email protected]/
v2: https://lore.kernel.org/r/[email protected]/
(v1: https://lore.kernel.org/r/[email protected]/)
Rebased onto dmaengine/next:
commit 338c853b7c3b ("dmaengine: Constify struct dma_descriptor_metadata_ops")
Best regards,
Koichiro
Koichiro Den (9):
dmaengine: dw-edma: Fix HDMA channel status register access
dmaengine: dw-edma: Terminate all descriptors without callbacks
dmaengine: dw-edma: Serialize abort state updates
dmaengine: dw-edma: Complete descriptors before pausing
dmaengine: dw-edma: Serialize channel state checks
dmaengine: dw-edma: Clear stale requests on termination
dmaengine: dw-edma-pcie: Drop redundant pci_free_irq_vectors()
dmaengine: dw-edma: Snapshot the v0 interrupt status once per handler
pass
dmaengine: dw-edma: Defer channel IRQ handling to workqueue
drivers/dma/dw-edma/dw-edma-core.c | 193 ++++++++++++++++++++++---- drivers/dma/dw-edma/dw-edma-core.h | 11 ++ drivers/dma/dw-edma/dw-edma-pcie.c | 3 - drivers/dma/dw-edma/dw-edma-v0-core.c | 27 ++-- drivers/dma/dw-edma/dw-hdma-v0-core.c | 2 +- 5 files changed, 188 insertions(+), 48 deletions(-)
Signature · 1 line
2.51.0
PATCH v5 1/9 dmaengine: dw-edma: Fix HDMA channel status register access
GET_CH_32() takes the direction before the channel ID, but dw_hdma_v0_core_ch_status() passed them in the opposite order. This can make the status callback read another HDMA channel status register.
Use the same argument order as the other HDMA register accesses.
---
Changes in v5:
- No changes.
drivers/dma/dw-edma/dw-hdma-v0-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/dw-edma/dw-hdma-v0-core.c +1 -1
@@ -90,7 +90,7 @@ static enum dma_status dw_hdma_v0_core_ch_status(struct dw_edma_chan *chan)u32 tmp; tmp =FIELD_GET (HDMA_V0_CH_STATUS_MASK , -GET_CH_32 (dw, chan->id, chan->dir, ch_stat)); +GET_CH_32 (dw, chan->dir, chan->id, ch_stat));if (tmp ==1 )return DMA_IN_PROGRESS ;
Signature · 1 line
2.51.0
PATCH v5 2/9 dmaengine: dw-edma: Terminate all descriptors without callbacks
In reply to Koichiro DenThe DMA Engine client documentation says in the "Terminate APIs" section of Documentation/driver-api/dmaengine/client.rst:
"No callback functions will be called for any incomplete transfers."
dw-edma instead calls vchan_cookie_complete() when a deferred STOP reaches the interrupt handler. This schedules a callback for the active descriptor and leaves other issued or submitted descriptors queued. A late callback after dmaengine_terminate_sync() can dereference client state that has already been freed, while leftover descriptors may later restart into reused buffers or leak.
Move all issued and submitted descriptors to the terminated list whenever termination completes. For a pending STOP, do this from both the DONE and ABORT paths. Complete their cookies in order without scheduling callbacks.
A STOP can remain pending until the running transfer raises an interrupt. Make device_synchronize() wait for such a pending STOP to complete before releasing terminated descriptors. Reuse it from free_chan_resources(), then release the remaining virt-dma resources. Sleep instead of busy-polling while waiting, and warn if the existing timeout expires.
---
Changes in v5:
- Add Frank's Reviewed-by tag.
drivers/dma/dw-edma/dw-edma-core.c | 90 +++++++++++++++++++++++++----- 1 file changed, 76 insertions(+), 14 deletions(-)
drivers/dma/dw-edma/dw-edma-core.c +76 -14
@@ -7,6 +7,7 @@*/ #include <linux/module.h> +#include <linux/delay.h> #include <linux/device.h> #include <linux/kernel.h> #include <linux/dmaengine.h>
@@ -115,6 +116,35 @@ static int dw_edma_start_transfer(struct dw_edma_chan *chan)return 1 ; } +static void dw_edma_terminate_vdesc (struct virt_dma_desc *vd) +{ +list_del (&vd->node); +dma_cookie_complete (&vd->tx); +vchan_terminate_vdesc (vd); +} + +static void dw_edma_terminate_vdesc_list (struct list_head *head) +{ +struct virt_dma_desc *vd, *_vd; + +list_for_each_entry_safe (vd, _vd, head, node) +dw_edma_terminate_vdesc (vd); +} + +/* Must be called with vc.lock held. */ +static void dw_edma_terminate_all_descs (struct dw_edma_chan *chan) +{ +/* +* This order must not be reversed. Cookies are assigned when +* descriptors are submitted, so desc_issued contains older cookies +* than desc_submitted. Completing desc_submitted first could move +* chan->vc.chan.completed_cookie backwards when desc_issued is +* terminated afterwards. +*/ +dw_edma_terminate_vdesc_list (&chan->vc.desc_issued); +dw_edma_terminate_vdesc_list (&chan->vc.desc_submitted); +} +static void dw_edma_device_caps (struct dma_chan *dchan,struct dma_slave_caps *caps) {
@@ -236,20 +266,22 @@ static int dw_edma_device_terminate_all(struct dma_chan *dchan)struct dw_edma_chan *chan =dchan2dw_edma_chan (dchan);int err =0 ; +guard (spinlock_irqsave)(&chan->vc.lock); +if (!chan->configured) { -/* Do nothing */ +dw_edma_terminate_all_descs (chan); }else if (chan->status ==EDMA_ST_PAUSE ) { +dw_edma_terminate_all_descs (chan); chan->status =EDMA_ST_IDLE ; - chan->configured = false; }else if (chan->status ==EDMA_ST_IDLE ) { - chan->configured = false; +dw_edma_terminate_all_descs (chan); }else if (dw_edma_core_ch_status (chan) ==DMA_COMPLETE ) {/* * The channel is in a false BUSY state, probably didn't * receive or lost an interrupt */ +dw_edma_terminate_all_descs (chan); chan->status =EDMA_ST_IDLE ; - chan->configured = false; }else if (chan->request >EDMA_REQ_PAUSE ) { err = -EPERM ; }else {
@@ -587,8 +619,7 @@ static void dw_edma_done_interrupt(struct dw_edma_chan *chan)break ;case EDMA_REQ_STOP : -list_del (&vd->node); -vchan_cookie_complete (vd); +dw_edma_terminate_all_descs (chan); chan->request =EDMA_REQ_NONE ; chan->status =EDMA_ST_IDLE ;break ;
@@ -612,7 +643,9 @@ static void dw_edma_abort_interrupt(struct dw_edma_chan *chan)spin_lock_irqsave (&chan->vc.lock, flags); vd =vchan_next_desc (&chan->vc); -if (vd) { +if (vd && chan->request ==EDMA_REQ_STOP ) { +dw_edma_terminate_all_descs (chan); + }else if (vd) {dw_hdma_set_callback_result (vd,DMA_TRANS_ABORTED );list_del (&vd->node);vchan_cookie_complete (vd);
@@ -770,21 +803,49 @@ static int dw_edma_alloc_chan_resources(struct dma_chan *dchan)return 0 ; } -static void dw_edma_free_chan_resources (struct dma_chan *dchan) +static void dw_edma_wait_termination (struct dma_chan *dchan) { +struct dw_edma_chan *chan =dchan2dw_edma_chan (dchan);unsigned long timeout = jiffies +msecs_to_jiffies (5000 ); -int ret; +bool stopping; +/* +* A STOP may be deferred to a later interrupt while the channel is still +* running. Wait until that handler completes the termination. +*/ while (time_before (jiffies, timeout)) { - ret =dw_edma_device_terminate_all (dchan); -if (!ret) -break ; +scoped_guard (spinlock_irqsave, &chan->vc.lock) + stopping = chan->request == EDMA_REQ_STOP; -if (time_after_eq (jiffies, timeout)) +if (!stopping)return ; -cpu_relax (); +fsleep (1000 ); } + +dev_warn (chan->dw->chip->dev, +"timeout waiting for channel termination\n" ); +} + +static void dw_edma_device_synchronize (struct dma_chan *dchan) +{ +struct dw_edma_chan *chan =dchan2dw_edma_chan (dchan); + +dw_edma_wait_termination (dchan); +vchan_synchronize (&chan->vc); +} + +static void dw_edma_free_chan_resources (struct dma_chan *dchan) +{ +struct dw_edma_chan *chan =dchan2dw_edma_chan (dchan); + +dw_edma_device_terminate_all (dchan); +dw_edma_device_synchronize (dchan); + +scoped_guard (spinlock_irqsave, &chan->vc.lock) + chan->configured = false; + +vchan_free_chan_resources (&chan->vc); }static int dw_edma_channel_setup (struct dw_edma *dw,u32 wr_alloc,u32 rd_alloc)
@@ -883,6 +944,7 @@ static int dw_edma_channel_setup(struct dw_edma *dw, u32 wr_alloc, u32 rd_alloc) dma->device_pause = dw_edma_device_pause; dma->device_resume = dw_edma_device_resume; dma->device_terminate_all = dw_edma_device_terminate_all; + dma->device_synchronize = dw_edma_device_synchronize; dma->device_issue_pending = dw_edma_device_issue_pending; dma->device_tx_status = dw_edma_device_tx_status; dma->device_prep_config_sg = dw_edma_device_prep_config_sg;
Signature · 1 line
2.51.0
PATCH v5 3/9 dmaengine: dw-edma: Serialize abort state updates
In reply to Koichiro Dendw_edma_abort_interrupt() drops vc.lock before changing request and status. issue_pending() can acquire the lock in that small window, observe the old busy state, and skip starting queued descriptors. Then the abort handler overwrites the channel status as idle, leaving the new descriptors stranded for good.
Keep descriptor completion and the state transition in the same critical section.
---
Changes in v5:
- No changes.
drivers/dma/dw-edma/dw-edma-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/dw-edma/dw-edma-core.c +1 -1
@@ -650,9 +650,9 @@ static void dw_edma_abort_interrupt(struct dw_edma_chan *chan)list_del (&vd->node);vchan_cookie_complete (vd); } -spin_unlock_irqrestore (&chan->vc.lock, flags); chan->request =EDMA_REQ_NONE ; chan->status =EDMA_ST_IDLE ; +spin_unlock_irqrestore (&chan->vc.lock, flags); }static void dw_edma_emul_irq_ack (struct irq_data *d)
Signature · 1 line
2.51.0
PATCH v5 4/9 dmaengine: dw-edma: Complete descriptors before pausing
In reply to Koichiro DenIf PAUSE is requested while the final burst of a descriptor is in flight, the DONE interrupt takes the PAUSE path without checking whether the descriptor has been depleted. The depleted descriptor remains on the issued list and the channel enters EDMA_ST_PAUSE.
On resume, dw_edma_start_transfer() can select that depleted descriptor again even though no burst remains, leaving the channel in an invalid busy state.
Check for descriptor completion before acknowledging PAUSE. If there is no work to start on resume, leave the channel idle. Also ignore DONE interrupts while the channel is paused so a stale or repeated interrupt cannot change its state or start queued work.
---
Changes in v5:
- Updated the commit message for the flattened descriptor representation in dmaengine/next.
drivers/dma/dw-edma/dw-edma-core.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/dma/dw-edma/dw-edma-core.c +14 -6
@@ -255,7 +255,8 @@ static int dw_edma_device_resume(struct dma_chan *dchan) err = -EPERM ; }else { chan->status =EDMA_ST_BUSY ; -dw_edma_start_transfer (chan); +if (!dw_edma_start_transfer (chan)) + chan->status =EDMA_ST_IDLE ; }return err;
@@ -601,10 +602,16 @@ static void dw_edma_done_interrupt(struct dw_edma_chan *chan)unsigned long flags;spin_lock_irqsave (&chan->vc.lock, flags); +if (chan->status ==EDMA_ST_PAUSE ) { +spin_unlock_irqrestore (&chan->vc.lock, flags); +return ; + } + vd =vchan_next_desc (&chan->vc);if (vd) {switch (chan->request) {case EDMA_REQ_NONE : +case EDMA_REQ_PAUSE : desc =vd2dw_edma_desc (vd);if (desc->start_burst >= desc->nburst) { dw_hdma_set_callback_result(vd,
@@ -613,6 +620,12 @@ static void dw_edma_done_interrupt(struct dw_edma_chan *chan)vchan_cookie_complete (vd); } +if (chan->request ==EDMA_REQ_PAUSE ) { + chan->request =EDMA_REQ_NONE ; + chan->status =EDMA_ST_PAUSE ; +break ; + } +/* Continue transferring if there are remaining chunks or issued requests. */ chan->status =dw_edma_start_transfer (chan) ?EDMA_ST_BUSY :EDMA_ST_IDLE ;
@@ -624,11 +637,6 @@ static void dw_edma_done_interrupt(struct dw_edma_chan *chan) chan->status =EDMA_ST_IDLE ;break ; -case EDMA_REQ_PAUSE : - chan->request =EDMA_REQ_NONE ; - chan->status =EDMA_ST_PAUSE ; -break ; -default :break ; }
Signature · 1 line
2.51.0
PATCH v5 5/9 dmaengine: dw-edma: Serialize channel state checks
In reply to Koichiro Denpause() and resume() read and update channel state without holding vc.lock, while the interrupt handlers update the same state under it. Take the same lock around those state checks so that request, status, and configured stay consistent.
For example, pause() can observe EDMA_ST_BUSY right before the interrupt handler completes the final descriptor and moves the channel to EDMA_ST_IDLE, and then record EDMA_REQ_PAUSE on an already idle channel. No further interrupt will acknowledge the request, and since issue_pending() requires EDMA_REQ_NONE, the channel is wedged for good: terminate_all() leaves the stale request behind, so even reconfiguring the channel does not recover it.
issue_pending() already runs under vc.lock, but it tests configured before taking it. Move that test under the lock as well, so configured, request, and status are evaluated as one channel-state snapshot.
---
Changes in v5:
- No changes.
drivers/dma/dw-edma/dw-edma-core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/dma/dw-edma/dw-edma-core.c +6 -4
@@ -230,6 +230,8 @@ static int dw_edma_device_pause(struct dma_chan *dchan)struct dw_edma_chan *chan =dchan2dw_edma_chan (dchan);int err =0 ; +guard (spinlock_irqsave)(&chan->vc.lock); +if (!chan->configured) err = -EPERM ;else if (chan->status !=EDMA_ST_BUSY )
@@ -247,6 +249,8 @@ static int dw_edma_device_resume(struct dma_chan *dchan)struct dw_edma_chan *chan =dchan2dw_edma_chan (dchan);int err =0 ; +guard (spinlock_irqsave)(&chan->vc.lock); +if (!chan->configured) { err = -EPERM ; }else if (chan->status !=EDMA_ST_PAUSE ) {
@@ -297,11 +301,9 @@ static void dw_edma_device_issue_pending(struct dma_chan *dchan)struct dw_edma_chan *chan =dchan2dw_edma_chan (dchan);unsigned long flags; -if (!chan->configured) -return ; -spin_lock_irqsave (&chan->vc.lock, flags); -if (vchan_issue_pending (&chan->vc) && chan->request ==EDMA_REQ_NONE && +if (chan->configured &&vchan_issue_pending (&chan->vc) && + chan->request ==EDMA_REQ_NONE && chan->status ==EDMA_ST_IDLE ) { chan->status =EDMA_ST_BUSY ;dw_edma_start_transfer (chan);
Signature · 1 line
2.51.0
PATCH v5 6/9 dmaengine: dw-edma: Clear stale requests on termination
In reply to Koichiro Denterminate_all() can finish immediately when the channel is unconfigured, paused, idle, or already stopped in hardware. A pending PAUSE request can survive these paths and block issue_pending() even after termination.
Clear the request whenever termination leaves the channel idle. A running channel keeps its STOP request until the interrupt handler consumes it.
---
Changes in v5:
- No changes.
drivers/dma/dw-edma/dw-edma-core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/dma/dw-edma/dw-edma-core.c +2 -0
@@ -292,6 +292,8 @@ static int dw_edma_device_terminate_all(struct dma_chan *dchan) }else { chan->request =EDMA_REQ_STOP ; } +if (chan->status ==EDMA_ST_IDLE ) + chan->request =EDMA_REQ_NONE ;return err; }
Signature · 1 line
2.51.0
PATCH v5 7/9 dmaengine: dw-edma-pcie: Drop redundant pci_free_irq_vectors()
In reply to Koichiro Dendw_edma_pcie enables the PCI device with pcim_enable_device(), so IRQ vectors allocated by pci_alloc_irq_vectors() are released by pcim_msi_release() on device release. The driver should not call pci_free_irq_vectors() manually.
Drop the redundant remove-time cleanup and rely on the managed PCI device lifetime instead, as documented by commit 03e4905402ae ("PCI/MSI:
Clarify pci_free_irq_vectors() usage for managed devices").
---
Changes in v5:
- No changes.
drivers/dma/dw-edma/dw-edma-pcie.c | 3 --- 1 file changed, 3 deletions(-)
drivers/dma/dw-edma/dw-edma-pcie.c +0 -3
@@ -555,9 +555,6 @@ static void dw_edma_pcie_remove(struct pci_dev *pdev) err =dw_edma_remove (chip);if (err)pci_warn (pdev,"can't remove device properly: %d\n" , err); - -/* Freeing IRQs */ -pci_free_irq_vectors (pdev); }static const struct pci_device_id dw_edma_pcie_id_table[] = {
Signature · 1 line
2.51.0
PATCH v5 8/9 dmaengine: dw-edma: Snapshot the v0 interrupt status once per handler pass
In reply to Koichiro DenThe v0 interrupt handler reads the interrupt status register twice per invocation, once through the DONE accessor and once through the ABORT accessor, although both fields live in the same 32-bit register. On remote setups (dw-edma-pcie) each read is a non-posted round trip across the PCIe link costing on the order of a microsecond, and with one completion interrupt per element the duplicate adds up. As an example, profiling the R-Car S4 remote path put the handler at ~7us per invocation, dominated by such reads.
Read the register once and derive the DONE and ABORT views from the snapshot. No abort is lost to this because the pass only clears status bits it observed, so an abort raised after the snapshot keeps its status and its own interrupt delivery brings it to the next pass. An abort on an observed channel cannot race the clear either. Software can restart the halted channel only after abort() runs, and abort() is called after dw_edma_v0_core_clear_abort_int().
---
Changes in v5:
- Adapted to the bitmap interrupt masks introduced by commit
64173b6b7609 ("dmaengine: dw-edma: Enable HDMA 64R/W Channels").drivers/dma/dw-edma/dw-edma-v0-core.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)
drivers/dma/dw-edma/dw-edma-v0-core.c +13 -14
@@ -218,18 +218,6 @@ static void dw_edma_v0_core_clear_abort_int(struct dw_edma_chan *chan) FIELD_PREP(EDMA_V0_ABORT_INT_MASK, BIT(chan->id))); } -static u32 dw_edma_v0_core_status_done_int (struct dw_edma *dw,enum dw_edma_dir dir) -{ -return FIELD_GET (EDMA_V0_DONE_INT_MASK , -GET_RW_32 (dw, dir, int_status)); -} - -static u32 dw_edma_v0_core_status_abort_int (struct dw_edma *dw,enum dw_edma_dir dir) -{ -return FIELD_GET (EDMA_V0_ABORT_INT_MASK , -GET_RW_32 (dw, dir, int_status)); -} -static irqreturn_t dw_edma_v0_core_handle_int (struct dw_edma_irq *dw_irq,enum dw_edma_dir dir,dw_edma_handler_t done,dw_edma_handler_t abort)
@@ -240,6 +228,7 @@ dw_edma_v0_core_handle_int(struct dw_edma_irq *dw_irq, enum dw_edma_dir dir,struct dw_edma_chan *chan;unsigned long off;unsigned long *mask; +u32 sts;if (dir ==EDMA_DIR_WRITE ) { total = dw->wr_ch_cnt;
@@ -251,7 +240,17 @@ dw_edma_v0_core_handle_int(struct dw_edma_irq *dw_irq, enum dw_edma_dir dir, mask = dw_irq->rd_mask; } - val =dw_edma_v0_core_status_done_int (dw, dir); +/* +* DONE and ABORT status share one register, and on remote setups +* every read is a non-posted round trip across the PCIe link. Take +* one snapshot and derive both views from it. An abort raised +* after the snapshot is deferred, not lost: only bits observed in +* the snapshot are ever cleared below, so its status remains set and +* triggers another handler pass. +*/ + sts =GET_RW_32 (dw, dir, int_status); + + val =FIELD_GET (EDMA_V0_DONE_INT_MASK , sts); val &= *mask;for_each_set_bit (pos, &val, total) { chan = &dw->chan[pos + off];
@@ -262,7 +261,7 @@ dw_edma_v0_core_handle_int(struct dw_edma_irq *dw_irq, enum dw_edma_dir dir, ret =IRQ_HANDLED ; } - val =dw_edma_v0_core_status_abort_int (dw, dir); + val =FIELD_GET (EDMA_V0_ABORT_INT_MASK , sts); val &= *mask;for_each_set_bit (pos, &val, total) { chan = &dw->chan[pos + off];
Signature · 1 line
2.51.0
PATCH v5 9/9 dmaengine: dw-edma: Defer channel IRQ handling to workqueue
In reply to Koichiro DenOn some SoCs (e.g. R-Car S4) the endpoint-side eDMA raises a single fixed SPI that is hardwired to CPU0 and covers every read and write channel. Handling channel events directly in that hard IRQ context serializes the completion processing of all channels on one CPU:
descriptor recycling and refill, client callbacks (the vchan tasklet runs on the scheduling CPU) and the doorbell writes all funnel through CPU0, while the handler additionally spins on each channel's vc.lock. Especially under heavy multichannel load, this contention becomes a performance bottleneck.
Keep the hard IRQ handler minimal: clear the status, dispatch channel events, and defer per-channel processing to work items. A work item per channel preserves ordering while allowing different channels to run in parallel on any CPU.
---
Changes in v5:
- No changes.
drivers/dma/dw-edma/dw-edma-core.c | 69 +++++++++++++++++++++++++++--- drivers/dma/dw-edma/dw-edma-core.h | 11 +++++ 2 files changed, 75 insertions(+), 5 deletions(-)
drivers/dma/dw-edma/dw-edma-core.c +64 -5
@@ -30,6 +30,11 @@ struct dw_edma_desc *vd2dw_edma_desc(struct virt_dma_desc *vd) return container_of(vd, struct dw_edma_desc, vd); } +enum dw_edma_irq_event { +DW_EDMA_IRQ_DONE =BIT (0 ), +DW_EDMA_IRQ_ABORT =BIT (1 ), +}; +static inline u64 dw_edma_get_pci_address (struct dw_edma_chan *chan,phys_addr_t cpu_addr) {
@@ -667,6 +672,39 @@ static void dw_edma_abort_interrupt(struct dw_edma_chan *chan)spin_unlock_irqrestore (&chan->vc.lock, flags); } +static void dw_edma_irq_work (struct work_struct *work) +{ + struct dw_edma_chan *chan = container_of(work, struct dw_edma_chan, + irq_work); +unsigned int events; + +do { + events =atomic_xchg (&chan->irq_pending,0 ); + +if (events &DW_EDMA_IRQ_DONE ) +dw_edma_done_interrupt (chan); +if (events &DW_EDMA_IRQ_ABORT ) +dw_edma_abort_interrupt (chan); + }while (atomic_read (&chan->irq_pending)); +} + +static void dw_edma_queue_irq_work (struct dw_edma_chan *chan, +enum dw_edma_irq_event event) +{ +atomic_or (event, &chan->irq_pending); +queue_work (chan->dw->wq, &chan->irq_work); +} + +static void dw_edma_done_interrupt_deferred (struct dw_edma_chan *chan) +{ +dw_edma_queue_irq_work (chan,DW_EDMA_IRQ_DONE ); +} + +static void dw_edma_abort_interrupt_deferred (struct dw_edma_chan *chan) +{ +dw_edma_queue_irq_work (chan,DW_EDMA_IRQ_ABORT ); +} +static void dw_edma_emul_irq_ack (struct irq_data *d) {struct dw_edma *dw =irq_data_get_irq_chip_data (d);
@@ -761,8 +799,8 @@ static inline irqreturn_t dw_edma_interrupt_write_inner(int irq, void *data)struct dw_edma_irq *dw_irq = data;return dw_edma_core_handle_int (dw_irq,EDMA_DIR_WRITE , - dw_edma_done_interrupt, - dw_edma_abort_interrupt); + dw_edma_done_interrupt_deferred, + dw_edma_abort_interrupt_deferred); }static inline irqreturn_t dw_edma_interrupt_read_inner (int irq,void *data)
@@ -770,8 +808,8 @@ static inline irqreturn_t dw_edma_interrupt_read_inner(int irq, void *data)struct dw_edma_irq *dw_irq = data;return dw_edma_core_handle_int (dw_irq,EDMA_DIR_READ , - dw_edma_done_interrupt, - dw_edma_abort_interrupt); + dw_edma_done_interrupt_deferred, + dw_edma_abort_interrupt_deferred); }static inline irqreturn_t dw_edma_interrupt_write (int irq,void *data)
@@ -844,6 +882,8 @@ static void dw_edma_device_synchronize(struct dma_chan *dchan)struct dw_edma_chan *chan =dchan2dw_edma_chan (dchan);dw_edma_wait_termination (dchan); +cancel_work_sync (&chan->irq_work); +atomic_set (&chan->irq_pending,0 );vchan_synchronize (&chan->vc); }
@@ -891,6 +931,8 @@ static int dw_edma_channel_setup(struct dw_edma *dw, u32 wr_alloc, u32 rd_alloc) chan->configured = false; chan->request =EDMA_REQ_NONE ; chan->status =EDMA_ST_IDLE ; +INIT_WORK (&chan->irq_work, dw_edma_irq_work); +atomic_set (&chan->irq_pending,0 );if (chan->dir ==EDMA_DIR_WRITE ) chan->ll_region = chip->ll_region_wr[chan->id];
@@ -1112,10 +1154,21 @@ int dw_edma_probe(struct dw_edma_chip *chip)/* Disable eDMA, only to establish the ideal initial conditions */ dw_edma_core_off (dw); +/* +* Deferred IRQ works are queued from the hard IRQ handlers, so the +* workqueue must exist before any IRQ is requested. +*/ + dw->wq =alloc_workqueue ("dw-edma:%s" ,WQ_UNBOUND |WQ_HIGHPRI ,0 , +dev_name (chip->dev)); +if (!dw->wq) +return -ENOMEM ; +/* Request IRQs */ err =dw_edma_irq_request (dw, &wr_alloc, &rd_alloc); -if (err) +if (err) { +destroy_workqueue (dw->wq);return err; + }/* Allocate a dedicated virtual IRQ for interrupt-emulation doorbells */ err =dw_edma_emul_irq_alloc (dw);
@@ -1138,6 +1191,7 @@ int dw_edma_probe(struct dw_edma_chip *chip)for (i = (dw->nr_irqs -1 ); i >=0 ; i--)free_irq (chip->ops->irq_vector (dev, i), &dw->irq[i]);dw_edma_emul_irq_free (dw); +destroy_workqueue (dw->wq);return err; }
@@ -1162,6 +1216,11 @@ int dw_edma_remove(struct dw_edma_chip *chip)free_irq (chip->ops->irq_vector (dev, i), &dw->irq[i]);dw_edma_emul_irq_free (dw); +for (i =0 ; i < dw->wr_ch_cnt + dw->rd_ch_cnt; i++) +cancel_work_sync (&dw->chan[i].irq_work); + +destroy_workqueue (dw->wq); +/* Deregister eDMA device */ dma_async_device_unregister (&dw->dma); list_for_each_entry_safe(chan, _chan, &dw->dma.channels,
drivers/dma/dw-edma/dw-edma-core.h +11 -0
@@ -9,8 +9,10 @@#ifndef _DW_EDMA_CORE_H#define _DW_EDMA_CORE_H +#include <linux/atomic.h> #include <linux/msi.h> #include <linux/dma/edma.h> +#include <linux/workqueue.h> #include "../virt-dma.h"
@@ -80,6 +82,9 @@ struct dw_edma_chan {struct dma_slave_config config;bool non_ll; + +struct work_struct irq_work; +atomic_t irq_pending; };struct dw_edma_irq {
@@ -103,6 +108,12 @@ struct dw_edma {struct dw_edma_chan *chan; +/* +* WQ_HIGHPRI keeps completion processing responsive under heavy load; +* WQ_UNBOUND lets different channels run on different CPUs. +*/ +struct workqueue_struct *wq; +raw_spinlock_t lock;/* Protect v0 shared registers */ struct dw_edma_chip *chip;
Signature · 1 line
2.51.0
Quoted 6 lines · Koichiro Den
This series collects dw-edma fixes and interrupt-path groundwork, mostly split from v1 of the "Support dynamic LL appends" series.
Apart from minor adjustments to patches 4 and 8 for the new base, the only change is Frank's Reviewed-by tag on patch 2.
Quoted 6 lines
v4: https://lore.kernel.org/r/[email protected]/
v3: https://lore.kernel.org/r/[email protected]/
v2: https://lore.kernel.org/r/[email protected]/
(v1: https://lore.kernel.org/r/[email protected]/)[...]
Applied, thanks!
[1/9] dmaengine: dw-edma: Fix HDMA channel status register access
commit: ef1b080e03acc83d5bde841da67036985acd50dc
[2/9] dmaengine: dw-edma: Terminate all descriptors without callbacks
commit: 99109a51efd28c9a661fbfb9469b023c517b31d1
[3/9] dmaengine: dw-edma: Serialize abort state updates
commit: dd80e259f65d932634e26d366570d71669ef6654
[4/9] dmaengine: dw-edma: Complete descriptors before pausing
commit: c154060016a9db2ac889bfdb0a3c1322f9be8ded
[5/9] dmaengine: dw-edma: Serialize channel state checks
commit: f7d1619f3e10c619b62c6cd6d95371b5c526c85a
[6/9] dmaengine: dw-edma: Clear stale requests on termination
commit: c0d9c6275adcca7c0ca5f4270bf88026f9864bd1
[7/9] dmaengine: dw-edma-pcie: Drop redundant pci_free_irq_vectors()
commit: eb4022c1fae2bb029178779bc2b1fe84a9510dbf
[8/9] dmaengine: dw-edma: Snapshot the v0 interrupt status once per handler pass
commit: 5b0a8818fc5237676bdcd9659180e1edf8e943d7
[9/9] dmaengine: dw-edma: Defer channel IRQ handling to workqueue
commit: 35de39e4511f00a87f814b5f0afeb082a8fbc5d7Best regards,
Signature · 1 line
~Vinod