Skip to content

Fix timeouts for operations over spidev#205

Open
xorptr wants to merge 1 commit intogoogle:mainfrom
xorptr:fix_spidev_timeouts
Open

Fix timeouts for operations over spidev#205
xorptr wants to merge 1 commit intogoogle:mainfrom
xorptr:fix_spidev_timeouts

Conversation

@xorptr
Copy link
Collaborator

@xorptr xorptr commented Feb 6, 2026

  • Rename spidev_device_busy_wait_timeout to spidev_page_program_busy_wait_timeout to indicate that the timeout is explicitly for page program operations over spidev
  • Change spidev_page_program_busy_wait_timeout to take timeout in milliseconds
  • Change timeout behavior for spidev so that timeout value of 0 indicates indefinite wait
  • Change timeout behavior for spidev so that spidev_page_program_busy_wait_timeout affects only the waits during intermediate page programs. After the final page program operation, timeout_ms argument from libhoth_spi_receive_response is used to wait for appropriate amount of time requested for host command execution

- Rename `spidev_device_busy_wait_timeout` to `spidev_page_program_busy_wait_timeout` to indicate that the timeout is explicitly for page program operations over spidev
- Change `spidev_page_program_busy_wait_timeout` to take timeout in milliseconds
- Change timeout behavior for spidev so that timeout value of 0 indicates indefinite wait
- Change timeout behavior for spidev so that `spidev_page_program_busy_wait_timeout` affects only the waits during intermediate page programs. After the final page program operation, `timeout_ms` argument from `libhoth_spi_receive_response` is used to wait for appropriate amount of time requested for host command execution
@xorptr xorptr force-pushed the fix_spidev_timeouts branch from 370d644 to 17bf6c7 Compare February 6, 2026 00:33
// handled except the last one. Waiting for the last page program will be
// done in `libhoth_spi_receive_response` since RoT will take some time to
// execute the host command
libhoth_status busy_wait_status = spi_nor_busy_wait(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the previous htool invocation was interrupted during host command execution, the timeout here may be insufficient. Currently this covers only the case if the previous invocation was interrupted after a intermediate page program operation. Do you folks think that this should handle the first case as well?

@xorptr xorptr requested a review from rkr35 February 6, 2026 00:41
.default_value = "10",
.desc = "Maximum duration (in milliseconds) to wait after a page program "
"command when SPI device indicates that it is busy"},
{HTOOL_FLAG_VALUE, .name = "spidev_device_busy_wait_check_interval",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have one spidev parameter here in ms and one in us. Can we just use the same function that the usb_retry logic uses so that it's clear?


if (time_elapsed_ms > (timeout_us / 1000)) {
return LIBHOTH_ERR_TIMEOUT;
if (timeout_ms != 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really not want to have a timeout at all for this? I think it might make sense to have a maximum of something very high (e.g. 60s?) so that it at least eventually fails and we return the proper timeout error code to the caller.

// - For the first iteration, wait for any previous operations that might
// have set the busy bit to finish
// - For rest of the iterations, wait for each page program operation to be
// handled except the last one. Waiting for the last page program will be
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document what this is for?

I presume what you're going for is that we can send a host command and let it process while doing other things?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants