Skip to content

Commit fbb618e

Browse files
james-c-linarobroonie
authored andcommitted
spi: spi-fsl-dspi: Use whole page for DMA buffers
dma_alloc_noncoherent() allocations are backed by a full page anyway, so use it all. VF610 devices used to use the full page before commit a957499 ("spi: spi-fsl-dspi: Fix bits-per-word acceleration in DMA mode"), but others still used the FIFO size. After that commit, all devices used the FIFO size. Now all devices use the full page. Signed-off-by: James Clark <james.clark@linaro.org> Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com> Message-ID: <20250902-james-nxp-spi-dma-v6-5-f7aa2c5e56e2@linaro.org> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 36db0b0 commit fbb618e

1 file changed

Lines changed: 30 additions & 11 deletions

File tree

drivers/spi/spi-fsl-dspi.c

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ struct fsl_dspi_dma {
331331
dma_addr_t rx_dma_phys;
332332
struct completion cmd_rx_complete;
333333
struct dma_async_tx_descriptor *rx_desc;
334+
335+
size_t bufsize;
334336
};
335337

336338
struct fsl_dspi {
@@ -493,6 +495,24 @@ static u32 dspi_pop_tx_pushr(struct fsl_dspi *dspi)
493495
return cmd << 16 | data;
494496
}
495497

498+
static size_t dspi_dma_max_datawords(struct fsl_dspi *dspi)
499+
{
500+
/*
501+
* Transfers look like one of these, so we always use a full DMA word
502+
* regardless of SPI word size:
503+
*
504+
* 31 16 15 0
505+
* -----------------------------------------
506+
* | CONTROL WORD | 16-bit DATA |
507+
* -----------------------------------------
508+
* or
509+
* -----------------------------------------
510+
* | CONTROL WORD | UNUSED | 8-bit DATA |
511+
* -----------------------------------------
512+
*/
513+
return dspi->dma->bufsize / DMA_SLAVE_BUSWIDTH_4_BYTES;
514+
}
515+
496516
static size_t dspi_dma_transfer_size(struct fsl_dspi *dspi)
497517
{
498518
return dspi->words_in_flight * DMA_SLAVE_BUSWIDTH_4_BYTES;
@@ -620,9 +640,8 @@ static void dspi_dma_xfer(struct fsl_dspi *dspi)
620640
/* Figure out operational bits-per-word for this chunk */
621641
dspi_setup_accel(dspi);
622642

623-
dspi->words_in_flight = dspi->len / dspi->oper_word_size;
624-
if (dspi->words_in_flight > dspi->devtype_data->fifo_size)
625-
dspi->words_in_flight = dspi->devtype_data->fifo_size;
643+
dspi->words_in_flight = min(dspi->len / dspi->oper_word_size,
644+
dspi_dma_max_datawords(dspi));
626645

627646
message->actual_length += dspi->words_in_flight *
628647
dspi->oper_word_size;
@@ -637,7 +656,6 @@ static void dspi_dma_xfer(struct fsl_dspi *dspi)
637656

638657
static int dspi_request_dma(struct fsl_dspi *dspi, phys_addr_t phy_addr)
639658
{
640-
int dma_bufsize = dspi->devtype_data->fifo_size * 2;
641659
struct device *dev = &dspi->pdev->dev;
642660
struct dma_slave_config cfg;
643661
struct fsl_dspi_dma *dma;
@@ -657,16 +675,18 @@ static int dspi_request_dma(struct fsl_dspi *dspi, phys_addr_t phy_addr)
657675
goto err_tx_channel;
658676
}
659677

678+
dma->bufsize = PAGE_SIZE;
679+
660680
dma->tx_dma_buf = dma_alloc_noncoherent(dma->chan_tx->device->dev,
661-
dma_bufsize, &dma->tx_dma_phys,
681+
dma->bufsize, &dma->tx_dma_phys,
662682
DMA_TO_DEVICE, GFP_KERNEL);
663683
if (!dma->tx_dma_buf) {
664684
ret = -ENOMEM;
665685
goto err_tx_dma_buf;
666686
}
667687

668688
dma->rx_dma_buf = dma_alloc_noncoherent(dma->chan_rx->device->dev,
669-
dma_bufsize, &dma->rx_dma_phys,
689+
dma->bufsize, &dma->rx_dma_phys,
670690
DMA_FROM_DEVICE, GFP_KERNEL);
671691
if (!dma->rx_dma_buf) {
672692
ret = -ENOMEM;
@@ -702,11 +722,11 @@ static int dspi_request_dma(struct fsl_dspi *dspi, phys_addr_t phy_addr)
702722
return 0;
703723

704724
err_slave_config:
705-
dma_free_noncoherent(dma->chan_rx->device->dev, dma_bufsize,
725+
dma_free_noncoherent(dma->chan_rx->device->dev, dma->bufsize,
706726
dma->rx_dma_buf, dma->rx_dma_phys,
707727
DMA_FROM_DEVICE);
708728
err_rx_dma_buf:
709-
dma_free_noncoherent(dma->chan_tx->device->dev, dma_bufsize,
729+
dma_free_noncoherent(dma->chan_tx->device->dev, dma->bufsize,
710730
dma->tx_dma_buf, dma->tx_dma_phys, DMA_TO_DEVICE);
711731
err_tx_dma_buf:
712732
dma_release_channel(dma->chan_tx);
@@ -721,21 +741,20 @@ static int dspi_request_dma(struct fsl_dspi *dspi, phys_addr_t phy_addr)
721741

722742
static void dspi_release_dma(struct fsl_dspi *dspi)
723743
{
724-
int dma_bufsize = dspi->devtype_data->fifo_size * 2;
725744
struct fsl_dspi_dma *dma = dspi->dma;
726745

727746
if (!dma)
728747
return;
729748

730749
if (dma->chan_tx) {
731-
dma_free_noncoherent(dma->chan_tx->device->dev, dma_bufsize,
750+
dma_free_noncoherent(dma->chan_tx->device->dev, dma->bufsize,
732751
dma->tx_dma_buf, dma->tx_dma_phys,
733752
DMA_TO_DEVICE);
734753
dma_release_channel(dma->chan_tx);
735754
}
736755

737756
if (dma->chan_rx) {
738-
dma_free_noncoherent(dma->chan_rx->device->dev, dma_bufsize,
757+
dma_free_noncoherent(dma->chan_rx->device->dev, dma->bufsize,
739758
dma->rx_dma_buf, dma->rx_dma_phys,
740759
DMA_FROM_DEVICE);
741760
dma_release_channel(dma->chan_rx);

0 commit comments

Comments
 (0)