Skip to content

Commit 68d94a8

Browse files
committed
Merge tag 'dmaengine-fix-5.0-rc6' of git://git.infradead.org/users/vkoul/slave-dma
Pull dmaengine fixes from Vinod Koul: - Fix in at_xdmac fr wrongful channel state - Fix for imx driver for wrong callback invocation - Fix to bcm driver for interrupt race & transaction abort. - Fix in dmatest to abort in mapping error * tag 'dmaengine-fix-5.0-rc6' of git://git.infradead.org/users/vkoul/slave-dma: dmaengine: dmatest: Abort test in case of mapping error dmaengine: bcm2835: Fix abort of transactions dmaengine: bcm2835: Fix interrupt race on RT dmaengine: imx-dma: fix wrong callback invoke dmaengine: at_xdmac: Fix wrongfull report of a channel as in use
2 parents aadaa80 + 6454368 commit 68d94a8

File tree

4 files changed

+53
-76
lines changed

4 files changed

+53
-76
lines changed

drivers/dma/at_xdmac.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ struct at_xdmac_chan {
203203
u32 save_cim;
204204
u32 save_cnda;
205205
u32 save_cndc;
206+
u32 irq_status;
206207
unsigned long status;
207208
struct tasklet_struct tasklet;
208209
struct dma_slave_config sconfig;
@@ -1580,24 +1581,24 @@ static void at_xdmac_tasklet(unsigned long data)
15801581
struct at_xdmac_desc *desc;
15811582
u32 error_mask;
15821583

1583-
dev_dbg(chan2dev(&atchan->chan), "%s: status=0x%08lx\n",
1584-
__func__, atchan->status);
1584+
dev_dbg(chan2dev(&atchan->chan), "%s: status=0x%08x\n",
1585+
__func__, atchan->irq_status);
15851586

15861587
error_mask = AT_XDMAC_CIS_RBEIS
15871588
| AT_XDMAC_CIS_WBEIS
15881589
| AT_XDMAC_CIS_ROIS;
15891590

15901591
if (at_xdmac_chan_is_cyclic(atchan)) {
15911592
at_xdmac_handle_cyclic(atchan);
1592-
} else if ((atchan->status & AT_XDMAC_CIS_LIS)
1593-
|| (atchan->status & error_mask)) {
1593+
} else if ((atchan->irq_status & AT_XDMAC_CIS_LIS)
1594+
|| (atchan->irq_status & error_mask)) {
15941595
struct dma_async_tx_descriptor *txd;
15951596

1596-
if (atchan->status & AT_XDMAC_CIS_RBEIS)
1597+
if (atchan->irq_status & AT_XDMAC_CIS_RBEIS)
15971598
dev_err(chan2dev(&atchan->chan), "read bus error!!!");
1598-
if (atchan->status & AT_XDMAC_CIS_WBEIS)
1599+
if (atchan->irq_status & AT_XDMAC_CIS_WBEIS)
15991600
dev_err(chan2dev(&atchan->chan), "write bus error!!!");
1600-
if (atchan->status & AT_XDMAC_CIS_ROIS)
1601+
if (atchan->irq_status & AT_XDMAC_CIS_ROIS)
16011602
dev_err(chan2dev(&atchan->chan), "request overflow error!!!");
16021603

16031604
spin_lock(&atchan->lock);
@@ -1652,7 +1653,7 @@ static irqreturn_t at_xdmac_interrupt(int irq, void *dev_id)
16521653
atchan = &atxdmac->chan[i];
16531654
chan_imr = at_xdmac_chan_read(atchan, AT_XDMAC_CIM);
16541655
chan_status = at_xdmac_chan_read(atchan, AT_XDMAC_CIS);
1655-
atchan->status = chan_status & chan_imr;
1656+
atchan->irq_status = chan_status & chan_imr;
16561657
dev_vdbg(atxdmac->dma.dev,
16571658
"%s: chan%d: imr=0x%x, status=0x%x\n",
16581659
__func__, i, chan_imr, chan_status);
@@ -1666,7 +1667,7 @@ static irqreturn_t at_xdmac_interrupt(int irq, void *dev_id)
16661667
at_xdmac_chan_read(atchan, AT_XDMAC_CDA),
16671668
at_xdmac_chan_read(atchan, AT_XDMAC_CUBC));
16681669

1669-
if (atchan->status & (AT_XDMAC_CIS_RBEIS | AT_XDMAC_CIS_WBEIS))
1670+
if (atchan->irq_status & (AT_XDMAC_CIS_RBEIS | AT_XDMAC_CIS_WBEIS))
16701671
at_xdmac_write(atxdmac, AT_XDMAC_GD, atchan->mask);
16711672

16721673
tasklet_schedule(&atchan->tasklet);

drivers/dma/bcm2835-dma.c

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -406,38 +406,32 @@ static void bcm2835_dma_fill_cb_chain_with_sg(
406406
}
407407
}
408408

409-
static int bcm2835_dma_abort(void __iomem *chan_base)
409+
static int bcm2835_dma_abort(struct bcm2835_chan *c)
410410
{
411-
unsigned long cs;
411+
void __iomem *chan_base = c->chan_base;
412412
long int timeout = 10000;
413413

414-
cs = readl(chan_base + BCM2835_DMA_CS);
415-
if (!(cs & BCM2835_DMA_ACTIVE))
414+
/*
415+
* A zero control block address means the channel is idle.
416+
* (The ACTIVE flag in the CS register is not a reliable indicator.)
417+
*/
418+
if (!readl(chan_base + BCM2835_DMA_ADDR))
416419
return 0;
417420

418421
/* Write 0 to the active bit - Pause the DMA */
419422
writel(0, chan_base + BCM2835_DMA_CS);
420423

421424
/* Wait for any current AXI transfer to complete */
422-
while ((cs & BCM2835_DMA_ISPAUSED) && --timeout) {
425+
while ((readl(chan_base + BCM2835_DMA_CS) &
426+
BCM2835_DMA_WAITING_FOR_WRITES) && --timeout)
423427
cpu_relax();
424-
cs = readl(chan_base + BCM2835_DMA_CS);
425-
}
426428

427-
/* We'll un-pause when we set of our next DMA */
429+
/* Peripheral might be stuck and fail to signal AXI write responses */
428430
if (!timeout)
429-
return -ETIMEDOUT;
430-
431-
if (!(cs & BCM2835_DMA_ACTIVE))
432-
return 0;
433-
434-
/* Terminate the control block chain */
435-
writel(0, chan_base + BCM2835_DMA_NEXTCB);
436-
437-
/* Abort the whole DMA */
438-
writel(BCM2835_DMA_ABORT | BCM2835_DMA_ACTIVE,
439-
chan_base + BCM2835_DMA_CS);
431+
dev_err(c->vc.chan.device->dev,
432+
"failed to complete outstanding writes\n");
440433

434+
writel(BCM2835_DMA_RESET, chan_base + BCM2835_DMA_CS);
441435
return 0;
442436
}
443437

@@ -476,20 +470,23 @@ static irqreturn_t bcm2835_dma_callback(int irq, void *data)
476470

477471
spin_lock_irqsave(&c->vc.lock, flags);
478472

479-
/* Acknowledge interrupt */
480-
writel(BCM2835_DMA_INT, c->chan_base + BCM2835_DMA_CS);
473+
/*
474+
* Clear the INT flag to receive further interrupts. Keep the channel
475+
* active in case the descriptor is cyclic or in case the client has
476+
* already terminated the descriptor and issued a new one. (May happen
477+
* if this IRQ handler is threaded.) If the channel is finished, it
478+
* will remain idle despite the ACTIVE flag being set.
479+
*/
480+
writel(BCM2835_DMA_INT | BCM2835_DMA_ACTIVE,
481+
c->chan_base + BCM2835_DMA_CS);
481482

482483
d = c->desc;
483484

484485
if (d) {
485486
if (d->cyclic) {
486487
/* call the cyclic callback */
487488
vchan_cyclic_callback(&d->vd);
488-
489-
/* Keep the DMA engine running */
490-
writel(BCM2835_DMA_ACTIVE,
491-
c->chan_base + BCM2835_DMA_CS);
492-
} else {
489+
} else if (!readl(c->chan_base + BCM2835_DMA_ADDR)) {
493490
vchan_cookie_complete(&c->desc->vd);
494491
bcm2835_dma_start_desc(c);
495492
}
@@ -779,7 +776,6 @@ static int bcm2835_dma_terminate_all(struct dma_chan *chan)
779776
struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
780777
struct bcm2835_dmadev *d = to_bcm2835_dma_dev(c->vc.chan.device);
781778
unsigned long flags;
782-
int timeout = 10000;
783779
LIST_HEAD(head);
784780

785781
spin_lock_irqsave(&c->vc.lock, flags);
@@ -789,27 +785,11 @@ static int bcm2835_dma_terminate_all(struct dma_chan *chan)
789785
list_del_init(&c->node);
790786
spin_unlock(&d->lock);
791787

792-
/*
793-
* Stop DMA activity: we assume the callback will not be called
794-
* after bcm_dma_abort() returns (even if it does, it will see
795-
* c->desc is NULL and exit.)
796-
*/
788+
/* stop DMA activity */
797789
if (c->desc) {
798790
vchan_terminate_vdesc(&c->desc->vd);
799791
c->desc = NULL;
800-
bcm2835_dma_abort(c->chan_base);
801-
802-
/* Wait for stopping */
803-
while (--timeout) {
804-
if (!(readl(c->chan_base + BCM2835_DMA_CS) &
805-
BCM2835_DMA_ACTIVE))
806-
break;
807-
808-
cpu_relax();
809-
}
810-
811-
if (!timeout)
812-
dev_err(d->ddev.dev, "DMA transfer could not be terminated\n");
792+
bcm2835_dma_abort(c);
813793
}
814794

815795
vchan_get_all_descriptors(&c->vc, &head);

drivers/dma/dmatest.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -711,11 +711,9 @@ static int dmatest_func(void *data)
711711
srcs[i] = um->addr[i] + src_off;
712712
ret = dma_mapping_error(dev->dev, um->addr[i]);
713713
if (ret) {
714-
dmaengine_unmap_put(um);
715714
result("src mapping error", total_tests,
716715
src_off, dst_off, len, ret);
717-
failed_tests++;
718-
continue;
716+
goto error_unmap_continue;
719717
}
720718
um->to_cnt++;
721719
}
@@ -730,11 +728,9 @@ static int dmatest_func(void *data)
730728
DMA_BIDIRECTIONAL);
731729
ret = dma_mapping_error(dev->dev, dsts[i]);
732730
if (ret) {
733-
dmaengine_unmap_put(um);
734731
result("dst mapping error", total_tests,
735732
src_off, dst_off, len, ret);
736-
failed_tests++;
737-
continue;
733+
goto error_unmap_continue;
738734
}
739735
um->bidi_cnt++;
740736
}
@@ -762,12 +758,10 @@ static int dmatest_func(void *data)
762758
}
763759

764760
if (!tx) {
765-
dmaengine_unmap_put(um);
766761
result("prep error", total_tests, src_off,
767762
dst_off, len, ret);
768763
msleep(100);
769-
failed_tests++;
770-
continue;
764+
goto error_unmap_continue;
771765
}
772766

773767
done->done = false;
@@ -776,12 +770,10 @@ static int dmatest_func(void *data)
776770
cookie = tx->tx_submit(tx);
777771

778772
if (dma_submit_error(cookie)) {
779-
dmaengine_unmap_put(um);
780773
result("submit error", total_tests, src_off,
781774
dst_off, len, ret);
782775
msleep(100);
783-
failed_tests++;
784-
continue;
776+
goto error_unmap_continue;
785777
}
786778
dma_async_issue_pending(chan);
787779

@@ -790,22 +782,20 @@ static int dmatest_func(void *data)
790782

791783
status = dma_async_is_tx_complete(chan, cookie, NULL, NULL);
792784

793-
dmaengine_unmap_put(um);
794-
795785
if (!done->done) {
796786
result("test timed out", total_tests, src_off, dst_off,
797787
len, 0);
798-
failed_tests++;
799-
continue;
788+
goto error_unmap_continue;
800789
} else if (status != DMA_COMPLETE) {
801790
result(status == DMA_ERROR ?
802791
"completion error status" :
803792
"completion busy status", total_tests, src_off,
804793
dst_off, len, ret);
805-
failed_tests++;
806-
continue;
794+
goto error_unmap_continue;
807795
}
808796

797+
dmaengine_unmap_put(um);
798+
809799
if (params->noverify) {
810800
verbose_result("test passed", total_tests, src_off,
811801
dst_off, len, 0);
@@ -846,6 +836,12 @@ static int dmatest_func(void *data)
846836
verbose_result("test passed", total_tests, src_off,
847837
dst_off, len, 0);
848838
}
839+
840+
continue;
841+
842+
error_unmap_continue:
843+
dmaengine_unmap_put(um);
844+
failed_tests++;
849845
}
850846
ktime = ktime_sub(ktime_get(), ktime);
851847
ktime = ktime_sub(ktime, comparetime);

drivers/dma/imx-dma.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ static void imxdma_tasklet(unsigned long data)
618618
{
619619
struct imxdma_channel *imxdmac = (void *)data;
620620
struct imxdma_engine *imxdma = imxdmac->imxdma;
621-
struct imxdma_desc *desc;
621+
struct imxdma_desc *desc, *next_desc;
622622
unsigned long flags;
623623

624624
spin_lock_irqsave(&imxdma->lock, flags);
@@ -648,10 +648,10 @@ static void imxdma_tasklet(unsigned long data)
648648
list_move_tail(imxdmac->ld_active.next, &imxdmac->ld_free);
649649

650650
if (!list_empty(&imxdmac->ld_queue)) {
651-
desc = list_first_entry(&imxdmac->ld_queue, struct imxdma_desc,
652-
node);
651+
next_desc = list_first_entry(&imxdmac->ld_queue,
652+
struct imxdma_desc, node);
653653
list_move_tail(imxdmac->ld_queue.next, &imxdmac->ld_active);
654-
if (imxdma_xfer_desc(desc) < 0)
654+
if (imxdma_xfer_desc(next_desc) < 0)
655655
dev_warn(imxdma->dev, "%s: channel: %d couldn't xfer desc\n",
656656
__func__, imxdmac->channel);
657657
}

0 commit comments

Comments
 (0)