From patchwork Tue Jun 7 03:37:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ed Swierk X-Patchwork-Id: 9159791 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 373BA60571 for ; Tue, 7 Jun 2016 04:03:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28F24265F9 for ; Tue, 7 Jun 2016 04:03:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DCEA2834A; Tue, 7 Jun 2016 04:03:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2E098265F9 for ; Tue, 7 Jun 2016 04:03:27 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bA8Ef-00008y-UF; Tue, 07 Jun 2016 04:03:25 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bA8Ed-00008t-Tl for tpmdd-devel@lists.sourceforge.net; Tue, 07 Jun 2016 04:03:23 +0000 Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of skyportsystems.com designates 209.85.220.54 as permitted sender) client-ip=209.85.220.54; envelope-from=eswierk@skyportsystems.com; helo=mail-pa0-f54.google.com; Received: from mail-pa0-f54.google.com ([209.85.220.54]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:AES128-SHA:128) (Exim 4.76) id 1bA8Ec-0001J0-Ou for tpmdd-devel@lists.sourceforge.net; Tue, 07 Jun 2016 04:03:23 +0000 Received: by mail-pa0-f54.google.com with SMTP id bz2so41748438pad.1 for ; Mon, 06 Jun 2016 21:03:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wnbkGrHZI7OHxxSivoPcZnXiXgx3C3dYsGTJ0voC6Io=; b=f/CQQ3CtioiXXnCNh4mT4zfoks9SpJQfoP6p9C17Q6ajepbepERBpRcPGL3Na09cNr QnbyQ6FkGt4hgegSARpla0iWZwOYwJmeUHI0rn304dCcZ1VSGjXB1c+q3DD8Ypa72uRD F1ieB+0vaUmRk3XwUexkW0u+buoBZBXDahVSIzTQrlfGuBc7SPJYPoY107uz8pI6PrV1 lcyPt4erhefRYf8tqFDebrFjKAVTeq1O1+EnpzepzgJ7EyTPtSjN9FMRseKu2zrD3whG cJr2SV0bGtl+RcU379Todvg/Y8sxiD60DC8jJMQDiYWfh6u12EuWTsbKZWN9B1KxFm+k HTCg== X-Gm-Message-State: ALyK8tJbuxKP/RD+AhNHCRDL+9So0GfDxckDA4NYsjddkXwilF4wpY+OgaHlTP39IRw3fI6B X-Received: by 10.66.126.47 with SMTP id mv15mr23620218pab.74.1465270684502; Mon, 06 Jun 2016 20:38:04 -0700 (PDT) Received: from eswierk-sc.localdomain (67-207-112-138.static.wiline.com. [67.207.112.138]) by smtp.gmail.com with ESMTPSA id fl1sm28516535pab.43.2016.06.06.20.38.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Jun 2016 20:38:04 -0700 (PDT) From: Ed Swierk To: tpmdd-devel@lists.sourceforge.net Date: Mon, 6 Jun 2016 20:37:28 -0700 Message-Id: <1465270649-22498-4-git-send-email-eswierk@skyportsystems.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465270649-22498-1-git-send-email-eswierk@skyportsystems.com> References: <1465270649-22498-1-git-send-email-eswierk@skyportsystems.com> X-Headers-End: 1bA8Ec-0001J0-Ou Subject: [tpmdd-devel] [PATCH v3 3/4] tpm: Allow TPM chip drivers to override reported command durations X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Virus-Scanned: ClamAV using ClamSMTP Some TPM chips report bogus command durations in their capabilities, just as others report incorrect timeouts. Add an update_durations() function and an implementation for tpm_tis, and move the existing BCM0102 workaround out of the common tpm_get_timeouts() code. Signed-off-by: Ed Swierk --- drivers/char/tpm/tpm-interface.c | 43 ++++++++++++++++++++++++---------------- drivers/char/tpm/tpm_tis.c | 40 +++++++++++++++++++++++++++++++++++++ include/linux/tpm.h | 2 ++ 3 files changed, 68 insertions(+), 17 deletions(-) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index cc1e5bc..91332dd 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -507,7 +507,8 @@ int tpm_get_timeouts(struct tpm_chip *chip) struct tpm_cmd_t tpm_cmd; unsigned long new_timeout[4]; unsigned long old_timeout[4]; - struct duration_t *duration_cap; + unsigned long new_duration[3]; + unsigned long old_duration[3]; ssize_t rc; tpm_cmd.header.in = tpm_getcap_header; @@ -599,26 +600,34 @@ duration: != sizeof(tpm_cmd.header.out) + sizeof(u32) + 3 * sizeof(u32)) return -EINVAL; - duration_cap = &tpm_cmd.params.getcap_out.cap.duration; + old_duration[TPM_SHORT] = + be32_to_cpu(tpm_cmd.params.getcap_out.cap.duration.tpm_short); + old_duration[TPM_MEDIUM] = + be32_to_cpu(tpm_cmd.params.getcap_out.cap.duration.tpm_medium); + old_duration[TPM_LONG] = + be32_to_cpu(tpm_cmd.params.getcap_out.cap.duration.tpm_long); + memcpy(new_duration, old_duration, sizeof(new_duration)); + + if (chip->ops->update_durations != NULL) + chip->vendor.duration_adjusted = + chip->ops->update_durations(chip, new_duration); + + /* Report adjusted durations */ + if (chip->vendor.duration_adjusted) { + dev_info(chip->pdev, + HW_ERR "Adjusting reported durations: short %lu->%luus medium %lu->%luus long %lu->%luus\n", + old_duration[TPM_SHORT], new_duration[TPM_SHORT], + old_duration[TPM_MEDIUM], new_duration[TPM_MEDIUM], + old_duration[TPM_LONG], new_duration[TPM_LONG]); + } + chip->vendor.duration[TPM_SHORT] = - usecs_to_jiffies(be32_to_cpu(duration_cap->tpm_short)); + usecs_to_jiffies(new_duration[TPM_SHORT]); chip->vendor.duration[TPM_MEDIUM] = - usecs_to_jiffies(be32_to_cpu(duration_cap->tpm_medium)); + usecs_to_jiffies(new_duration[TPM_MEDIUM]); chip->vendor.duration[TPM_LONG] = - usecs_to_jiffies(be32_to_cpu(duration_cap->tpm_long)); + usecs_to_jiffies(new_duration[TPM_LONG]); - /* The Broadcom BCM0102 chipset in a Dell Latitude D820 gets the above - * value wrong and apparently reports msecs rather than usecs. So we - * fix up the resulting too-small TPM_SHORT value to make things work. - * We also scale the TPM_MEDIUM and -_LONG values by 1000. - */ - if (chip->vendor.duration[TPM_SHORT] < (HZ / 100)) { - chip->vendor.duration[TPM_SHORT] = HZ; - chip->vendor.duration[TPM_MEDIUM] *= 1000; - chip->vendor.duration[TPM_LONG] *= 1000; - chip->vendor.duration_adjusted = true; - dev_info(chip->pdev, "Adjusting TPM timeout parameters."); - } return 0; } EXPORT_SYMBOL_GPL(tpm_get_timeouts); diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c index 088fa86..3baba73 100644 --- a/drivers/char/tpm/tpm_tis.c +++ b/drivers/char/tpm/tpm_tis.c @@ -505,6 +505,45 @@ static bool tpm_tis_update_timeouts(struct tpm_chip *chip, return false; } +struct tis_vendor_duration_override { + u32 did_vid; + unsigned long duration_us[3]; +}; + +static const struct tis_vendor_duration_override vendor_duration_overrides[] = { +}; + +static bool tpm_tis_update_durations(struct tpm_chip *chip, + unsigned long *duration_cap) +{ + int i; + u32 did_vid; + + did_vid = ioread32(chip->vendor.iobase + TPM_DID_VID(0)); + + for (i = 0; i != ARRAY_SIZE(vendor_duration_overrides); i++) { + if (vendor_duration_overrides[i].did_vid != did_vid) + continue; + memcpy(duration_cap, vendor_duration_overrides[i].duration_us, + sizeof(vendor_duration_overrides[i].duration_us)); + return true; + } + + /* The Broadcom BCM0102 chipset in a Dell Latitude D820 gets the above + * value wrong and apparently reports msecs rather than usecs. So we + * fix up the resulting too-small TPM_SHORT value to make things work. + * We also scale the TPM_MEDIUM and -_LONG values by 1000. + */ + if (duration_cap[TPM_SHORT] < (HZ / 100)) { + duration_cap[TPM_SHORT] = HZ; + duration_cap[TPM_MEDIUM] *= 1000; + duration_cap[TPM_LONG] *= 1000; + return true; + } + + return false; +} + /* * Early probing for iTPM with STS_DATA_EXPECT flaw. * Try sending command without itpm flag set and if that @@ -570,6 +609,7 @@ static const struct tpm_class_ops tpm_tis = { .send = tpm_tis_send, .cancel = tpm_tis_ready, .update_timeouts = tpm_tis_update_timeouts, + .update_durations = tpm_tis_update_durations, .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID, .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID, .req_canceled = tpm_tis_req_canceled, diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 706e63e..862d0a1 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -43,6 +43,8 @@ struct tpm_class_ops { u8 (*status) (struct tpm_chip *chip); bool (*update_timeouts)(struct tpm_chip *chip, unsigned long *timeout_cap); + bool (*update_durations)(struct tpm_chip *chip, + unsigned long *duration_cap); };