spi: au1550_spi full duplex dma fix
Fix unsafe order in dma mapping operation: always flush data from the cache *BEFORE* invalidating it, to allow full duplex transfers where the same buffer may be used for both writes and reads. Tested with mmc-spi. Signed-off-by: Jan Nikitenko <jan.nikitenko@gmail.com> Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
6a010b56e9
commit
4e253d2300
|
@ -369,10 +369,23 @@ static int au1550_spi_dma_txrxb(struct spi_device *spi, struct spi_transfer *t)
|
||||||
dma_rx_addr = t->rx_dma;
|
dma_rx_addr = t->rx_dma;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* check if buffers are already dma mapped, map them otherwise
|
* check if buffers are already dma mapped, map them otherwise:
|
||||||
|
* - first map the TX buffer, so cache data gets written to memory
|
||||||
|
* - then map the RX buffer, so that cache entries (with
|
||||||
|
* soon-to-be-stale data) get removed
|
||||||
* use rx buffer in place of tx if tx buffer was not provided
|
* use rx buffer in place of tx if tx buffer was not provided
|
||||||
* use temp rx buffer (preallocated or realloc to fit) for rx dma
|
* use temp rx buffer (preallocated or realloc to fit) for rx dma
|
||||||
*/
|
*/
|
||||||
|
if (t->tx_buf) {
|
||||||
|
if (t->tx_dma == 0) { /* if DMA_ADDR_INVALID, map it */
|
||||||
|
dma_tx_addr = dma_map_single(hw->dev,
|
||||||
|
(void *)t->tx_buf,
|
||||||
|
t->len, DMA_TO_DEVICE);
|
||||||
|
if (dma_mapping_error(hw->dev, dma_tx_addr))
|
||||||
|
dev_err(hw->dev, "tx dma map error\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (t->rx_buf) {
|
if (t->rx_buf) {
|
||||||
if (t->rx_dma == 0) { /* if DMA_ADDR_INVALID, map it */
|
if (t->rx_dma == 0) { /* if DMA_ADDR_INVALID, map it */
|
||||||
dma_rx_addr = dma_map_single(hw->dev,
|
dma_rx_addr = dma_map_single(hw->dev,
|
||||||
|
@ -396,15 +409,8 @@ static int au1550_spi_dma_txrxb(struct spi_device *spi, struct spi_transfer *t)
|
||||||
dma_sync_single_for_device(hw->dev, dma_rx_addr,
|
dma_sync_single_for_device(hw->dev, dma_rx_addr,
|
||||||
t->len, DMA_FROM_DEVICE);
|
t->len, DMA_FROM_DEVICE);
|
||||||
}
|
}
|
||||||
if (t->tx_buf) {
|
|
||||||
if (t->tx_dma == 0) { /* if DMA_ADDR_INVALID, map it */
|
if (!t->tx_buf) {
|
||||||
dma_tx_addr = dma_map_single(hw->dev,
|
|
||||||
(void *)t->tx_buf,
|
|
||||||
t->len, DMA_TO_DEVICE);
|
|
||||||
if (dma_mapping_error(hw->dev, dma_tx_addr))
|
|
||||||
dev_err(hw->dev, "tx dma map error\n");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dma_sync_single_for_device(hw->dev, dma_rx_addr,
|
dma_sync_single_for_device(hw->dev, dma_rx_addr,
|
||||||
t->len, DMA_BIDIRECTIONAL);
|
t->len, DMA_BIDIRECTIONAL);
|
||||||
hw->tx = hw->rx;
|
hw->tx = hw->rx;
|
||||||
|
|
Loading…
Reference in a new issue