Skip to content

Commit

Permalink
spi: spi-cadence: Reverse the order of interleaved write and read ope…
Browse files Browse the repository at this point in the history
…rations

In the existing implementation, when executing interleaved write and read
operations in the ISR for a transfer length greater than the FIFO size,
the TXFIFO write precedes the RXFIFO read. Consequently, the initially
received data in the RXFIFO is pushed out and lost, leading to a failure
in data integrity. To address this issue, reverse the order of interleaved
operations and conduct the RXFIFO read followed by the TXFIFO write.

Fixes: 6afe2ae ("spi: spi-cadence: Interleave write of TX and read of RX FIFO")
Signed-off-by: Amit Kumar Mahapatra <amit.kumar-mahapatra@amd.com>
Link: https://msgid.link/r/20231218090652.18403-1-amit.kumar-mahapatra@amd.com
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Amit Kumar Mahapatra authored and Mark Brown committed Jan 23, 2024
1 parent e267a5b commit 633cd6f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions drivers/spi/spi-cadence.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,15 @@ static void cdns_spi_process_fifo(struct cdns_spi *xspi, int ntx, int nrx)
xspi->rx_bytes -= nrx;

while (ntx || nrx) {
if (nrx) {
u8 data = cdns_spi_read(xspi, CDNS_SPI_RXD);

if (xspi->rxbuf)
*xspi->rxbuf++ = data;

nrx--;
}

if (ntx) {
if (xspi->txbuf)
cdns_spi_write(xspi, CDNS_SPI_TXD, *xspi->txbuf++);
Expand All @@ -326,14 +335,6 @@ static void cdns_spi_process_fifo(struct cdns_spi *xspi, int ntx, int nrx)
ntx--;
}

if (nrx) {
u8 data = cdns_spi_read(xspi, CDNS_SPI_RXD);

if (xspi->rxbuf)
*xspi->rxbuf++ = data;

nrx--;
}
}
}

Expand Down

0 comments on commit 633cd6f

Please sign in to comment.