drivers/tpm: Add return codes to TPM driver

Add additional failure mode reporting to the TPM driver to provide
additional visibility into what failures are occurring.

BUG=b:296439237
TEST=Verify code paths on Skyrim, ensure behavior is unchanged.
BRANCH=None

Change-Id: I77a653201acf1bddc1ed1e2af701c8d3dd4f0606
Signed-off-by: Jon Murphy <jpmurphy@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/77491
Reviewed-by: Eric Lai <eric_lai@quanta.corp-partner.google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Jan Samek <jan.samek@siemens.com>
This commit is contained in:
Jon Murphy 2023-09-05 11:38:59 -06:00 committed by Raul Rangel
parent d7b8dc9cf5
commit db4e93ba1a
2 changed files with 10 additions and 10 deletions

View File

@ -61,7 +61,7 @@ static struct tpm_inf_dev tpm_dev;
static tpm_result_t cr50_i2c_read(uint8_t addr, uint8_t *buffer, size_t len) static tpm_result_t cr50_i2c_read(uint8_t addr, uint8_t *buffer, size_t len)
{ {
if (tpm_dev.addr == 0) if (tpm_dev.addr == 0)
return TPM_CB_FAIL; return TPM_CB_INVALID_ARG;
/* Clear interrupt before starting transaction */ /* Clear interrupt before starting transaction */
cr50_plat_irq_status(); cr50_plat_irq_status();
@ -69,17 +69,17 @@ static tpm_result_t cr50_i2c_read(uint8_t addr, uint8_t *buffer, size_t len)
/* Send the register address byte to the TPM */ /* Send the register address byte to the TPM */
if (i2c_write_raw(tpm_dev.bus, tpm_dev.addr, &addr, 1)) { if (i2c_write_raw(tpm_dev.bus, tpm_dev.addr, &addr, 1)) {
printk(BIOS_ERR, "%s: Address write failed\n", __func__); printk(BIOS_ERR, "%s: Address write failed\n", __func__);
return TPM_CB_FAIL; return TPM_CB_COMMUNICATION_ERROR;
} }
/* Wait for TPM to be ready with response data */ /* Wait for TPM to be ready with response data */
if (cr50_wait_tpm_ready() != CB_SUCCESS) if (cr50_wait_tpm_ready() != CB_SUCCESS)
return TPM_CB_FAIL; return TPM_CB_TIMEOUT;
/* Read response data from the TPM */ /* Read response data from the TPM */
if (i2c_read_raw(tpm_dev.bus, tpm_dev.addr, buffer, len)) { if (i2c_read_raw(tpm_dev.bus, tpm_dev.addr, buffer, len)) {
printk(BIOS_ERR, "%s: Read response failed\n", __func__); printk(BIOS_ERR, "%s: Read response failed\n", __func__);
return TPM_CB_FAIL; return TPM_CB_COMMUNICATION_ERROR;
} }
return TPM_SUCCESS; return TPM_SUCCESS;
@ -115,11 +115,11 @@ static tpm_result_t cr50_i2c_write(uint8_t addr, const uint8_t *buffer, size_t l
/* Send write request buffer with address */ /* Send write request buffer with address */
if (i2c_write_raw(tpm_dev.bus, tpm_dev.addr, tpm_dev.buf, len + 1)) { if (i2c_write_raw(tpm_dev.bus, tpm_dev.addr, tpm_dev.buf, len + 1)) {
printk(BIOS_ERR, "%s: Error writing to TPM\n", __func__); printk(BIOS_ERR, "%s: Error writing to TPM\n", __func__);
return TPM_CB_FAIL; return TPM_CB_COMMUNICATION_ERROR;
} }
/* Wait for TPM to be ready */ /* Wait for TPM to be ready */
return cr50_wait_tpm_ready() == CB_SUCCESS ? TPM_SUCCESS : TPM_CB_FAIL; return cr50_wait_tpm_ready() == CB_SUCCESS ? TPM_SUCCESS : TPM_CB_TIMEOUT;
} }
/* /*
@ -276,7 +276,7 @@ static tpm_result_t cr50_i2c_wait_burststs(uint8_t mask, size_t *burst, int *sta
printk(BIOS_ERR, "%s: Timeout reading burst and status with error %#x\n", __func__, rc); printk(BIOS_ERR, "%s: Timeout reading burst and status with error %#x\n", __func__, rc);
if (rc) if (rc)
return rc; return rc;
return TPM_CB_TIMEOUT; return TPM_CB_COMMUNICATION_ERROR;
} }
static int cr50_i2c_tis_recv(uint8_t *buf, size_t buf_len) static int cr50_i2c_tis_recv(uint8_t *buf, size_t buf_len)
@ -464,7 +464,7 @@ static tpm_result_t cr50_i2c_probe(uint32_t *did_vid)
printk(BIOS_ERR, "DID_VID 0x%08x not recognized\n", *did_vid); printk(BIOS_ERR, "DID_VID 0x%08x not recognized\n", *did_vid);
return TPM_CB_FAIL; return TPM_CB_FAIL;
} }
return rc; return TPM_CB_COMMUNICATION_ERROR;
} }
tpm_result_t tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr) tpm_result_t tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr)
@ -474,7 +474,7 @@ tpm_result_t tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t d
if (dev_addr == 0) { if (dev_addr == 0) {
printk(BIOS_ERR, "%s: missing device address\n", __func__); printk(BIOS_ERR, "%s: missing device address\n", __func__);
return TPM_CB_FAIL; return TPM_CB_INVALID_ARG;
} }
tpm_dev.bus = bus; tpm_dev.bus = bus;

View File

@ -498,7 +498,7 @@ tpm_result_t tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t d
if (dev_addr == 0) { if (dev_addr == 0) {
printk(BIOS_ERR, "%s: missing device address\n", __func__); printk(BIOS_ERR, "%s: missing device address\n", __func__);
return TPM_CB_FAIL; return TPM_CB_INVALID_ARG;
} }
tpm_dev.chip_type = UNKNOWN; tpm_dev.chip_type = UNKNOWN;