Skip to content

Commit 89b35e3

Browse files
Eddie Jamesbroonie
authored andcommitted
spi: fsi: Implement a timeout for polling status
The data transfer routines must poll the status register to determine when more data can be shifted in or out. If the hardware gets into a bad state, these polling loops may never exit. Prevent this by returning an error if a timeout is exceeded. Signed-off-by: Eddie James <eajames@linux.ibm.com> Link: https://lore.kernel.org/r/20220317211426.38940-1-eajames@linux.ibm.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent ebc4cb4 commit 89b35e3

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

drivers/spi/spi-fsi.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#define SPI_FSI_BASE 0x70000
2727
#define SPI_FSI_INIT_TIMEOUT_MS 1000
28+
#define SPI_FSI_STATUS_TIMEOUT_MS 100
2829
#define SPI_FSI_MAX_RX_SIZE 8
2930
#define SPI_FSI_MAX_TX_SIZE 40
3031

@@ -299,6 +300,7 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx,
299300
struct spi_transfer *transfer)
300301
{
301302
int rc = 0;
303+
unsigned long end;
302304
u64 status = 0ULL;
303305

304306
if (transfer->tx_buf) {
@@ -315,10 +317,14 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx,
315317
if (rc)
316318
return rc;
317319

320+
end = jiffies + msecs_to_jiffies(SPI_FSI_STATUS_TIMEOUT_MS);
318321
do {
319322
rc = fsi_spi_status(ctx, &status, "TX");
320323
if (rc)
321324
return rc;
325+
326+
if (time_after(jiffies, end))
327+
return -ETIMEDOUT;
322328
} while (status & SPI_FSI_STATUS_TDR_FULL);
323329

324330
sent += nb;
@@ -329,10 +335,14 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx,
329335
u8 *rx = transfer->rx_buf;
330336

331337
while (transfer->len > recv) {
338+
end = jiffies + msecs_to_jiffies(SPI_FSI_STATUS_TIMEOUT_MS);
332339
do {
333340
rc = fsi_spi_status(ctx, &status, "RX");
334341
if (rc)
335342
return rc;
343+
344+
if (time_after(jiffies, end))
345+
return -ETIMEDOUT;
336346
} while (!(status & SPI_FSI_STATUS_RDR_FULL));
337347

338348
rc = fsi_spi_read_reg(ctx, SPI_FSI_DATA_RX, &in);

0 commit comments

Comments
 (0)