2011-03-23 18:42:44 +07:00
|
|
|
/*
|
2017-05-10 16:25:25 +07:00
|
|
|
* DMA function for TMIO MMC implementations
|
2011-03-23 18:42:44 +07:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010-2011 Guennadi Liakhovetski
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
2011-06-16 18:01:34 +07:00
|
|
|
#include <linux/dma-mapping.h>
|
2011-03-23 18:42:44 +07:00
|
|
|
#include <linux/dmaengine.h>
|
|
|
|
#include <linux/mfd/tmio.h>
|
|
|
|
#include <linux/mmc/host.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/scatterlist.h>
|
|
|
|
|
|
|
|
#include "tmio_mmc.h"
|
|
|
|
|
|
|
|
#define TMIO_MMC_MIN_DMA_LEN 8
|
|
|
|
|
2011-07-14 23:39:10 +07:00
|
|
|
void tmio_mmc_enable_dma(struct tmio_mmc_host *host, bool enable)
|
2011-03-23 18:42:44 +07:00
|
|
|
{
|
2011-07-14 23:39:10 +07:00
|
|
|
if (!host->chan_tx || !host->chan_rx)
|
|
|
|
return;
|
|
|
|
|
2015-01-13 11:59:05 +07:00
|
|
|
if (host->dma->enable)
|
|
|
|
host->dma->enable(host, enable);
|
2011-03-23 18:42:44 +07:00
|
|
|
}
|
|
|
|
|
2012-01-06 19:06:51 +07:00
|
|
|
void tmio_mmc_abort_dma(struct tmio_mmc_host *host)
|
|
|
|
{
|
|
|
|
tmio_mmc_enable_dma(host, false);
|
|
|
|
|
|
|
|
if (host->chan_rx)
|
|
|
|
dmaengine_terminate_all(host->chan_rx);
|
|
|
|
if (host->chan_tx)
|
|
|
|
dmaengine_terminate_all(host->chan_tx);
|
|
|
|
|
|
|
|
tmio_mmc_enable_dma(host, true);
|
|
|
|
}
|
|
|
|
|
mmc: tmio: ensure end of DMA and SD access are in sync
The current code assumes that DMA is finished before SD access end is
flagged. Thus, it schedules the 'dma_complete' tasklet in the SD card
interrupt routine when DATAEND is set. The assumption is not safe,
though. Even by mounting an SD card, it can be seen that sometimes DMA
complete is first, sometimes DATAEND. It seems they are usually close
enough timewise to not cause problems. However, a customer reported that
with CMD53 sometimes things really break apart. As a result, the BSP has
a patch which introduces flags for both events and makes sure both flags
are set before scheduling the tasklet. The customer accepted the patch,
yet it doesn't seem a proper upstream solution to me.
This patch refactors the code to replace the tasklet with already
existing and more lightweight mechanisms. First of all, we set the
callback in a DMA descriptor to automatically get notified when DMA is
done. In the callback, we then use a completion to make sure the SD
access has already ended. Then, we proceed as before.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2017-02-18 01:22:41 +07:00
|
|
|
static void tmio_mmc_dma_callback(void *arg)
|
|
|
|
{
|
|
|
|
struct tmio_mmc_host *host = arg;
|
|
|
|
|
|
|
|
spin_lock_irq(&host->lock);
|
|
|
|
|
|
|
|
if (!host->data)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (host->data->flags & MMC_DATA_READ)
|
|
|
|
dma_unmap_sg(host->chan_rx->device->dev,
|
|
|
|
host->sg_ptr, host->sg_len,
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
else
|
|
|
|
dma_unmap_sg(host->chan_tx->device->dev,
|
|
|
|
host->sg_ptr, host->sg_len,
|
|
|
|
DMA_TO_DEVICE);
|
|
|
|
|
2017-03-16 17:56:02 +07:00
|
|
|
spin_unlock_irq(&host->lock);
|
|
|
|
|
|
|
|
wait_for_completion(&host->dma_dataend);
|
|
|
|
|
|
|
|
spin_lock_irq(&host->lock);
|
mmc: tmio: ensure end of DMA and SD access are in sync
The current code assumes that DMA is finished before SD access end is
flagged. Thus, it schedules the 'dma_complete' tasklet in the SD card
interrupt routine when DATAEND is set. The assumption is not safe,
though. Even by mounting an SD card, it can be seen that sometimes DMA
complete is first, sometimes DATAEND. It seems they are usually close
enough timewise to not cause problems. However, a customer reported that
with CMD53 sometimes things really break apart. As a result, the BSP has
a patch which introduces flags for both events and makes sure both flags
are set before scheduling the tasklet. The customer accepted the patch,
yet it doesn't seem a proper upstream solution to me.
This patch refactors the code to replace the tasklet with already
existing and more lightweight mechanisms. First of all, we set the
callback in a DMA descriptor to automatically get notified when DMA is
done. In the callback, we then use a completion to make sure the SD
access has already ended. Then, we proceed as before.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2017-02-18 01:22:41 +07:00
|
|
|
tmio_mmc_do_data_irq(host);
|
|
|
|
out:
|
|
|
|
spin_unlock_irq(&host->lock);
|
|
|
|
}
|
|
|
|
|
2011-03-23 18:42:44 +07:00
|
|
|
static void tmio_mmc_start_dma_rx(struct tmio_mmc_host *host)
|
|
|
|
{
|
|
|
|
struct scatterlist *sg = host->sg_ptr, *sg_tmp;
|
|
|
|
struct dma_async_tx_descriptor *desc = NULL;
|
|
|
|
struct dma_chan *chan = host->chan_rx;
|
|
|
|
dma_cookie_t cookie;
|
|
|
|
int ret, i;
|
|
|
|
bool aligned = true, multiple = true;
|
2015-01-13 11:58:46 +07:00
|
|
|
unsigned int align = (1 << host->pdata->alignment_shift) - 1;
|
2011-03-23 18:42:44 +07:00
|
|
|
|
|
|
|
for_each_sg(sg, sg_tmp, host->sg_len, i) {
|
|
|
|
if (sg_tmp->offset & align)
|
|
|
|
aligned = false;
|
|
|
|
if (sg_tmp->length & align) {
|
|
|
|
multiple = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 19:29:47 +07:00
|
|
|
if ((!aligned && (host->sg_len > 1 || sg->length > PAGE_SIZE ||
|
2011-03-23 18:42:44 +07:00
|
|
|
(align & PAGE_MASK))) || !multiple) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto pio;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sg->length < TMIO_MMC_MIN_DMA_LEN) {
|
|
|
|
host->force_pio = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmio_mmc_disable_mmc_irqs(host, TMIO_STAT_RXRDY);
|
|
|
|
|
|
|
|
/* The only sg element can be unaligned, use our bounce buffer then */
|
|
|
|
if (!aligned) {
|
|
|
|
sg_init_one(&host->bounce_sg, host->bounce_buf, sg->length);
|
|
|
|
host->sg_ptr = &host->bounce_sg;
|
|
|
|
sg = host->sg_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = dma_map_sg(chan->device->dev, sg, host->sg_len, DMA_FROM_DEVICE);
|
|
|
|
if (ret > 0)
|
2012-03-09 04:11:18 +07:00
|
|
|
desc = dmaengine_prep_slave_sg(chan, sg, ret,
|
2011-10-14 12:15:11 +07:00
|
|
|
DMA_DEV_TO_MEM, DMA_CTRL_ACK);
|
2011-03-23 18:42:44 +07:00
|
|
|
|
|
|
|
if (desc) {
|
mmc: tmio: ensure end of DMA and SD access are in sync
The current code assumes that DMA is finished before SD access end is
flagged. Thus, it schedules the 'dma_complete' tasklet in the SD card
interrupt routine when DATAEND is set. The assumption is not safe,
though. Even by mounting an SD card, it can be seen that sometimes DMA
complete is first, sometimes DATAEND. It seems they are usually close
enough timewise to not cause problems. However, a customer reported that
with CMD53 sometimes things really break apart. As a result, the BSP has
a patch which introduces flags for both events and makes sure both flags
are set before scheduling the tasklet. The customer accepted the patch,
yet it doesn't seem a proper upstream solution to me.
This patch refactors the code to replace the tasklet with already
existing and more lightweight mechanisms. First of all, we set the
callback in a DMA descriptor to automatically get notified when DMA is
done. In the callback, we then use a completion to make sure the SD
access has already ended. Then, we proceed as before.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2017-02-18 01:22:41 +07:00
|
|
|
reinit_completion(&host->dma_dataend);
|
|
|
|
desc->callback = tmio_mmc_dma_callback;
|
|
|
|
desc->callback_param = host;
|
|
|
|
|
2011-03-23 18:42:44 +07:00
|
|
|
cookie = dmaengine_submit(desc);
|
|
|
|
if (cookie < 0) {
|
|
|
|
desc = NULL;
|
|
|
|
ret = cookie;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pio:
|
|
|
|
if (!desc) {
|
|
|
|
/* DMA failed, fall back to PIO */
|
2013-08-25 10:38:15 +07:00
|
|
|
tmio_mmc_enable_dma(host, false);
|
2011-03-23 18:42:44 +07:00
|
|
|
if (ret >= 0)
|
|
|
|
ret = -EIO;
|
|
|
|
host->chan_rx = NULL;
|
|
|
|
dma_release_channel(chan);
|
|
|
|
/* Free the Tx channel too */
|
|
|
|
chan = host->chan_tx;
|
|
|
|
if (chan) {
|
|
|
|
host->chan_tx = NULL;
|
|
|
|
dma_release_channel(chan);
|
|
|
|
}
|
|
|
|
dev_warn(&host->pdev->dev,
|
|
|
|
"DMA failed: %d, falling back to PIO\n", ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tmio_mmc_start_dma_tx(struct tmio_mmc_host *host)
|
|
|
|
{
|
|
|
|
struct scatterlist *sg = host->sg_ptr, *sg_tmp;
|
|
|
|
struct dma_async_tx_descriptor *desc = NULL;
|
|
|
|
struct dma_chan *chan = host->chan_tx;
|
|
|
|
dma_cookie_t cookie;
|
|
|
|
int ret, i;
|
|
|
|
bool aligned = true, multiple = true;
|
2015-01-13 11:58:46 +07:00
|
|
|
unsigned int align = (1 << host->pdata->alignment_shift) - 1;
|
2011-03-23 18:42:44 +07:00
|
|
|
|
|
|
|
for_each_sg(sg, sg_tmp, host->sg_len, i) {
|
|
|
|
if (sg_tmp->offset & align)
|
|
|
|
aligned = false;
|
|
|
|
if (sg_tmp->length & align) {
|
|
|
|
multiple = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 19:29:47 +07:00
|
|
|
if ((!aligned && (host->sg_len > 1 || sg->length > PAGE_SIZE ||
|
2011-03-23 18:42:44 +07:00
|
|
|
(align & PAGE_MASK))) || !multiple) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto pio;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sg->length < TMIO_MMC_MIN_DMA_LEN) {
|
|
|
|
host->force_pio = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmio_mmc_disable_mmc_irqs(host, TMIO_STAT_TXRQ);
|
|
|
|
|
|
|
|
/* The only sg element can be unaligned, use our bounce buffer then */
|
|
|
|
if (!aligned) {
|
|
|
|
unsigned long flags;
|
|
|
|
void *sg_vaddr = tmio_mmc_kmap_atomic(sg, &flags);
|
|
|
|
sg_init_one(&host->bounce_sg, host->bounce_buf, sg->length);
|
|
|
|
memcpy(host->bounce_buf, sg_vaddr, host->bounce_sg.length);
|
|
|
|
tmio_mmc_kunmap_atomic(sg, &flags, sg_vaddr);
|
|
|
|
host->sg_ptr = &host->bounce_sg;
|
|
|
|
sg = host->sg_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = dma_map_sg(chan->device->dev, sg, host->sg_len, DMA_TO_DEVICE);
|
|
|
|
if (ret > 0)
|
2012-03-09 04:11:18 +07:00
|
|
|
desc = dmaengine_prep_slave_sg(chan, sg, ret,
|
2011-10-14 12:15:11 +07:00
|
|
|
DMA_MEM_TO_DEV, DMA_CTRL_ACK);
|
2011-03-23 18:42:44 +07:00
|
|
|
|
|
|
|
if (desc) {
|
mmc: tmio: ensure end of DMA and SD access are in sync
The current code assumes that DMA is finished before SD access end is
flagged. Thus, it schedules the 'dma_complete' tasklet in the SD card
interrupt routine when DATAEND is set. The assumption is not safe,
though. Even by mounting an SD card, it can be seen that sometimes DMA
complete is first, sometimes DATAEND. It seems they are usually close
enough timewise to not cause problems. However, a customer reported that
with CMD53 sometimes things really break apart. As a result, the BSP has
a patch which introduces flags for both events and makes sure both flags
are set before scheduling the tasklet. The customer accepted the patch,
yet it doesn't seem a proper upstream solution to me.
This patch refactors the code to replace the tasklet with already
existing and more lightweight mechanisms. First of all, we set the
callback in a DMA descriptor to automatically get notified when DMA is
done. In the callback, we then use a completion to make sure the SD
access has already ended. Then, we proceed as before.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2017-02-18 01:22:41 +07:00
|
|
|
reinit_completion(&host->dma_dataend);
|
|
|
|
desc->callback = tmio_mmc_dma_callback;
|
|
|
|
desc->callback_param = host;
|
|
|
|
|
2011-03-23 18:42:44 +07:00
|
|
|
cookie = dmaengine_submit(desc);
|
|
|
|
if (cookie < 0) {
|
|
|
|
desc = NULL;
|
|
|
|
ret = cookie;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pio:
|
|
|
|
if (!desc) {
|
|
|
|
/* DMA failed, fall back to PIO */
|
2013-08-25 10:38:15 +07:00
|
|
|
tmio_mmc_enable_dma(host, false);
|
2011-03-23 18:42:44 +07:00
|
|
|
if (ret >= 0)
|
|
|
|
ret = -EIO;
|
|
|
|
host->chan_tx = NULL;
|
|
|
|
dma_release_channel(chan);
|
|
|
|
/* Free the Rx channel too */
|
|
|
|
chan = host->chan_rx;
|
|
|
|
if (chan) {
|
|
|
|
host->chan_rx = NULL;
|
|
|
|
dma_release_channel(chan);
|
|
|
|
}
|
|
|
|
dev_warn(&host->pdev->dev,
|
|
|
|
"DMA failed: %d, falling back to PIO\n", ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tmio_mmc_start_dma(struct tmio_mmc_host *host,
|
|
|
|
struct mmc_data *data)
|
|
|
|
{
|
|
|
|
if (data->flags & MMC_DATA_READ) {
|
|
|
|
if (host->chan_rx)
|
|
|
|
tmio_mmc_start_dma_rx(host);
|
|
|
|
} else {
|
|
|
|
if (host->chan_tx)
|
|
|
|
tmio_mmc_start_dma_tx(host);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tmio_mmc_issue_tasklet_fn(unsigned long priv)
|
|
|
|
{
|
|
|
|
struct tmio_mmc_host *host = (struct tmio_mmc_host *)priv;
|
|
|
|
struct dma_chan *chan = NULL;
|
|
|
|
|
|
|
|
spin_lock_irq(&host->lock);
|
|
|
|
|
|
|
|
if (host && host->data) {
|
|
|
|
if (host->data->flags & MMC_DATA_READ)
|
|
|
|
chan = host->chan_rx;
|
|
|
|
else
|
|
|
|
chan = host->chan_tx;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irq(&host->lock);
|
|
|
|
|
|
|
|
tmio_mmc_enable_mmc_irqs(host, TMIO_STAT_DATAEND);
|
|
|
|
|
|
|
|
if (chan)
|
|
|
|
dma_async_issue_pending(chan);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tmio_mmc_request_dma(struct tmio_mmc_host *host, struct tmio_mmc_data *pdata)
|
|
|
|
{
|
|
|
|
/* We can only either use DMA for both Tx and Rx or not use it at all */
|
2015-01-13 11:57:33 +07:00
|
|
|
if (!host->dma || (!host->pdev->dev.of_node &&
|
2015-02-24 09:06:43 +07:00
|
|
|
(!pdata->chan_priv_tx || !pdata->chan_priv_rx)))
|
2011-05-05 23:13:12 +07:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!host->chan_tx && !host->chan_rx) {
|
2013-04-26 22:47:18 +07:00
|
|
|
struct resource *res = platform_get_resource(host->pdev,
|
|
|
|
IORESOURCE_MEM, 0);
|
|
|
|
struct dma_slave_config cfg = {};
|
2011-03-23 18:42:44 +07:00
|
|
|
dma_cap_mask_t mask;
|
2013-04-26 22:47:18 +07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!res)
|
|
|
|
return;
|
2011-03-23 18:42:44 +07:00
|
|
|
|
|
|
|
dma_cap_zero(mask);
|
|
|
|
dma_cap_set(DMA_SLAVE, mask);
|
|
|
|
|
2013-04-26 22:47:19 +07:00
|
|
|
host->chan_tx = dma_request_slave_channel_compat(mask,
|
2015-02-24 09:06:43 +07:00
|
|
|
host->dma->filter, pdata->chan_priv_tx,
|
2013-04-26 22:47:19 +07:00
|
|
|
&host->pdev->dev, "tx");
|
2011-03-23 18:42:44 +07:00
|
|
|
dev_dbg(&host->pdev->dev, "%s: TX: got channel %p\n", __func__,
|
|
|
|
host->chan_tx);
|
|
|
|
|
|
|
|
if (!host->chan_tx)
|
|
|
|
return;
|
|
|
|
|
2013-04-26 22:47:18 +07:00
|
|
|
cfg.direction = DMA_MEM_TO_DEV;
|
2015-01-13 11:58:20 +07:00
|
|
|
cfg.dst_addr = res->start + (CTL_SD_DATA_PORT << host->bus_shift);
|
2015-01-13 11:59:14 +07:00
|
|
|
cfg.dst_addr_width = host->dma->dma_buswidth;
|
|
|
|
if (!cfg.dst_addr_width)
|
|
|
|
cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
|
2013-04-26 22:47:18 +07:00
|
|
|
cfg.src_addr = 0;
|
|
|
|
ret = dmaengine_slave_config(host->chan_tx, &cfg);
|
|
|
|
if (ret < 0)
|
|
|
|
goto ecfgtx;
|
|
|
|
|
2013-04-26 22:47:19 +07:00
|
|
|
host->chan_rx = dma_request_slave_channel_compat(mask,
|
2015-02-24 09:06:43 +07:00
|
|
|
host->dma->filter, pdata->chan_priv_rx,
|
2013-04-26 22:47:19 +07:00
|
|
|
&host->pdev->dev, "rx");
|
2011-03-23 18:42:44 +07:00
|
|
|
dev_dbg(&host->pdev->dev, "%s: RX: got channel %p\n", __func__,
|
|
|
|
host->chan_rx);
|
|
|
|
|
|
|
|
if (!host->chan_rx)
|
|
|
|
goto ereqrx;
|
|
|
|
|
2013-04-26 22:47:18 +07:00
|
|
|
cfg.direction = DMA_DEV_TO_MEM;
|
2015-01-13 11:58:56 +07:00
|
|
|
cfg.src_addr = cfg.dst_addr + host->pdata->dma_rx_offset;
|
2015-01-13 11:59:14 +07:00
|
|
|
cfg.src_addr_width = host->dma->dma_buswidth;
|
|
|
|
if (!cfg.src_addr_width)
|
|
|
|
cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
|
2013-04-26 22:47:18 +07:00
|
|
|
cfg.dst_addr = 0;
|
|
|
|
ret = dmaengine_slave_config(host->chan_rx, &cfg);
|
|
|
|
if (ret < 0)
|
|
|
|
goto ecfgrx;
|
|
|
|
|
2011-03-23 18:42:44 +07:00
|
|
|
host->bounce_buf = (u8 *)__get_free_page(GFP_KERNEL | GFP_DMA);
|
|
|
|
if (!host->bounce_buf)
|
|
|
|
goto ebouncebuf;
|
|
|
|
|
mmc: tmio: ensure end of DMA and SD access are in sync
The current code assumes that DMA is finished before SD access end is
flagged. Thus, it schedules the 'dma_complete' tasklet in the SD card
interrupt routine when DATAEND is set. The assumption is not safe,
though. Even by mounting an SD card, it can be seen that sometimes DMA
complete is first, sometimes DATAEND. It seems they are usually close
enough timewise to not cause problems. However, a customer reported that
with CMD53 sometimes things really break apart. As a result, the BSP has
a patch which introduces flags for both events and makes sure both flags
are set before scheduling the tasklet. The customer accepted the patch,
yet it doesn't seem a proper upstream solution to me.
This patch refactors the code to replace the tasklet with already
existing and more lightweight mechanisms. First of all, we set the
callback in a DMA descriptor to automatically get notified when DMA is
done. In the callback, we then use a completion to make sure the SD
access has already ended. Then, we proceed as before.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2017-02-18 01:22:41 +07:00
|
|
|
init_completion(&host->dma_dataend);
|
2011-03-23 18:42:44 +07:00
|
|
|
tasklet_init(&host->dma_issue, tmio_mmc_issue_tasklet_fn, (unsigned long)host);
|
2011-05-05 23:13:12 +07:00
|
|
|
}
|
2011-03-23 18:42:44 +07:00
|
|
|
|
2011-05-05 23:13:12 +07:00
|
|
|
tmio_mmc_enable_dma(host, true);
|
|
|
|
|
|
|
|
return;
|
2011-03-23 18:42:44 +07:00
|
|
|
|
|
|
|
ebouncebuf:
|
2013-04-26 22:47:18 +07:00
|
|
|
ecfgrx:
|
2011-05-05 23:13:12 +07:00
|
|
|
dma_release_channel(host->chan_rx);
|
|
|
|
host->chan_rx = NULL;
|
2011-03-23 18:42:44 +07:00
|
|
|
ereqrx:
|
2013-04-26 22:47:18 +07:00
|
|
|
ecfgtx:
|
2011-05-05 23:13:12 +07:00
|
|
|
dma_release_channel(host->chan_tx);
|
|
|
|
host->chan_tx = NULL;
|
2011-03-23 18:42:44 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void tmio_mmc_release_dma(struct tmio_mmc_host *host)
|
|
|
|
{
|
|
|
|
if (host->chan_tx) {
|
|
|
|
struct dma_chan *chan = host->chan_tx;
|
|
|
|
host->chan_tx = NULL;
|
|
|
|
dma_release_channel(chan);
|
|
|
|
}
|
|
|
|
if (host->chan_rx) {
|
|
|
|
struct dma_chan *chan = host->chan_rx;
|
|
|
|
host->chan_rx = NULL;
|
|
|
|
dma_release_channel(chan);
|
|
|
|
}
|
|
|
|
if (host->bounce_buf) {
|
|
|
|
free_pages((unsigned long)host->bounce_buf, 0);
|
|
|
|
host->bounce_buf = NULL;
|
|
|
|
}
|
|
|
|
}
|