未验证 提交 89b35e3f 编写于 作者: E Eddie James 提交者: Mark Brown

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: NEddie James <eajames@linux.ibm.com>
Link: https://lore.kernel.org/r/20220317211426.38940-1-eajames@linux.ibm.comSigned-off-by: NMark Brown <broonie@kernel.org>
上级 ebc4cb43
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#define SPI_FSI_BASE 0x70000 #define SPI_FSI_BASE 0x70000
#define SPI_FSI_INIT_TIMEOUT_MS 1000 #define SPI_FSI_INIT_TIMEOUT_MS 1000
#define SPI_FSI_STATUS_TIMEOUT_MS 100
#define SPI_FSI_MAX_RX_SIZE 8 #define SPI_FSI_MAX_RX_SIZE 8
#define SPI_FSI_MAX_TX_SIZE 40 #define SPI_FSI_MAX_TX_SIZE 40
...@@ -299,6 +300,7 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx, ...@@ -299,6 +300,7 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx,
struct spi_transfer *transfer) struct spi_transfer *transfer)
{ {
int rc = 0; int rc = 0;
unsigned long end;
u64 status = 0ULL; u64 status = 0ULL;
if (transfer->tx_buf) { if (transfer->tx_buf) {
...@@ -315,10 +317,14 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx, ...@@ -315,10 +317,14 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx,
if (rc) if (rc)
return rc; return rc;
end = jiffies + msecs_to_jiffies(SPI_FSI_STATUS_TIMEOUT_MS);
do { do {
rc = fsi_spi_status(ctx, &status, "TX"); rc = fsi_spi_status(ctx, &status, "TX");
if (rc) if (rc)
return rc; return rc;
if (time_after(jiffies, end))
return -ETIMEDOUT;
} while (status & SPI_FSI_STATUS_TDR_FULL); } while (status & SPI_FSI_STATUS_TDR_FULL);
sent += nb; sent += nb;
...@@ -329,10 +335,14 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx, ...@@ -329,10 +335,14 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx,
u8 *rx = transfer->rx_buf; u8 *rx = transfer->rx_buf;
while (transfer->len > recv) { while (transfer->len > recv) {
end = jiffies + msecs_to_jiffies(SPI_FSI_STATUS_TIMEOUT_MS);
do { do {
rc = fsi_spi_status(ctx, &status, "RX"); rc = fsi_spi_status(ctx, &status, "RX");
if (rc) if (rc)
return rc; return rc;
if (time_after(jiffies, end))
return -ETIMEDOUT;
} while (!(status & SPI_FSI_STATUS_RDR_FULL)); } while (!(status & SPI_FSI_STATUS_RDR_FULL));
rc = fsi_spi_read_reg(ctx, SPI_FSI_DATA_RX, &in); rc = fsi_spi_read_reg(ctx, SPI_FSI_DATA_RX, &in);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册