spi: sh-msiof: Fix maximum DMA transfer size

[ Upstream commit 0941d5166629cb766000530945e54b4e49680c68 ]

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: fe78d0b769 ("spi: sh-msiof: Fix FIFO size to 64 word from 256 word")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://patch.msgid.link/d9961767a97758b2614f2ee8afe1bd56dc900a60.1747401908.git.geert+renesas@glider.be
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Geert Uytterhoeven
2025-05-16 15:32:06 +02:00
committed by Greg Kroah-Hartman
parent 5174ac310a
commit 42f7dd4bf5

View File

@@ -918,6 +918,7 @@ static int sh_msiof_transfer_one(struct spi_controller *ctlr,
void *rx_buf = t->rx_buf; void *rx_buf = t->rx_buf;
unsigned int len = t->len; unsigned int len = t->len;
unsigned int bits = t->bits_per_word; unsigned int bits = t->bits_per_word;
unsigned int max_wdlen = 256;
unsigned int bytes_per_word; unsigned int bytes_per_word;
unsigned int words; unsigned int words;
int n; int n;
@@ -931,17 +932,17 @@ static int sh_msiof_transfer_one(struct spi_controller *ctlr,
if (!spi_controller_is_target(p->ctlr)) if (!spi_controller_is_target(p->ctlr))
sh_msiof_spi_set_clk_regs(p, t); sh_msiof_spi_set_clk_regs(p, t);
if (tx_buf)
max_wdlen = min(max_wdlen, p->tx_fifo_size);
if (rx_buf)
max_wdlen = min(max_wdlen, p->rx_fifo_size);
while (ctlr->dma_tx && len > 15) { while (ctlr->dma_tx && len > 15) {
/* /*
* DMA supports 32-bit words only, hence pack 8-bit and 16-bit * DMA supports 32-bit words only, hence pack 8-bit and 16-bit
* words, with byte resp. word swapping. * words, with byte resp. word swapping.
*/ */
unsigned int l = 0; unsigned int l = min(round_down(len, 4), max_wdlen * 4);
if (tx_buf)
l = min(round_down(len, 4), p->tx_fifo_size * 4);
if (rx_buf)
l = min(round_down(len, 4), p->rx_fifo_size * 4);
if (bits <= 8) { if (bits <= 8) {
copy32 = copy_bswap32; copy32 = copy_bswap32;