From: Alexander Steffen <[email protected]>

commit f25534a68b8e1ed8266d23b464a3b512364b124d upstream

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 <[email protected]>
Signed-off-by: Johannes Holland <[email protected]>
Signed-off-by: Alexander Steffen <[email protected]>
Reviewed-by: Jarkko Sakkinen <[email protected]>
Signed-off-by: Jarkko Sakkinen <[email protected]>
Signed-off-by: Li Wang <[email protected]>
---
 drivers/char/tpm/tpm_tis_core.c | 13 +++++++++++++
 drivers/char/tpm/tpm_tis_core.h | 10 ++++++++++
 2 files changed, 23 insertions(+)

diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index d7c440ac465f..f98655fe6d33 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -359,6 +359,13 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, 
size_t count)
                goto out;
        }
 
+       rc = tpm_tis_verify_crc(priv, (size_t)size, buf);
+       if (rc < 0) {
+               dev_err(&chip->dev, "CRC mismatch for response.\n");
+               size = rc;
+               goto out;
+       }
+
 out:
        tpm_tis_ready(chip);
        return size;
@@ -474,6 +481,12 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const 
u8 *buf, size_t len)
        if (rc < 0)
                return rc;
 
+       rc = tpm_tis_verify_crc(priv, len, buf);
+       if (rc < 0) {
+               dev_err(&chip->dev, "CRC mismatch for command.\n");
+               return rc;
+       }
+
        /* go and do it */
        rc = tpm_tis_write8(priv, TPM_STS(priv->locality), TPM_STS_GO);
        if (rc < 0)
diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h
index 39ba9dd21363..1ad769f674f4 100644
--- a/drivers/char/tpm/tpm_tis_core.h
+++ b/drivers/char/tpm/tpm_tis_core.h
@@ -123,6 +123,8 @@ struct tpm_tis_phy_ops {
                          u8 *result, enum tpm_tis_io_mode mode);
        int (*write_bytes)(struct tpm_tis_data *data, u32 addr, u16 len,
                           const u8 *value, enum tpm_tis_io_mode mode);
+       int (*verify_crc)(struct tpm_tis_data *data, size_t len,
+                          const u8 *value);
 };
 
 static inline int tpm_tis_read_bytes(struct tpm_tis_data *data, u32 addr,
@@ -190,6 +192,14 @@ static inline int tpm_tis_write32(struct tpm_tis_data 
*data, u32 addr,
        return rc;
 }
 
+static inline int tpm_tis_verify_crc(struct tpm_tis_data *data, size_t len,
+                                    const u8 *value)
+{
+       if (!data->phy_ops->verify_crc)
+               return 0;
+       return data->phy_ops->verify_crc(data, len, value);
+}
+
 static inline bool is_bsw(void)
 {
 #ifdef CONFIG_X86
-- 
2.39.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#13054): 
https://lists.yoctoproject.org/g/linux-yocto/message/13054
Mute This Topic: https://lists.yoctoproject.org/mt/101353519/21656
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to