Skip to content

Commit bd6d66f

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 a8fd277 commit bd6d66f

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
@@ -458,6 +458,7 @@ typedef struct {
458458
Fifo8 chr_fifo; /* QEMU protocol input FIFO */
459459
uint8_t mode; /* Polarity/phase mismatch */
460460
bool release; /* Whether to release /CS on last byte */
461+
bool failed_transaction; /* Whether to discard until /CS is deasserted */
461462
bool rev_rx; /* Reverse RX bits */
462463
bool rev_tx; /* Reverse TX bits */
463464
} SpiDeviceBus;
@@ -876,6 +877,7 @@ static void ot_spi_device_release(OtSPIDeviceState *s)
876877

877878
BUS_CHANGE_STATE(s, IDLE);
878879
bus->byte_count = 0u;
880+
bus->failed_transaction = false;
879881

880882
bool update_irq = false;
881883
switch (ot_spi_device_get_mode(s)) {
@@ -2028,6 +2030,12 @@ static void ot_spi_device_chr_handle_header(OtSPIDeviceState *s)
20282030
return;
20292031
}
20302032

2033+
/* discard the packet if we're within a failed transaction */
2034+
if (bus->failed_transaction) {
2035+
BUS_CHANGE_STATE(s, DISCARD);
2036+
return;
2037+
}
2038+
20312039
/* @todo: Check that the tpm chip-select was assigned.*/
20322040
if (ot_spi_device_is_tpm_enabled(s)) {
20332041
ot_spi_device_tpm_init_buffers(s);
@@ -2292,6 +2300,8 @@ static void ot_spi_device_chr_receive(void *opaque, const uint8_t *buf,
22922300
case SPI_BUS_DISCARD:
22932301
case SPI_BUS_ERROR:
22942302
ot_spi_device_chr_recv_discard(s, buf, (unsigned)size);
2303+
/* we need to discard the other packets in this transaction */
2304+
bus->failed_transaction = true;
22952305
break;
22962306
default:
22972307
g_assert_not_reached();

0 commit comments

Comments
 (0)