Skip to content

Commit 502a582

Browse files
nagasureshmchpbroonie
authored andcommitted
spi: microchip-core: fix the issues in the isr
It is possible for the TXDONE interrupt be raised if the tx FIFO becomes temporarily empty while transmitting, resulting in recursive calls to mchp_corespi_write_fifo() and therefore a garbage message might be transmitted depending on when the interrupt is triggered. Moving all of the tx FIFO writes out of the TXDONE portion of the interrupt handler avoids this problem. Most of rest of the TXDONE portion of the handler is problematic too. Only reading the rx FIFO (and finalising the transfer) when the TXDONE interrupt is raised can cause the transfer to stall, if the final bytes of rx data are not available in the rx FIFO when the final TXDONE interrupt is raised. The transfer should be finalised regardless of which interrupt is raised, provided that all tx data has been set and all rx data received. The first issue was encountered "in the wild", the second is theoretical. Fixes: 9ac8d17 ("spi: add support for microchip fpga spi controllers") Signed-off-by: Naga Sureshkumar Relli <[email protected]> Signed-off-by: Conor Dooley <[email protected]> Link: https://patch.msgid.link/20240715-candied-deforest-585685ef3c8a@wendy Signed-off-by: Mark Brown <[email protected]>
1 parent 3048dc8 commit 502a582

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

drivers/spi/spi-microchip-core.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -383,21 +383,18 @@ static irqreturn_t mchp_corespi_interrupt(int irq, void *dev_id)
383383
if (intfield == 0)
384384
return IRQ_NONE;
385385

386-
if (intfield & INT_TXDONE) {
386+
if (intfield & INT_TXDONE)
387387
mchp_corespi_write(spi, REG_INT_CLEAR, INT_TXDONE);
388388

389+
if (intfield & INT_RXRDY) {
390+
mchp_corespi_write(spi, REG_INT_CLEAR, INT_RXRDY);
391+
389392
if (spi->rx_len)
390393
mchp_corespi_read_fifo(spi);
391-
392-
if (spi->tx_len)
393-
mchp_corespi_write_fifo(spi);
394-
395-
if (!spi->rx_len)
396-
finalise = true;
397394
}
398395

399-
if (intfield & INT_RXRDY)
400-
mchp_corespi_write(spi, REG_INT_CLEAR, INT_RXRDY);
396+
if (!spi->rx_len && !spi->tx_len)
397+
finalise = true;
401398

402399
if (intfield & INT_RX_CHANNEL_OVERFLOW) {
403400
mchp_corespi_write(spi, REG_INT_CLEAR, INT_RX_CHANNEL_OVERFLOW);
@@ -482,8 +479,9 @@ static int mchp_corespi_transfer_one(struct spi_controller *host,
482479
mchp_corespi_set_xfer_size(spi, (spi->tx_len > FIFO_DEPTH)
483480
? FIFO_DEPTH : spi->tx_len);
484481

485-
if (spi->tx_len)
482+
while (spi->tx_len)
486483
mchp_corespi_write_fifo(spi);
484+
487485
return 1;
488486
}
489487

0 commit comments

Comments
 (0)