aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Swierk <eswierk@skyportsystems.com>2016-09-19 16:22:08 -0400
committerJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>2016-11-27 18:31:30 -0500
commitaaa6f7f6c8bf1a056c1bb337578cbb2f0c50c12a (patch)
tree999bd883249db0d0ba2897761442237727529d55
parent2c97f6f20cb193264360067259029892c70ce63f (diff)
tpm: Clean up reading of timeout and duration capabilities
Call tpm_getcap() from tpm_get_timeouts() to eliminate redundant code. Return all errors to the caller rather than swallowing them (e.g. when tpm_transmit_cmd() returns nonzero). Signed-off-by: Ed Swierk <eswierk@skyportsystems.com> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
-rw-r--r--drivers/char/tpm/tpm-interface.c65
1 files changed, 17 insertions, 48 deletions
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index cb0e57ee053d..acf89e8d838e 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -493,10 +493,9 @@ static int tpm_startup(struct tpm_chip *chip, __be16 startup_type)
493 493
494int tpm_get_timeouts(struct tpm_chip *chip) 494int tpm_get_timeouts(struct tpm_chip *chip)
495{ 495{
496 struct tpm_cmd_t tpm_cmd; 496 cap_t cap;
497 unsigned long new_timeout[4]; 497 unsigned long new_timeout[4];
498 unsigned long old_timeout[4]; 498 unsigned long old_timeout[4];
499 struct duration_t *duration_cap;
500 ssize_t rc; 499 ssize_t rc;
501 500
502 if (chip->flags & TPM_CHIP_FLAG_TPM2) { 501 if (chip->flags & TPM_CHIP_FLAG_TPM2) {
@@ -514,43 +513,25 @@ int tpm_get_timeouts(struct tpm_chip *chip)
514 return 0; 513 return 0;
515 } 514 }
516 515
517 tpm_cmd.header.in = tpm_getcap_header; 516 rc = tpm_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap,
518 tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP; 517 "attempting to determine the timeouts");
519 tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
520 tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_TIMEOUT;
521 rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, 0,
522 NULL);
523
524 if (rc == TPM_ERR_INVALID_POSTINIT) { 518 if (rc == TPM_ERR_INVALID_POSTINIT) {
525 /* The TPM is not started, we are the first to talk to it. 519 /* The TPM is not started, we are the first to talk to it.
526 Execute a startup command. */ 520 Execute a startup command. */
527 dev_info(&chip->dev, "Issuing TPM_STARTUP"); 521 dev_info(&chip->dev, "Issuing TPM_STARTUP\n");
528 if (tpm_startup(chip, TPM_ST_CLEAR)) 522 if (tpm_startup(chip, TPM_ST_CLEAR))
529 return rc; 523 return rc;
530 524
531 tpm_cmd.header.in = tpm_getcap_header; 525 rc = tpm_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap,
532 tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP; 526 "attempting to determine the timeouts");
533 tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
534 tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_TIMEOUT;
535 rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE,
536 0, NULL);
537 } 527 }
538 if (rc) { 528 if (rc)
539 dev_err(&chip->dev, 529 return rc;
540 "A TPM error (%zd) occurred attempting to determine the timeouts\n",
541 rc);
542 goto duration;
543 }
544
545 if (be32_to_cpu(tpm_cmd.header.out.return_code) != 0 ||
546 be32_to_cpu(tpm_cmd.header.out.length)
547 != sizeof(tpm_cmd.header.out) + sizeof(u32) + 4 * sizeof(u32))
548 return -EINVAL;
549 530
550 old_timeout[0] = be32_to_cpu(tpm_cmd.params.getcap_out.cap.timeout.a); 531 old_timeout[0] = be32_to_cpu(cap.timeout.a);
551 old_timeout[1] = be32_to_cpu(tpm_cmd.params.getcap_out.cap.timeout.b); 532 old_timeout[1] = be32_to_cpu(cap.timeout.b);
552 old_timeout[2] = be32_to_cpu(tpm_cmd.params.getcap_out.cap.timeout.c); 533 old_timeout[2] = be32_to_cpu(cap.timeout.c);
553 old_timeout[3] = be32_to_cpu(tpm_cmd.params.getcap_out.cap.timeout.d); 534 old_timeout[3] = be32_to_cpu(cap.timeout.d);
554 memcpy(new_timeout, old_timeout, sizeof(new_timeout)); 535 memcpy(new_timeout, old_timeout, sizeof(new_timeout));
555 536
556 /* 537 /*
@@ -588,29 +569,17 @@ int tpm_get_timeouts(struct tpm_chip *chip)
588 chip->timeout_c = usecs_to_jiffies(new_timeout[2]); 569 chip->timeout_c = usecs_to_jiffies(new_timeout[2]);
589 chip->timeout_d = usecs_to_jiffies(new_timeout[3]); 570 chip->timeout_d = usecs_to_jiffies(new_timeout[3]);
590 571
591duration: 572 rc = tpm_getcap(chip, TPM_CAP_PROP_TIS_DURATION, &cap,
592 tpm_cmd.header.in = tpm_getcap_header; 573 "attempting to determine the durations");
593 tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP;
594 tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
595 tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_DURATION;
596
597 rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, 0,
598 "attempting to determine the durations");
599 if (rc) 574 if (rc)
600 return rc; 575 return rc;
601 576
602 if (be32_to_cpu(tpm_cmd.header.out.return_code) != 0 ||
603 be32_to_cpu(tpm_cmd.header.out.length)
604 != sizeof(tpm_cmd.header.out) + sizeof(u32) + 3 * sizeof(u32))
605 return -EINVAL;
606
607 duration_cap = &tpm_cmd.params.getcap_out.cap.duration;
608 chip->duration[TPM_SHORT] = 577 chip->duration[TPM_SHORT] =
609 usecs_to_jiffies(be32_to_cpu(duration_cap->tpm_short)); 578 usecs_to_jiffies(be32_to_cpu(cap.duration.tpm_short));
610 chip->duration[TPM_MEDIUM] = 579 chip->duration[TPM_MEDIUM] =
611 usecs_to_jiffies(be32_to_cpu(duration_cap->tpm_medium)); 580 usecs_to_jiffies(be32_to_cpu(cap.duration.tpm_medium));
612 chip->duration[TPM_LONG] = 581 chip->duration[TPM_LONG] =
613 usecs_to_jiffies(be32_to_cpu(duration_cap->tpm_long)); 582 usecs_to_jiffies(be32_to_cpu(cap.duration.tpm_long));
614 583
615 /* The Broadcom BCM0102 chipset in a Dell Latitude D820 gets the above 584 /* The Broadcom BCM0102 chipset in a Dell Latitude D820 gets the above
616 * value wrong and apparently reports msecs rather than usecs. So we 585 * value wrong and apparently reports msecs rather than usecs. So we