TPM: Work around buggy TPMs that block during continue self test
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / char / tpm / tpm.c
index 023dfbaffe7395258139a2b33d9b883c53444c60..e38054b33bb43423c92e6b4b1e2f1413a04d90a4 100644 (file)
@@ -843,7 +843,7 @@ int tpm_do_selftest(struct tpm_chip *chip)
 {
        int rc;
        unsigned int loops;
-       unsigned int delay_msec = 1000;
+       unsigned int delay_msec = 100;
        unsigned long duration;
        struct tpm_cmd_t cmd;
 
@@ -864,6 +864,14 @@ int tpm_do_selftest(struct tpm_chip *chip)
                cmd.header.in = pcrread_header;
                cmd.params.pcrread_in.pcr_idx = cpu_to_be32(0);
                rc = tpm_transmit(chip, (u8 *) &cmd, READ_PCR_RESULT_SIZE);
+               /* Some buggy TPMs will not respond to tpm_tis_ready() for
+                * around 300ms while the self test is ongoing, keep trying
+                * until the self test duration expires. */
+               if (rc == -ETIME) {
+                       dev_info(chip->dev, HW_ERR "TPM command timed out during continue self test");
+                       msleep(delay_msec);
+                       continue;
+               }
 
                if (rc < TPM_HEADER_SIZE)
                        return -EFAULT;