Skip to content

Commit f25534a

Browse files
webmeisterjarkkojs
authored andcommitted
tpm: Add tpm_tis_verify_crc to the tpm_tis_phy_ops protocol layer
Some TPMs, e.g. those implementing the I2C variant of TIS, can verify data transfers to/from the FIFO with a CRC. The CRC is calculated over the entirety of the FIFO register. Since the phy_ops layer is not aware when the core layer is done reading/writing the FIFO, CRC verification must be triggered from the core layer. To this end, add an optional phy_ops API call. Co-developed-by: Johannes Holland <johannes.holland@infineon.com> Signed-off-by: Johannes Holland <johannes.holland@infineon.com> Signed-off-by: Alexander Steffen <Alexander.Steffen@infineon.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
1 parent 2353673 commit f25534a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

drivers/char/tpm/tpm_tis_core.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
289289
int size = 0;
290290
int status;
291291
u32 expected;
292+
int rc;
292293

293294
if (count < TPM_HEADER_SIZE) {
294295
size = -EIO;
@@ -328,6 +329,13 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
328329
goto out;
329330
}
330331

332+
rc = tpm_tis_verify_crc(priv, (size_t)size, buf);
333+
if (rc < 0) {
334+
dev_err(&chip->dev, "CRC mismatch for response.\n");
335+
size = rc;
336+
goto out;
337+
}
338+
331339
out:
332340
tpm_tis_ready(chip);
333341
return size;
@@ -443,6 +451,12 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len)
443451
if (rc < 0)
444452
return rc;
445453

454+
rc = tpm_tis_verify_crc(priv, len, buf);
455+
if (rc < 0) {
456+
dev_err(&chip->dev, "CRC mismatch for command.\n");
457+
return rc;
458+
}
459+
446460
/* go and do it */
447461
rc = tpm_tis_write8(priv, TPM_STS(priv->locality), TPM_STS_GO);
448462
if (rc < 0)

drivers/char/tpm/tpm_tis_core.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ struct tpm_tis_phy_ops {
121121
u8 *result, enum tpm_tis_io_mode mode);
122122
int (*write_bytes)(struct tpm_tis_data *data, u32 addr, u16 len,
123123
const u8 *value, enum tpm_tis_io_mode mode);
124+
int (*verify_crc)(struct tpm_tis_data *data, size_t len,
125+
const u8 *value);
124126
};
125127

126128
static inline int tpm_tis_read_bytes(struct tpm_tis_data *data, u32 addr,
@@ -188,6 +190,14 @@ static inline int tpm_tis_write32(struct tpm_tis_data *data, u32 addr,
188190
return rc;
189191
}
190192

193+
static inline int tpm_tis_verify_crc(struct tpm_tis_data *data, size_t len,
194+
const u8 *value)
195+
{
196+
if (!data->phy_ops->verify_crc)
197+
return 0;
198+
return data->phy_ops->verify_crc(data, len, value);
199+
}
200+
191201
static inline bool is_bsw(void)
192202
{
193203
#ifdef CONFIG_X86

0 commit comments

Comments
 (0)