Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tpm_tis: override durations for STM tpm with firmware 1.2.8.28

There was revealed a bug in the STM TPM chipset used in Dell R415s.
Bug is observed so far only on chipset firmware 1.2.8.28
(1.2 TPM, device-id 0x0, rev-id 78). After some number of
operations chipset hangs and stays in inconsistent state:

tpm_tis 00:09: Operation Timed out
tpm_tis 00:09: tpm_transmit: tpm_send: error -5

Durations returned by the chip are the same like on other
firmware revisions but apparently with specifically 1.2.8.28 fw
durations should be reset to 2 minutes to enable tpm chip work
properly. No working way of updating firmware was found.

This patch adds implementation of ->update_durations method
that matches only STM devices with specific firmware version.

Cc: Peter Huewe <peterhuewe@gmx.de>
Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Signed-off-by: Alexey Klimov <aklimov@redhat.com>
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> (!update_durations path)
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> (!update_durations path)

authored by

Jerry Snitselaar and committed by
Jarkko Sakkinen
5af4f1d5 15d0b22c

+79
+79
drivers/char/tpm/tpm_tis_core.c
··· 506 506 return rc; 507 507 } 508 508 509 + struct tis_vendor_durations_override { 510 + u32 did_vid; 511 + struct tpm1_version version; 512 + unsigned long durations[3]; 513 + }; 514 + 515 + static const struct tis_vendor_durations_override vendor_dur_overrides[] = { 516 + /* STMicroelectronics 0x104a */ 517 + { 0x0000104a, 518 + { 1, 2, 8, 28 }, 519 + { (2 * 60 * HZ), (2 * 60 * HZ), (2 * 60 * HZ) } }, 520 + }; 521 + 522 + static void tpm_tis_update_durations(struct tpm_chip *chip, 523 + unsigned long *duration_cap) 524 + { 525 + struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); 526 + struct tpm1_version *version; 527 + u32 did_vid; 528 + int i, rc; 529 + cap_t cap; 530 + 531 + chip->duration_adjusted = false; 532 + 533 + if (chip->ops->clk_enable != NULL) 534 + chip->ops->clk_enable(chip, true); 535 + 536 + rc = tpm_tis_read32(priv, TPM_DID_VID(0), &did_vid); 537 + if (rc < 0) { 538 + dev_warn(&chip->dev, "%s: failed to read did_vid. %d\n", 539 + __func__, rc); 540 + goto out; 541 + } 542 + 543 + /* Try to get a TPM version 1.2 or 1.1 TPM_CAP_VERSION_INFO */ 544 + rc = tpm1_getcap(chip, TPM_CAP_VERSION_1_2, &cap, 545 + "attempting to determine the 1.2 version", 546 + sizeof(cap.version2)); 547 + if (!rc) { 548 + version = &cap.version2.version; 549 + } else { 550 + rc = tpm1_getcap(chip, TPM_CAP_VERSION_1_1, &cap, 551 + "attempting to determine the 1.1 version", 552 + sizeof(cap.version1)); 553 + 554 + if (rc) 555 + goto out; 556 + 557 + version = &cap.version1; 558 + } 559 + 560 + for (i = 0; i != ARRAY_SIZE(vendor_dur_overrides); i++) { 561 + if (vendor_dur_overrides[i].did_vid != did_vid) 562 + continue; 563 + 564 + if ((version->major == 565 + vendor_dur_overrides[i].version.major) && 566 + (version->minor == 567 + vendor_dur_overrides[i].version.minor) && 568 + (version->rev_major == 569 + vendor_dur_overrides[i].version.rev_major) && 570 + (version->rev_minor == 571 + vendor_dur_overrides[i].version.rev_minor)) { 572 + 573 + memcpy(duration_cap, 574 + vendor_dur_overrides[i].durations, 575 + sizeof(vendor_dur_overrides[i].durations)); 576 + 577 + chip->duration_adjusted = true; 578 + goto out; 579 + } 580 + } 581 + 582 + out: 583 + if (chip->ops->clk_enable != NULL) 584 + chip->ops->clk_enable(chip, false); 585 + } 586 + 509 587 struct tis_vendor_timeout_override { 510 588 u32 did_vid; 511 589 unsigned long timeout_us[4]; ··· 920 842 .send = tpm_tis_send, 921 843 .cancel = tpm_tis_ready, 922 844 .update_timeouts = tpm_tis_update_timeouts, 845 + .update_durations = tpm_tis_update_durations, 923 846 .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID, 924 847 .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID, 925 848 .req_canceled = tpm_tis_req_canceled,