From patchwork Thu Nov 5 16:19:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 7562651 Return-Path: X-Original-To: patchwork-tpmdd-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3A2989F399 for ; Thu, 5 Nov 2015 16:19:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 438B9205EB for ; Thu, 5 Nov 2015 16:19:44 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id B34FC20811 for ; Thu, 5 Nov 2015 16:19:41 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ZuNGH-00051p-0h; Thu, 05 Nov 2015 16:19:41 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ZuNGF-00051i-KQ for tpmdd-devel@lists.sourceforge.net; Thu, 05 Nov 2015 16:19:39 +0000 Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of ts.fujitsu.com designates 80.70.172.51 as permitted sender) client-ip=80.70.172.51; envelope-from=martin.wilck@ts.fujitsu.com; helo=dgate20.ts.fujitsu.com; Received: from dgate20.ts.fujitsu.com ([80.70.172.51]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1ZuNGE-000576-Bx for tpmdd-devel@lists.sourceforge.net; Thu, 05 Nov 2015 16:19:39 +0000 X-SBRSScore: None Received: from unknown (HELO abgdate50u.abg.fsc.net) ([172.25.138.66]) by dgate20u.abg.fsc.net with ESMTP; 05 Nov 2015 17:19:29 +0100 Received: from unknown (HELO pdbcooper.pdb.fsc.net) ([172.25.111.126]) by abgdate50u.abg.fsc.net with ESMTP; 05 Nov 2015 17:19:29 +0100 Received: from pdbcooper.pdb.fsc.net (localhost [127.0.0.1]) by pdbcooper.pdb.fsc.net (8.14.9/8.14.8) with ESMTP id tA5GJNFh015280; Thu, 5 Nov 2015 17:19:24 +0100 From: martin.wilck@ts.fujitsu.com To: tpmdd-devel@lists.sourceforge.net Date: Thu, 5 Nov 2015 17:19:08 +0100 Message-Id: <1446740353-15235-2-git-send-email-martin.wilck@ts.fujitsu.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1446740353-15235-1-git-send-email-martin.wilck@ts.fujitsu.com> References: <1446740353-15235-1-git-send-email-martin.wilck@ts.fujitsu.com> X-Spam-Score: -1.6 (-) X-Headers-End: 1ZuNGE-000576-Bx Cc: Martin Wilck Subject: [tpmdd-devel] [PATCH 1/6] tpm_tis: calculate command durations before irq probing 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-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, HK_RANDOM_ENVFROM, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Martin Wilck For reliable IRQ probing, the expected command durations should be known before doing the probe. Also, in the probing algorithm, wait another ms for the IRQ to arrive, as it is done in the IRQ testing code in tpm_tis_send(). Signed-off-by: Martin Wilck --- drivers/char/tpm/tpm_tis.c | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c index 696ef1d..3ed7e6ce 100644 --- a/drivers/char/tpm/tpm_tis.c +++ b/drivers/char/tpm/tpm_tis.c @@ -730,6 +730,25 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info, if (intfcaps & TPM_INTF_DATA_AVAIL_INT) dev_dbg(dev, "\tData Avail Int Support\n"); + if (chip->flags & TPM_CHIP_FLAG_TPM2) { + chip->vendor.timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A); + chip->vendor.timeout_b = msecs_to_jiffies(TPM2_TIMEOUT_B); + chip->vendor.timeout_c = msecs_to_jiffies(TPM2_TIMEOUT_C); + chip->vendor.timeout_d = msecs_to_jiffies(TPM2_TIMEOUT_D); + chip->vendor.duration[TPM_SHORT] = + msecs_to_jiffies(TPM2_DURATION_SHORT); + chip->vendor.duration[TPM_MEDIUM] = + msecs_to_jiffies(TPM2_DURATION_MEDIUM); + chip->vendor.duration[TPM_LONG] = + msecs_to_jiffies(TPM2_DURATION_LONG); + } else { + if (tpm_get_timeouts(chip)) { + dev_err(dev, "Could not get TPM timeouts and durations\n"); + rc = -ENODEV; + goto out_err; + } + } + /* INTERRUPT Setup */ init_waitqueue_head(&chip->vendor.read_queue); init_waitqueue_head(&chip->vendor.int_queue); @@ -759,6 +778,7 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info, } for (i = irq_s; i <= irq_e && chip->vendor.irq == 0; i++) { + dev_dbg(dev, "Probing irq %d\n", i); iowrite8(i, chip->vendor.iobase + TPM_INT_VECTOR(chip->vendor.locality)); if (devm_request_irq @@ -790,8 +810,14 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info, else tpm_gen_interrupt(chip); + if (!chip->vendor.probed_irq) + msleep(1); + chip->vendor.irq = chip->vendor.probed_irq; + if (chip->vendor.irq) + dev_info(dev, "Probed IRQ: %d\n", i); + /* free_irq will call into tis_int_probe; clear all irqs we haven't seen while doing tpm_gen_interrupt */ @@ -834,17 +860,6 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info, } if (chip->flags & TPM_CHIP_FLAG_TPM2) { - chip->vendor.timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A); - chip->vendor.timeout_b = msecs_to_jiffies(TPM2_TIMEOUT_B); - chip->vendor.timeout_c = msecs_to_jiffies(TPM2_TIMEOUT_C); - chip->vendor.timeout_d = msecs_to_jiffies(TPM2_TIMEOUT_D); - chip->vendor.duration[TPM_SHORT] = - msecs_to_jiffies(TPM2_DURATION_SHORT); - chip->vendor.duration[TPM_MEDIUM] = - msecs_to_jiffies(TPM2_DURATION_MEDIUM); - chip->vendor.duration[TPM_LONG] = - msecs_to_jiffies(TPM2_DURATION_LONG); - rc = tpm2_do_selftest(chip); if (rc == TPM2_RC_INITIALIZE) { dev_warn(dev, "Firmware has not started TPM\n"); @@ -860,12 +875,6 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info, goto out_err; } } else { - if (tpm_get_timeouts(chip)) { - dev_err(dev, "Could not get TPM timeouts and durations\n"); - rc = -ENODEV; - goto out_err; - } - if (tpm_do_selftest(chip)) { dev_err(dev, "TPM self test failed\n"); rc = -ENODEV;