Skip to content

Commit 0941d51

Browse files
geertubroonie
authored andcommitted
spi: sh-msiof: Fix maximum DMA transfer size
The maximum amount of data to transfer in a single DMA request is calculated from the FIFO sizes (which is technically not 100% correct, but a simplification, as it is limited by the maximum word count values in the Transmit and Control Data Registers). However, in case there is both data to transmit and to receive, the transmit limit is overwritten by the receive limit. Fix this by using the minimum applicable FIFO size instead. Move the calculation outside the loop, so it is not repeated for each individual DMA transfer. As currently tx_fifo_size is always equal to rx_fifo_size, this bug had no real impact. Fixes: fe78d0b ("spi: sh-msiof: Fix FIFO size to 64 word from 256 word") Signed-off-by: Geert Uytterhoeven <[email protected]> Link: https://patch.msgid.link/d9961767a97758b2614f2ee8afe1bd56dc900a60.1747401908.git.geert+renesas@glider.be Signed-off-by: Mark Brown <[email protected]>
1 parent ee44d3f commit 0941d51

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

drivers/spi/spi-sh-msiof.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,7 @@ static int sh_msiof_transfer_one(struct spi_controller *ctlr,
919919
void *rx_buf = t->rx_buf;
920920
unsigned int len = t->len;
921921
unsigned int bits = t->bits_per_word;
922+
unsigned int max_wdlen = 256;
922923
unsigned int bytes_per_word;
923924
unsigned int words;
924925
int n;
@@ -932,17 +933,17 @@ static int sh_msiof_transfer_one(struct spi_controller *ctlr,
932933
if (!spi_controller_is_target(p->ctlr))
933934
sh_msiof_spi_set_clk_regs(p, t);
934935

936+
if (tx_buf)
937+
max_wdlen = min(max_wdlen, p->tx_fifo_size);
938+
if (rx_buf)
939+
max_wdlen = min(max_wdlen, p->rx_fifo_size);
940+
935941
while (ctlr->dma_tx && len > 15) {
936942
/*
937943
* DMA supports 32-bit words only, hence pack 8-bit and 16-bit
938944
* words, with byte resp. word swapping.
939945
*/
940-
unsigned int l = 0;
941-
942-
if (tx_buf)
943-
l = min(round_down(len, 4), p->tx_fifo_size * 4);
944-
if (rx_buf)
945-
l = min(round_down(len, 4), p->rx_fifo_size * 4);
946+
unsigned int l = min(round_down(len, 4), max_wdlen * 4);
946947

947948
if (bits <= 8) {
948949
copy32 = copy_bswap32;

0 commit comments

Comments
 (0)