Skip to content

Commit 5ae68c6

Browse files
committed
[ot] hw/opentitan: spi_device: always upload payload for SW commands
The SPI device design only considers the `PAYLOAD_EN` bit of a slot for the passthrough mode, not for uploaded flash commands which always upload their payloads. Signed-off-by: James Wainwright <[email protected]>
1 parent 91b1f39 commit 5ae68c6

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

hw/opentitan/ot_spi_device.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -677,12 +677,6 @@ static void ot_spi_device_flash_change_state_line(
677677
}
678678
}
679679

680-
static bool ot_spi_device_flash_has_input_payload(uint32_t cmd_info)
681-
{
682-
return (cmd_info & CMD_INFO_PAYLOAD_EN_MASK) != 0 &&
683-
!(cmd_info & CMD_INFO_PAYLOAD_DIR_MASK);
684-
}
685-
686680
static bool ot_spi_device_flash_is_upload(const SpiDeviceFlash *f)
687681
{
688682
return (f->cmd_info & CMD_INFO_UPLOAD_MASK) != 0 &&
@@ -1296,9 +1290,13 @@ static void ot_spi_device_flash_decode_sw_command(OtSPIDeviceState *s)
12961290
} else if (f->cmd_info & CMD_INFO_DUMMY_EN_MASK) {
12971291
f->len = 1u;
12981292
FLASH_CHANGE_STATE(s, UP_DUMMY);
1299-
} else if (ot_spi_device_flash_has_input_payload(f->cmd_info)) {
1293+
} else if (ot_spi_device_flash_is_upload(f)) {
13001294
ot_spi_device_flash_init_payload(s);
13011295
} else {
1296+
/*
1297+
* Any payload sent with a non-uploaded SW command is ignored. The
1298+
* behaviour of this error case is not well specified for the hardware.
1299+
*/
13021300
s->spi_regs[R_UPLOAD_STATUS2] = 0;
13031301
}
13041302
}
@@ -1328,19 +1326,27 @@ static void ot_spi_device_flash_exec_sw_command(OtSPIDeviceState *s, uint8_t rx)
13281326
if (f->cmd_info & CMD_INFO_DUMMY_EN_MASK) {
13291327
f->len = 1u;
13301328
FLASH_CHANGE_STATE(s, UP_DUMMY);
1331-
} else if (ot_spi_device_flash_has_input_payload(f->cmd_info)) {
1329+
} else if (ot_spi_device_flash_is_upload(f)) {
13321330
ot_spi_device_flash_init_payload(s);
13331331
} else {
1332+
/*
1333+
* Any payload sent with a non-uploaded SW command is ignored. The
1334+
* behaviour of this error case is not well specified for the hardware.
1335+
*/
13341336
FLASH_CHANGE_STATE(s, DONE);
13351337
}
13361338
}
13371339
break;
13381340
case SPI_FLASH_UP_DUMMY:
13391341
f->pos++;
13401342
g_assert(f->pos == f->len);
1341-
if (ot_spi_device_flash_has_input_payload(f->cmd_info)) {
1343+
if (ot_spi_device_flash_is_upload(f)) {
13421344
ot_spi_device_flash_init_payload(s);
13431345
} else {
1346+
/*
1347+
* Any payload sent with a non-uploaded SW command is ignored. The
1348+
* behaviour of this error case is not well specified for the hardware.
1349+
*/
13441350
FLASH_CHANGE_STATE(s, DONE);
13451351
}
13461352
break;

0 commit comments

Comments
 (0)