spi: pxa2xx: handle error of pxa2xx_spi_dma_prepare()
Subsystems (3)
PATCH v2 1/3 spi: pxa2xx: handle error of pxa2xx_spi_dma_prepare()
From: Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]>
If by some reason pxa2xx_spi_dma_prepare() fails we have not to ignore its error. In such case we abort the transfer and return the error to upper level.
[Jarkko: Avoid leaking TX descriptors in case RX descriptor allocation fails. Noted by Robert Jarzmik <[email protected]>. Unmap also buffers in case of failure.]
---
Reposting Andy's fix from December that got buried to list during holidays.
--- drivers/spi/spi-pxa2xx-dma.c | 13 +++++++++++-- drivers/spi/spi-pxa2xx.c | 8 +++++++- 2 files changed, 18 insertions(+), 3 deletions(-)
drivers/spi/spi-pxa2xx-dma.c +11 -2
@@ -267,19 +267,22 @@ irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data)int pxa2xx_spi_dma_prepare (struct driver_data *drv_data,u32 dma_burst) {struct dma_async_tx_descriptor *tx_desc, *rx_desc; +int err =0 ; tx_desc =pxa2xx_spi_dma_prepare_one (drv_data,DMA_MEM_TO_DEV );if (!tx_desc) {dev_err (&drv_data->pdev->dev,"failed to get DMA TX descriptor\n" ); -return -EBUSY ; + err = -EBUSY ; + goto err_tx; } rx_desc =pxa2xx_spi_dma_prepare_one (drv_data,DMA_DEV_TO_MEM );if (!rx_desc) {dev_err (&drv_data->pdev->dev,"failed to get DMA RX descriptor\n" ); -return -EBUSY ; + err = -EBUSY ; + goto err_rx; }/* We are ready when RX completes */
@@ -289,6 +292,12 @@ int pxa2xx_spi_dma_prepare(struct driver_data *drv_data, u32 dma_burst)dmaengine_submit (rx_desc);dmaengine_submit (tx_desc);return 0 ; + +err_rx: +dmaengine_terminate_async (drv_data->tx_chan); +err_tx: +pxa2xx_spi_unmap_dma_buffers (drv_data); +return err; }void pxa2xx_spi_dma_start (struct driver_data *drv_data)
drivers/spi/spi-pxa2xx.c +7 -1
@@ -928,6 +928,7 @@ static void pump_transfers(unsigned long data)u32 dma_thresh = drv_data->cur_chip->dma_threshold;u32 dma_burst = drv_data->cur_chip->dma_burst_size;u32 change_mask =pxa2xx_spi_get_ssrc1_change_mask (drv_data); +int err;/* Get current state information */ message = drv_data->cur_msg;
@@ -1047,7 +1048,12 @@ static void pump_transfers(unsigned long data)/* Ensure we have the correct interrupt handler */ drv_data->transfer_handler = pxa2xx_spi_dma_transfer; -pxa2xx_spi_dma_prepare (drv_data, dma_burst); + err =pxa2xx_spi_dma_prepare (drv_data, dma_burst); +if (err) { + message->status = err; +giveback (drv_data); +return ; + }/* Clear status and start DMA engine */ cr1 = chip->cr1 | dma_thresh | drv_data->dma_cr1;
Signature · 6 lines
2.8.0.rc3 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 1458826544-28553-1-git-send-email-jarkko.nikula-VuQAYsv1563Yd54FQh9/[email protected]
PATCH v2 2/3 spi: pxa2xx: Remove rx_/tx_map_len members from struct driver_data
spi-pxa2xx-dma.c DMA engine implementation stopped using PIO for unaligned trailing bytes in the commit 111e0a9dc71e ("spi/pxa2xx: Prevent DMA from transferring too many bytes"). This means there is no need to update tx/rx transfer buffer pointers after DMA completion. These buffer pointers will be set to new buffers when handling the next transfer.
Because this buffer pointer update was only remaining use for rx_map_len and tx_map_len members in struct driver_data after removing the legacy PXA DMA implementation they can be removed now.
--- drivers/spi/spi-pxa2xx-dma.c | 5 ----- drivers/spi/spi-pxa2xx.h | 2 -- 2 files changed, 7 deletions(-)
drivers/spi/spi-pxa2xx-dma.c +0 -5
@@ -33,12 +33,10 @@ static int pxa2xx_spi_map_dma_buffer(struct driver_data *drv_data, dmadev = drv_data->tx_chan->device->dev; sgt = &drv_data->tx_sgt; buf = drv_data->tx; - drv_data->tx_map_len = len; }else { dmadev = drv_data->rx_chan->device->dev; sgt = &drv_data->rx_sgt; buf = drv_data->rx; - drv_data->rx_map_len = len; } nents =DIV_ROUND_UP (len,SZ_2K );
@@ -133,9 +131,6 @@ static void pxa2xx_spi_dma_transfer_complete(struct driver_data *drv_data,if (!error) {pxa2xx_spi_unmap_dma_buffers (drv_data); - drv_data->tx += drv_data->tx_map_len; - drv_data->rx += drv_data->rx_map_len; - msg->actual_length += drv_data->len; msg->state =pxa2xx_spi_next_transfer (drv_data); }else {
drivers/spi/spi-pxa2xx.h +0 -2
@@ -69,8 +69,6 @@ struct driver_data {void *rx;void *rx_end;int dma_mapped; -size_t rx_map_len; -size_t tx_map_len;u8 n_bytes;int (*write)(struct driver_data *drv_data);int (*read)(struct driver_data *drv_data);
Signature · 6 lines
2.8.0.rc3 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 3/3 spi: pxa2xx: Use dummy buffers provided by SPI core
In reply to a message not in the archiveDummy buffer is used for half duplex transfers that don't have TX or RX buffer set. Instead of own dummy buffer management here let the SPI core to handle it by setting the SPI_MASTER_MUST_RX and SPI_MASTER_MUST_TX flags. Then core makes sure both transfer buffers are set.
--- drivers/spi/spi-pxa2xx-dma.c | 10 +--------- drivers/spi/spi-pxa2xx.c | 1 + drivers/spi/spi-pxa2xx.h | 1 - 3 files changed, 2 insertions(+), 10 deletions(-)
drivers/spi/spi-pxa2xx-dma.c +1 -9
@@ -53,11 +53,7 @@ static int pxa2xx_spi_map_dma_buffer(struct driver_data *drv_data,for_each_sg (sgt->sgl, sg, sgt->nents, i) {size_t bytes =min_t (size_t, len,SZ_2K ); -if (buf) -sg_set_buf (sg, pbuf, bytes); -else -sg_set_buf (sg, drv_data->dummy, bytes); - +sg_set_buf (sg, pbuf, bytes); pbuf += bytes; len -= bytes; }
@@ -312,10 +308,6 @@ int pxa2xx_spi_dma_setup(struct driver_data *drv_data)dma_cap_zero (mask);dma_cap_set (DMA_SLAVE , mask); - drv_data->dummy =devm_kzalloc (dev,SZ_2K ,GFP_KERNEL ); -if (!drv_data->dummy) -return -ENOMEM ; - drv_data->tx_chan =dma_request_slave_channel_compat (mask, pdata->dma_filter, pdata->tx_param, dev,"tx" );if (!drv_data->tx_chan)
drivers/spi/spi-pxa2xx.c +1 -0
@@ -1562,6 +1562,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) master->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer; master->fw_translate_cs = pxa2xx_spi_fw_translate_cs; master->auto_runtime_pm = true; + master->flags =SPI_MASTER_MUST_RX |SPI_MASTER_MUST_TX ; drv_data->ssp_type = ssp->type;
drivers/spi/spi-pxa2xx.h +0 -1
@@ -56,7 +56,6 @@ struct driver_data {struct sg_table tx_sgt;int rx_nents;int tx_nents; -void *dummy;atomic_t dma_running;/* Current message transfer state info */
Signature · 6 lines
2.8.0.rc3 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Robert Jarzmik
Acked-byQuoted 10 lines · Jarkko Nikula
From: Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]>
If by some reason
pxa2xx_spi_dma_prepare()fails we have not to ignore its error. In such case we abort the transfer and return the error to upper level.[Jarkko: Avoid leaking TX descriptors in case RX descriptor allocation fails. Noted by Robert Jarzmik <[email protected]>. Unmap also buffers in case of failure.]
Quoted 8 lines
---
Reposting Andy's fix from December that got buried to list during holidays.--- drivers/spi/spi-pxa2xx-dma.c | 13 +++++++++++-- drivers/spi/spi-pxa2xx.c | 8 +++++++- 2 files changed, 18 insertions(+), 3 deletions(-)
Cheers.
Signature · 5 lines
Robert -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Applied "spi: pxa2xx: handle error of pxa2xx_spi_dma_prepare()" to the spi tree
In reply to a message not in the archiveThe patch
spi: pxa2xx: handle error of pxa2xx_spi_dma_prepare()
has been applied to the spi tree at
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
7d1f1bf699efc9b0f0e92c910dc667a4511943f5Mon Sep 17 00:00:00 2001
From: Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]>
Date: Thu, 24 Mar 2016 15:35:42 +0200
Subject: [PATCH] spi: pxa2xx: handle error of pxa2xx_spi_dma_prepare()
If by some reason pxa2xx_spi_dma_prepare() fails we have not to ignore its error. In such case we abort the transfer and return the error to upper level.
[Jarkko: Avoid leaking TX descriptors in case RX descriptor allocation fails. Noted by Robert Jarzmik <[email protected]>. Unmap also buffers in case of failure.]
--- drivers/spi/spi-pxa2xx-dma.c | 13 +++++++++++-- drivers/spi/spi-pxa2xx.c | 8 +++++++- 2 files changed, 18 insertions(+), 3 deletions(-)
drivers/spi/spi-pxa2xx-dma.c +11 -2
@@ -267,19 +267,22 @@ irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data)int pxa2xx_spi_dma_prepare (struct driver_data *drv_data,u32 dma_burst) {struct dma_async_tx_descriptor *tx_desc, *rx_desc; +int err =0 ; tx_desc =pxa2xx_spi_dma_prepare_one (drv_data,DMA_MEM_TO_DEV );if (!tx_desc) {dev_err (&drv_data->pdev->dev,"failed to get DMA TX descriptor\n" ); -return -EBUSY ; + err = -EBUSY ; + goto err_tx; } rx_desc =pxa2xx_spi_dma_prepare_one (drv_data,DMA_DEV_TO_MEM );if (!rx_desc) {dev_err (&drv_data->pdev->dev,"failed to get DMA RX descriptor\n" ); -return -EBUSY ; + err = -EBUSY ; + goto err_rx; }/* We are ready when RX completes */
@@ -289,6 +292,12 @@ int pxa2xx_spi_dma_prepare(struct driver_data *drv_data, u32 dma_burst)dmaengine_submit (rx_desc);dmaengine_submit (tx_desc);return 0 ; + +err_rx: +dmaengine_terminate_async (drv_data->tx_chan); +err_tx: +pxa2xx_spi_unmap_dma_buffers (drv_data); +return err; }void pxa2xx_spi_dma_start (struct driver_data *drv_data)
drivers/spi/spi-pxa2xx.c +7 -1
@@ -928,6 +928,7 @@ static void pump_transfers(unsigned long data)u32 dma_thresh = drv_data->cur_chip->dma_threshold;u32 dma_burst = drv_data->cur_chip->dma_burst_size;u32 change_mask =pxa2xx_spi_get_ssrc1_change_mask (drv_data); +int err;/* Get current state information */ message = drv_data->cur_msg;
@@ -1047,7 +1048,12 @@ static void pump_transfers(unsigned long data)/* Ensure we have the correct interrupt handler */ drv_data->transfer_handler = pxa2xx_spi_dma_transfer; -pxa2xx_spi_dma_prepare (drv_data, dma_burst); + err =pxa2xx_spi_dma_prepare (drv_data, dma_burst); +if (err) { + message->status = err; +giveback (drv_data); +return ; + }/* Clear status and start DMA engine */ cr1 = chip->cr1 | dma_thresh | drv_data->dma_cr1;
Signature · 6 lines
2.8.0.rc3 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html