Skip to content

Commit 04fe470

Browse files
stefano-garzarellajarkkojs
authored andcommitted
tpm: support devices with synchronous send()
Some devices do not support interrupts and provide a single synchronous operation to send the command and receive the response on the same buffer. Currently, these types of drivers must use an internal buffer where they temporarily store the response between .send() and .recv() calls. Introduce a new flag (TPM_CHIP_FLAG_SYNC) to support synchronous send(). If that flag is set by the driver, tpm_try_transmit() will use the send() callback to send the command and receive the response on the same buffer synchronously. In that case send() return the number of bytes of the response on success, or -errno on failure. Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> Suggested-by: Jason Gunthorpe <jgg@ziepe.ca> Suggested-by: Jarkko Sakkinen <jarkko@kernel.org> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
1 parent 07d8004 commit 04fe470

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

drivers/char/tpm/tpm-interface.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,19 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz)
114114
return rc;
115115
}
116116

117-
/* A sanity check. send() should just return zero on success e.g.
118-
* not the command length.
117+
/*
118+
* Synchronous devices return the response directly during the send()
119+
* call in the same buffer.
120+
*/
121+
if (chip->flags & TPM_CHIP_FLAG_SYNC) {
122+
len = rc;
123+
rc = 0;
124+
goto out_sync;
125+
}
126+
127+
/*
128+
* A sanity check. send() of asynchronous devices should just return
129+
* zero on success e.g. not the command length.
119130
*/
120131
if (rc > 0) {
121132
dev_warn(&chip->dev,
@@ -151,7 +162,10 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz)
151162
if (len < 0) {
152163
rc = len;
153164
dev_err(&chip->dev, "tpm_transmit: tpm_recv: error %d\n", rc);
154-
} else if (len < TPM_HEADER_SIZE || len != be32_to_cpu(header->length))
165+
return rc;
166+
}
167+
out_sync:
168+
if (len < TPM_HEADER_SIZE || len != be32_to_cpu(header->length))
155169
rc = -EFAULT;
156170

157171
return rc ? rc : len;

include/linux/tpm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ enum tpm_chip_flags {
351351
TPM_CHIP_FLAG_SUSPENDED = BIT(8),
352352
TPM_CHIP_FLAG_HWRNG_DISABLED = BIT(9),
353353
TPM_CHIP_FLAG_DISABLE = BIT(10),
354+
TPM_CHIP_FLAG_SYNC = BIT(11),
354355
};
355356

356357
#define to_tpm_chip(d) container_of(d, struct tpm_chip, dev)

0 commit comments

Comments
 (0)