dmaengine: provide a common function for completing a dma descriptor
authorRussell King - ARM Linux <linux@arm.linux.org.uk>
Tue, 6 Mar 2012 22:35:07 +0000 (22:35 +0000)
committerVinod Koul <vinod.koul@linux.intel.com>
Tue, 13 Mar 2012 06:07:01 +0000 (11:37 +0530)
Provide a common function to do the cookie mechanics for completing
a DMA descriptor.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Tested-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Jassi Brar <jassisinghbrar@gmail.com>
[imx-sdma.c & mxs-dma.c]
Tested-by: Shawn Guo <shawn.guo@linaro.org>
Signed-off-by: Vinod Koul <vinod.koul@linux.intel.com>
19 files changed:
drivers/dma/amba-pl08x.c
drivers/dma/at_hdmac.c
drivers/dma/coh901318.c
drivers/dma/dmaengine.h
drivers/dma/dw_dmac.c
drivers/dma/ep93xx_dma.c
drivers/dma/fsldma.c
drivers/dma/imx-dma.c
drivers/dma/imx-sdma.c
drivers/dma/intel_mid_dma.c
drivers/dma/ioat/dma.c
drivers/dma/ioat/dma_v2.c
drivers/dma/ioat/dma_v3.c
drivers/dma/ipu/ipu_idmac.c
drivers/dma/mxs-dma.c
drivers/dma/pl330.c
drivers/dma/ste_dma40.c
drivers/dma/timb_dma.c
drivers/dma/txx9dmac.c

index d8d3dc273f29f391933fc09266e483ff41c5d349..346327572cfba76c0211605b25079c6f919b8c21 100644 (file)
@@ -1542,7 +1542,7 @@ static void pl08x_tasklet(unsigned long data)
 
        if (txd) {
                /* Update last completed */
-               plchan->chan.completed_cookie = txd->tx.cookie;
+               dma_cookie_complete(&txd->tx);
        }
 
        /* If a new descriptor is queued, set it up plchan->at is NULL here */
index df47e7d6164bae85df47f3e04cab0f797f018507..b2826304da2491a99df030ea7c76234c45044720 100644 (file)
@@ -249,7 +249,7 @@ atc_chain_complete(struct at_dma_chan *atchan, struct at_desc *desc)
        dev_vdbg(chan2dev(&atchan->chan_common),
                "descriptor %u complete\n", txd->cookie);
 
-       atchan->chan_common.completed_cookie = txd->cookie;
+       dma_cookie_complete(txd);
 
        /* move children to free_list */
        list_splice_init(&desc->tx_list, &atchan->free_list);
index 843a1a3b8a8155be0ef16105ef723611ad004279..24837d700951c1b22c5595b116bc34f27911bf69 100644 (file)
@@ -691,7 +691,7 @@ static void dma_tasklet(unsigned long data)
        callback_param = cohd_fin->desc.callback_param;
 
        /* sign this job as completed on the channel */
-       cohc->chan.completed_cookie = cohd_fin->desc.cookie;
+       dma_cookie_complete(&cohd_fin->desc);
 
        /* release the lli allocation and remove the descriptor */
        coh901318_lli_free(&cohc->base->pool, &cohd_fin->lli);
index 7692c864404539ea61bcc26fcf2a4bf59516bfeb..47e099772b8e84d9ee42727df9188ab33266be5e 100644 (file)
@@ -5,6 +5,7 @@
 #ifndef DMAENGINE_H
 #define DMAENGINE_H
 
+#include <linux/bug.h>
 #include <linux/dmaengine.h>
 
 /**
@@ -27,4 +28,21 @@ static inline dma_cookie_t dma_cookie_assign(struct dma_async_tx_descriptor *tx)
        return cookie;
 }
 
+/**
+ * dma_cookie_complete - complete a descriptor
+ * @tx: descriptor to complete
+ *
+ * Mark this descriptor complete by updating the channels completed
+ * cookie marker.  Zero the descriptors cookie to prevent accidental
+ * repeated completions.
+ *
+ * Note: caller is expected to hold a lock to prevent concurrency.
+ */
+static inline void dma_cookie_complete(struct dma_async_tx_descriptor *tx)
+{
+       BUG_ON(tx->cookie < DMA_MIN_COOKIE);
+       tx->chan->completed_cookie = tx->cookie;
+       tx->cookie = 0;
+}
+
 #endif
index 3a4ca67ace02f30a10985b359913228ec3dd187f..12ea60b2a1beb8cbef7f20f9c304bc6be3fa7e6d 100644 (file)
@@ -235,7 +235,7 @@ dwc_descriptor_complete(struct dw_dma_chan *dwc, struct dw_desc *desc,
        dev_vdbg(chan2dev(&dwc->chan), "descriptor %u complete\n", txd->cookie);
 
        spin_lock_irqsave(&dwc->lock, flags);
-       dwc->chan.completed_cookie = txd->cookie;
+       dma_cookie_complete(txd);
        if (callback_required) {
                callback = txd->callback;
                param = txd->callback_param;
index e5aaae87ddfb2cd9d9b3e13c07602a09611ba809..1c56f75d9faffddee53ad588066bbea85a035709 100644 (file)
@@ -703,7 +703,7 @@ static void ep93xx_dma_tasklet(unsigned long data)
        desc = ep93xx_dma_get_active(edmac);
        if (desc) {
                if (desc->complete) {
-                       edmac->chan.completed_cookie = desc->txd.cookie;
+                       dma_cookie_complete(&desc->txd);
                        list_splice_init(&edmac->active, &list);
                }
                callback = desc->txd.callback;
index 04b4347ba4e9bad6013a90bb2fedb221e133de4d..f36e8b18cba29ea71e4fa6267b5f144c78c03a98 100644 (file)
@@ -1081,8 +1081,8 @@ static void dma_do_tasklet(unsigned long data)
 
                desc = to_fsl_desc(chan->ld_running.prev);
                cookie = desc->async_tx.cookie;
+               dma_cookie_complete(&desc->async_tx);
 
-               chan->common.completed_cookie = cookie;
                chan_dbg(chan, "completed_cookie=%d\n", cookie);
        }
 
index 687fc687aaf6efd27d47922aa953d8f30b50a82f..9a3cbac3d69590f7dd2934b6115d127318621e8f 100644 (file)
@@ -66,7 +66,7 @@ static void imxdma_handle(struct imxdma_channel *imxdmac)
 {
        if (imxdmac->desc.callback)
                imxdmac->desc.callback(imxdmac->desc.callback_param);
-       imxdmac->chan.completed_cookie = imxdmac->desc.cookie;
+       dma_cookie_complete(&imxdmac->desc);
 }
 
 static void imxdma_irq_handler(int channel, void *data)
index 3f0c002933f3ecbd0527fff6c5b165ec36c9d275..981071ebd5c8bf3d23dd6f5234bf9f2105ef48c7 100644 (file)
@@ -530,7 +530,7 @@ static void mxc_sdma_handle_channel_normal(struct sdma_channel *sdmac)
        else
                sdmac->status = DMA_SUCCESS;
 
-       sdmac->chan.completed_cookie = sdmac->desc.cookie;
+       dma_cookie_complete(&sdmac->desc);
        if (sdmac->desc.callback)
                sdmac->desc.callback(sdmac->desc.callback_param);
 }
index e9217c390b76e998eff58251ceef8465a8b2638f..cee79f6e035ddb6c1984cb6725e6dc393ff0b69e 100644 (file)
@@ -290,7 +290,7 @@ static void midc_descriptor_complete(struct intel_mid_dma_chan *midc,
        struct intel_mid_dma_lli        *llitem;
        void *param_txd = NULL;
 
-       midc->chan.completed_cookie = txd->cookie;
+       dma_cookie_complete(txd);
        callback_txd = txd->callback;
        param_txd = txd->callback_param;
 
index 5c06117ac682f3279aa5be565b1dcd6df0d1438e..b0517c86c1bb51210448466eb39e2df34ac89fbc 100644 (file)
@@ -600,8 +600,7 @@ static void __cleanup(struct ioat_dma_chan *ioat, unsigned long phys_complete)
                 */
                dump_desc_dbg(ioat, desc);
                if (tx->cookie) {
-                       chan->common.completed_cookie = tx->cookie;
-                       tx->cookie = 0;
+                       dma_cookie_complete(tx);
                        ioat_dma_unmap(chan, tx->flags, desc->len, desc->hw);
                        ioat->active -= desc->hw->tx_cnt;
                        if (tx->callback) {
index 17ecacb70d40c9c15288be0ce16942a2d64d378b..e8e110ff3d965547b03f7bbf80cddcb58911a031 100644 (file)
@@ -149,8 +149,7 @@ static void __cleanup(struct ioat2_dma_chan *ioat, unsigned long phys_complete)
                dump_desc_dbg(ioat, desc);
                if (tx->cookie) {
                        ioat_dma_unmap(chan, tx->flags, desc->len, desc->hw);
-                       chan->common.completed_cookie = tx->cookie;
-                       tx->cookie = 0;
+                       dma_cookie_complete(tx);
                        if (tx->callback) {
                                tx->callback(tx->callback_param);
                                tx->callback = NULL;
index d4afac741e8a53efd85c70e0ea0dcecbec3c7af3..1bda46c43bd7caca6d8c013dec320bb330e52b67 100644 (file)
@@ -277,9 +277,8 @@ static void __cleanup(struct ioat2_dma_chan *ioat, unsigned long phys_complete)
                dump_desc_dbg(ioat, desc);
                tx = &desc->txd;
                if (tx->cookie) {
-                       chan->common.completed_cookie = tx->cookie;
+                       dma_cookie_complete(tx);
                        ioat3_dma_unmap(ioat, desc, idx + i);
-                       tx->cookie = 0;
                        if (tx->callback) {
                                tx->callback(tx->callback_param);
                                tx->callback = NULL;
index d4620c53fd2d3518ab0b31ee9003c728cf8235d2..bff9250a59ce92395165f6d469597ff062a5ba5b 100644 (file)
@@ -1289,7 +1289,7 @@ static irqreturn_t idmac_interrupt(int irq, void *dev_id)
        /* Flip the active buffer - even if update above failed */
        ichan->active_buffer = !ichan->active_buffer;
        if (done)
-               ichan->dma_chan.completed_cookie = desc->txd.cookie;
+               dma_cookie_complete(&desc->txd);
 
        callback = desc->txd.callback;
        callback_param = desc->txd.callback_param;
index 4d3b6ff3050f7453e901535fa31db7d977cb3e29..5f3492e5d28f34494681b6d342fd482f302c88e6 100644 (file)
@@ -262,7 +262,7 @@ static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id)
                stat1 &= ~(1 << channel);
 
                if (mxs_chan->status == DMA_SUCCESS)
-                       mxs_chan->chan.completed_cookie = mxs_chan->desc.cookie;
+                       dma_cookie_complete(&mxs_chan->desc);
 
                /* schedule tasklet on this channel */
                tasklet_schedule(&mxs_chan->tasklet);
index 644eb789958be99138e9d454452d2242c6c16626..a81d0a5f8191565c76340ed1b51dd60d0bc7d7e5 100644 (file)
@@ -233,7 +233,7 @@ static void pl330_tasklet(unsigned long data)
        /* Pick up ripe tomatoes */
        list_for_each_entry_safe(desc, _dt, &pch->work_list, node)
                if (desc->status == DONE) {
-                       pch->chan.completed_cookie = desc->txd.cookie;
+                       dma_cookie_complete(&desc->txd);
                        list_move_tail(&desc->node, &list);
                }
 
index 23e2edc4afd41720ece607b79ae37601acaaabea..c2463758fed1b3b8a16abf48e1cf9c34365bf350 100644 (file)
@@ -1347,7 +1347,7 @@ static void dma_tasklet(unsigned long data)
                goto err;
 
        if (!d40d->cyclic)
-               d40c->chan.completed_cookie = d40d->txd.cookie;
+               dma_cookie_complete(&d40d->txd);
 
        /*
         * If terminating a channel pending_tx is set to zero.
index b6e83fc27c4e9ea3e66146932ede648f684b5a06..1845ac9d6e882517778bd1709b5567bbcd1beb1d 100644 (file)
@@ -285,7 +285,7 @@ static void __td_finish(struct timb_dma_chan *td_chan)
        else
                iowrite32(0, td_chan->membase + TIMBDMA_OFFS_TX_DLAR);
 */
-       td_chan->chan.completed_cookie = txd->cookie;
+       dma_cookie_complete(txd);
        td_chan->ongoing = false;
 
        callback = txd->callback;
index 66f8fca1bd3c5322623dc320008ec75919218ce9..8a5225bf9bc945b3afe87481ef9c7ed34b637b93 100644 (file)
@@ -411,7 +411,7 @@ txx9dmac_descriptor_complete(struct txx9dmac_chan *dc,
        dev_vdbg(chan2dev(&dc->chan), "descriptor %u %p complete\n",
                 txd->cookie, desc);
 
-       dc->chan.completed_cookie = txd->cookie;
+       dma_cookie_complete(txd);
        callback = txd->callback;
        param = txd->callback_param;