tpm_crb_ffa: handle tpm busy return code
authorPrachotan Bathi <prachotan.bathi@arm.com>
Tue, 8 Jul 2025 22:51:51 +0000 (17:51 -0500)
committerJarkko Sakkinen <jarkko@kernel.org>
Tue, 22 Jul 2025 23:32:00 +0000 (02:32 +0300)
commit7f0c6675b3194461ad7bb8db1d822445121fb029
tree93823d9b2d5533515e585a454c0014fd17271dd4
parent586dafcdbc5004266a74bc280281e4ee92488633
tpm_crb_ffa: handle tpm busy return code

Platforms supporting direct message request v2 [1] can support secure
partitions that support multiple services. For CRB over FF-A interface,
if the firmware TPM or TPM service [1] shares its Secure Partition (SP)
with another service, message requests may fail with a -EBUSY error.

To handle this, replace the single check and call with a retry loop
that attempts the TPM message send operation until it succeeds or a
configurable timeout is reached. Implement a _try_send_receive function
to do a single send/receive and modify the existing send_receive to
add this retry loop.
The retry mechanism introduces a module parameter (`busy_timeout_ms`,
default: 2000ms) to control how long to keep retrying on -EBUSY
responses. Between retries, the code waits briefly (50-100 microseconds)
to avoid busy-waiting and handling TPM BUSY conditions more gracefully.

The parameter can be modified at run-time as such:
echo 3000 | tee /sys/module/tpm_crb_ffa/parameters/busy_timeout_ms
This changes the timeout from the default 2000ms to 3000ms.

[1] TPM Service Command Response Buffer Interface Over FF-A
https://developer.arm.com/documentation/den0138/latest/

Signed-off-by: Prachotan Bathi <prachotan.bathi@arm.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Documentation/admin-guide/kernel-parameters.txt
drivers/char/tpm/tpm_crb_ffa.c