spi: spi-cadence-quadspi: Fix mapping of buffers for DMA reads
PATCH 1/1 spi: spi-cadence-quadspi: Fix mapping of buffers for DMA reads
Buffers need to mapped to DMA channel's device pointer instead of SPI controller's device pointer as its system DMA that actually does data transfer.
Data inconsistencies have been reported when reading from flash without this fix.
---
This issue was present in the original driver under SPI NOR framework as well. But only got exposed as driver started handling probe deferral for DMA channel request and thus uses DMA almost always unlike before.
drivers/spi/spi-cadence-quadspi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/spi/spi-cadence-quadspi.c +5 -3
@@ -907,14 +907,16 @@ static int cqspi_direct_read_execute(struct cqspi_flash_pdata *f_pdata,struct dma_async_tx_descriptor *tx;dma_cookie_t cookie;dma_addr_t dma_dst; +struct device *ddev;if (!cqspi->rx_chan || !virt_addr_valid (buf)) {memcpy_fromio (buf, cqspi->ahb_base + from, len);return 0 ; } - dma_dst =dma_map_single (dev, buf, len,DMA_FROM_DEVICE ); -if (dma_mapping_error (dev, dma_dst)) { + ddev = cqspi->rx_chan->device->dev; + dma_dst =dma_map_single (ddev, buf, len,DMA_FROM_DEVICE ); +if (dma_mapping_error (ddev, dma_dst)) {dev_err (dev,"dma mapping failed\n" );return -ENOMEM ; }
@@ -948,7 +950,7 @@ static int cqspi_direct_read_execute(struct cqspi_flash_pdata *f_pdata, } err_unmap: -dma_unmap_single (dev, dma_dst, len,DMA_FROM_DEVICE ); +dma_unmap_single (ddev, dma_dst, len,DMA_FROM_DEVICE );return ret; }
Signature · 1 line
2.28.0
Quoted 7 lines · Vignesh Raghavendra
Buffers need to mapped to DMA channel's device pointer instead of SPI controller's device pointer as its system DMA that actually does data transfer.
Data inconsistencies have been reported when reading from flash without this fix.Fixes 31fb632b5d43c ("spi: Move cadence-quadspi driver to drivers/spi/")
This looks wrong, ...
Quoted 6 lines
Signed-off-by Vignesh Raghavendra <[email protected]>---
This issue was present in the original driver under SPI NOR framework as well. But only got exposed as driver started handling probe deferral for DMA channel request and thus uses DMA almost always unlike before.
...you rather want 935da5e5100f57d843cac4781b21f1c235059aa0 then.
Other than that:
Thanks!
Jan
Quoted 37 lines
drivers/spi/spi-cadence-quadspi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/spi/spi-cadence-quadspi.c +5
-3@@ -907,14 +907,16 @@ static int cqspi_direct_read_execute(struct cqspi_flash_pdata *f_pdata,struct dma_async_tx_descriptor *tx;dma_cookie_t cookie;dma_addr_t dma_dst; +struct device *ddev;if (!cqspi->rx_chan || !virt_addr_valid (buf)) {memcpy_fromio (buf, cqspi->ahb_base + from, len);return 0 ; } - dma_dst =dma_map_single (dev, buf, len,DMA_FROM_DEVICE ); -if (dma_mapping_error (dev, dma_dst)) { + ddev = cqspi->rx_chan->device->dev; + dma_dst =dma_map_single (ddev, buf, len,DMA_FROM_DEVICE ); +if (dma_mapping_error (ddev, dma_dst)) {dev_err (dev,"dma mapping failed\n" );return -ENOMEM ; }@@ -948,7 +950,7 @@ static int cqspi_direct_read_execute(struct cqspi_flash_pdata *f_pdata, } err_unmap: -dma_unmap_single (dev, dma_dst, len,DMA_FROM_DEVICE ); +dma_unmap_single (ddev, dma_dst, len,DMA_FROM_DEVICE );return ret; }
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Quoted 11 lines · Jan Kiszka
Quoted 7 lines · Vignesh Raghavendra
Buffers need to mapped to DMA channel's device pointer instead of SPI controller's device pointer as its system DMA that actually does data transfer.
Data inconsistencies have been reported when reading from flash without this fix.Fixes 31fb632b5d43c ("spi: Move cadence-quadspi driver to drivers/spi/")This looks wrong, ...
Quoted 9 lines
Quoted 6 lines
Signed-off-by Vignesh Raghavendra <[email protected]>---
This issue was present in the original driver under SPI NOR framework as well. But only got exposed as driver started handling probe deferral for DMA channel request and thus uses DMA almost always unlike before.
...you rather want
935da5e5100f57d843cac4781b21f1c235059aa0then.
Actually, the offending code is actually from
commit ffa639e069fb ("mtd: spi-nor: cadence-quadspi: Add DMA support for direct mode reads) which adds dma_{un}map_single() calls.
Will send v2 with Fixes tag updated to point to above commit
Quoted 3 lines
Other than that:
Tested-by Jan Kiszka <[email protected]>
Thanks!
Regards
Vignesh
Quoted 42 lines
Thanks!
JanQuoted 37 lines
drivers/spi/spi-cadence-quadspi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/spi/spi-cadence-quadspi.c +5
-3@@ -907,14 +907,16 @@ static int cqspi_direct_read_execute(struct cqspi_flash_pdata *f_pdata,struct dma_async_tx_descriptor *tx;dma_cookie_t cookie;dma_addr_t dma_dst; +struct device *ddev;if (!cqspi->rx_chan || !virt_addr_valid (buf)) {memcpy_fromio (buf, cqspi->ahb_base + from, len);return 0 ; } - dma_dst =dma_map_single (dev, buf, len,DMA_FROM_DEVICE ); -if (dma_mapping_error (dev, dma_dst)) { + ddev = cqspi->rx_chan->device->dev; + dma_dst =dma_map_single (ddev, buf, len,DMA_FROM_DEVICE ); +if (dma_mapping_error (ddev, dma_dst)) {dev_err (dev,"dma mapping failed\n" );return -ENOMEM ; }@@ -948,7 +950,7 @@ static int cqspi_direct_read_execute(struct cqspi_flash_pdata *f_pdata, } err_unmap: -dma_unmap_single (dev, dma_dst, len,DMA_FROM_DEVICE ); +dma_unmap_single (ddev, dma_dst, len,DMA_FROM_DEVICE );return ret; }