瀏覽代碼

tpm: Adjust interface timeouts if they are too small

Adjust the interface timeouts if they are found to be too small, i.e., if
they are returned in milliseconds rather than microseconds as we heared
from Infineon that some (old) Infineon TPMs do.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Signed-off-by: Rajiv Andrade <srajiv@linux.vnet.ibm.com>
Stefan Berger 14 年之前
父節點
當前提交
e3e1a1e169
共有 1 個文件被更改,包括 9 次插入4 次删除
  1. 9 4
      drivers/char/tpm/tpm.c

+ 9 - 4
drivers/char/tpm/tpm.c

@@ -534,6 +534,7 @@ void tpm_get_timeouts(struct tpm_chip *chip)
 	struct duration_t *duration_cap;
 	struct duration_t *duration_cap;
 	ssize_t rc;
 	ssize_t rc;
 	u32 timeout;
 	u32 timeout;
+	unsigned int scale = 1;
 
 
 	tpm_cmd.header.in = tpm_getcap_header;
 	tpm_cmd.header.in = tpm_getcap_header;
 	tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP;
 	tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP;
@@ -553,17 +554,21 @@ void tpm_get_timeouts(struct tpm_chip *chip)
 	timeout_cap = &tpm_cmd.params.getcap_out.cap.timeout;
 	timeout_cap = &tpm_cmd.params.getcap_out.cap.timeout;
 	/* Don't overwrite default if value is 0 */
 	/* Don't overwrite default if value is 0 */
 	timeout = be32_to_cpu(timeout_cap->a);
 	timeout = be32_to_cpu(timeout_cap->a);
+	if (timeout && timeout < 1000) {
+		/* timeouts in msec rather usec */
+		scale = 1000;
+	}
 	if (timeout)
 	if (timeout)
-		chip->vendor.timeout_a = usecs_to_jiffies(timeout);
+		chip->vendor.timeout_a = usecs_to_jiffies(timeout * scale);
 	timeout = be32_to_cpu(timeout_cap->b);
 	timeout = be32_to_cpu(timeout_cap->b);
 	if (timeout)
 	if (timeout)
-		chip->vendor.timeout_b = usecs_to_jiffies(timeout);
+		chip->vendor.timeout_b = usecs_to_jiffies(timeout * scale);
 	timeout = be32_to_cpu(timeout_cap->c);
 	timeout = be32_to_cpu(timeout_cap->c);
 	if (timeout)
 	if (timeout)
-		chip->vendor.timeout_c = usecs_to_jiffies(timeout);
+		chip->vendor.timeout_c = usecs_to_jiffies(timeout * scale);
 	timeout = be32_to_cpu(timeout_cap->d);
 	timeout = be32_to_cpu(timeout_cap->d);
 	if (timeout)
 	if (timeout)
-		chip->vendor.timeout_d = usecs_to_jiffies(timeout);
+		chip->vendor.timeout_d = usecs_to_jiffies(timeout * scale);
 
 
 duration:
 duration:
 	tpm_cmd.header.in = tpm_getcap_header;
 	tpm_cmd.header.in = tpm_getcap_header;