From patchwork Mon May 9 08:05:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12843171 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7847C433EF for ; Mon, 9 May 2022 08:45:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237323AbiEIIq2 (ORCPT ); Mon, 9 May 2022 04:46:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235691AbiEIIOx (ORCPT ); Mon, 9 May 2022 04:14:53 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B40751D075D; Mon, 9 May 2022 01:10:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1652083627; bh=XQDSzEYmlgJhOdBUnEG20yQFV5PTnn/Qs44xno+mB9E=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=hVQ2W9b2tfB7146tpn+kH7M/xmPM0JWeRSOhFaFdJu2+Qy+K73Kf/V2jiG8reON26 ebh7O2hG/nTyl6yENGOm36kTmTm31LR5c55iPrjsbKRCzs66TRYlmnmN4VMaXBRfd3 bbvMTP8sz2el9606JdkYjkDQ3xHt3m9/4l4kTGnk= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.3.89]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MIMfc-1nbvjD1aNQ-00EOnx; Mon, 09 May 2022 10:07:07 +0200 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com, Lino Sanfilippo Subject: [PATCH v4 5/6] tpm, tpm_tis: Move irq test from tpm_tis_send() to tpm_tis_probe_irq_single() Date: Mon, 9 May 2022 10:05:58 +0200 Message-Id: <20220509080559.4381-6-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220509080559.4381-1-LinoSanfilippo@gmx.de> References: <20220509080559.4381-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:4kJWVwqbBEo2xvrqes8YKbtx9fvrePzaXpK+nDtCFLzgR0AV2U2 4nsfLXapkftu9kQt2xNb9eXi1gCIoOCHgVNIjSYRywavlSATdL8K3PuIpt8mu9NBhAr8P+r PSMPJnG1OSBXX8BLoYeQg56Wl7kRIrPZbRcJ6CjqTHwNbF/EAdfusEqdNKVcz0+bq9TV52U b10V8HiRx1lQiDXGCm0Zw== X-UI-Out-Filterresults: notjunk:1;V03:K0:ojO5q+OKEN0=:Acv4EVI+xsaeaOKkYz29tN Bjmy4p9CrVuOVLy4gk5qic5ra/hu9f8/6B9ttNVtl2tWVyIiwYSgO1KOedViw9A2izblC6ocu tpmSTgWlXeRGcnCi9CqU6Z6BGRDcmk+2N0NH4PjL8PnpbsWD6faw2a3KQkJdM5ohsm130KzYU vakclW0quoyd4qGeWvR5R/GDZpr+wpzCwRpFK29wbq0GFpCdT/EqTXVynrahgWIwc+tANGALA Yt+OxagvC9AtaqUpxfCCTuH8n24rKnwB1dWj4PGJt5AVJgzrE4bGogTai+aPKFx7GNLF6ep16 2lRyr94XBVQ6PCYybrYBRhpzhj2lgJqeorcx58owCPh+PTI2ZjTYXZi8D3HoLzbGnB6iwqM5Z ZI/Yz0seVQgqVkWSFqQFk5DXMpZKJkDTO1FLXjRfs1maxHZ5mzjSMyDlE+HtYl2z4Tolzx9k5 hDDoehSjSCml7/lt2eEj+I2RX2rndCLHV7JZVQSlwHZh7HZdzQpoPJT+EWesnmhtTXvunxvRM 1+o9fwUuI/N0fHf3IU+tWv+By3H9ozk8TZkq9nJ5dsl0gcFjaXlUyWgqXw+3CyJXNc76K+RpB xsRd9I2mWgE8rKuU6RxuaqP2X1ViYEUmi6UZXS5zgpmN2rqPV/0+TNSpAV0zMbjuRZ2wUkKtv vFGbXDHicu9qcIVC4B0xzm5tldLFNyuxJTzDz5xGf7OysVjqY9BNs31crfAOY0V3o9kQI/ogK VunBVJM7X4GvcOpITXODChgolSivAH/qJLUWdILye5ZehbHSjniwm0lx6c10VvZxW27gIZi4k 6n+yF+5joQN+O2oK8WzbmMTvMg0En6SsQjaF+kSy7j0Gzw1MSRvO3+cb8iSQDGjA3QFWipgMr knflQCw2p41x0mI1Lzcla/XoT7KqXCH9q3xPdyUhMHcAUxj3I15cnYdt7MFg9XU5Sugo+UHBE UxDjOisR3e9yCG43hDEjCO1YbAv3J0E6MADScXWPclOqvno3VYcSekX2acqt0ugtWpB7hp5eL sQQNCzYTqOUI0Ly9NUrYBZ7LYaxUbz1PkzjfDbdcLOjV1Ag7HaJqObg3J+IVB6vWJy3kqOdX+ neNg/urj4wy/bk= Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo There is no need to check for the irq test completion at each data transmission during the driver livetime. Instead do the check only once at driver startup. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_core.c | 68 +++++++++++---------------------- 1 file changed, 22 insertions(+), 46 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index bdfde1cd71fe..4c65718feb7d 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -432,7 +432,7 @@ static void disable_interrupts(struct tpm_chip *chip) * tpm.c can skip polling for the data to be available as the interrupt is * waited for here */ -static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len) +static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); int rc; @@ -465,30 +465,6 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len) return rc; } -static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) -{ - int rc, irq; - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - - if (!(chip->flags & TPM_CHIP_FLAG_IRQ) || - test_bit(TPM_TIS_IRQTEST_OK, &priv->irqtest_flags)) - return tpm_tis_send_main(chip, buf, len); - - /* Verify receipt of the expected IRQ */ - irq = priv->irq; - priv->irq = 0; - chip->flags &= ~TPM_CHIP_FLAG_IRQ; - rc = tpm_tis_send_main(chip, buf, len); - priv->irq = irq; - chip->flags |= TPM_CHIP_FLAG_IRQ; - if (!test_bit(TPM_TIS_IRQTEST_OK, &priv->irqtest_flags)) - tpm_msleep(1); - if (!test_bit(TPM_TIS_IRQTEST_OK, &priv->irqtest_flags)) - disable_interrupts(chip); - set_bit(TPM_TIS_IRQTEST_OK, &priv->irqtest_flags); - return rc; -} - struct tis_vendor_durations_override { u32 did_vid; struct tpm1_version version; @@ -759,51 +735,54 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, rc = tpm_tis_read8(priv, TPM_INT_VECTOR(priv->locality), &original_int_vec); - if (rc < 0) + if (rc < 0) { + disable_interrupts(chip); return rc; + } rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), irq); if (rc < 0) - return rc; + goto out_err; rc = tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &int_status); if (rc < 0) - return rc; + goto out_err; /* Clear all existing */ rc = tpm_tis_write32(priv, TPM_INT_STATUS(priv->locality), int_status); if (rc < 0) - return rc; + goto out_err; /* Turn on */ rc = tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask | TPM_GLOBAL_INT_ENABLE); if (rc < 0) - return rc; + goto out_err; clear_bit(TPM_TIS_IRQTEST_OK, &priv->irqtest_flags); - chip->flags |= TPM_CHIP_FLAG_IRQ; /* Generate an interrupt by having the core call through to * tpm_tis_send */ rc = tpm_tis_gen_interrupt(chip); if (rc < 0) - return rc; + goto out_err; - /* tpm_tis_send will either confirm the interrupt is working or it - * will call disable_irq which undoes all of the above. - */ - if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { - rc = tpm_tis_write8(priv, original_int_vec, - TPM_INT_VECTOR(priv->locality)); - if (rc < 0) - return rc; + tpm_msleep(1); - return 1; - } + /* Verify receipt of the expected IRQ */ + if (!test_bit(TPM_TIS_IRQTEST_OK, &priv->irqtest_flags)) + goto out_err; + + chip->flags |= TPM_CHIP_FLAG_IRQ; return 0; + +out_err: + disable_interrupts(chip); + tpm_tis_write8(priv, original_int_vec, TPM_INT_VECTOR(priv->locality)); + + return rc; } /* Try to find the IRQ the TPM is using. This is for legacy x86 systems that @@ -1075,12 +1054,9 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, if (irq) { tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED, irq); - if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { + if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) dev_err(&chip->dev, FW_BUG "TPM interrupt not working, polling instead\n"); - - disable_interrupts(chip); - } } else { tpm_tis_probe_irq(chip, intmask); }