Skip to content

Commit 9109cba

Browse files
committed
[ot] hw/opentitan: spi_device: discard all packets in failed transaction
If one packet in a transaction triggers an error and needs discarding, we must continue discarding the remaining packets until CS is released. Signed-off-by: James Wainwright <[email protected]>
1 parent 61c4166 commit 9109cba

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

hw/opentitan/ot_spi_device.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ typedef struct {
419419
Fifo8 chr_fifo; /* QEMU protocol input FIFO */
420420
uint8_t mode; /* Polarity/phase mismatch */
421421
bool release; /* Whether to release /CS on last byte */
422+
bool failed_transaction; /* Whether to discard until /CS is deasserted */
422423
bool rev_rx; /* Reverse RX bits */
423424
bool rev_tx; /* Reverse TX bits */
424425
} SpiDeviceBus;
@@ -801,6 +802,7 @@ static void ot_spi_device_release(OtSPIDeviceState *s)
801802

802803
BUS_CHANGE_STATE(s, IDLE);
803804
bus->byte_count = 0;
805+
bus->failed_transaction = false;
804806

805807
bool update_irq = false;
806808
switch (ot_spi_device_get_mode(s)) {
@@ -1924,6 +1926,12 @@ static void ot_spi_device_chr_handle_header(OtSPIDeviceState *s)
19241926
return;
19251927
}
19261928

1929+
/* discard the packet if we're within a failed transaction */
1930+
if (bus->failed_transaction) {
1931+
BUS_CHANGE_STATE(s, DISCARD);
1932+
return;
1933+
}
1934+
19271935
switch (ot_spi_device_get_mode(s)) {
19281936
case CTRL_MODE_FLASH:
19291937
BUS_CHANGE_STATE(s, FLASH);
@@ -2028,6 +2036,8 @@ static void ot_spi_device_chr_receive(void *opaque, const uint8_t *buf,
20282036
case SPI_BUS_DISCARD:
20292037
case SPI_BUS_ERROR:
20302038
ot_spi_device_chr_recv_discard(s, buf, (unsigned)size);
2039+
/* we need to discard the other packets in this transaction */
2040+
bus->failed_transaction = true;
20312041
break;
20322042
default:
20332043
g_assert_not_reached();

0 commit comments

Comments
 (0)