From: Jarkko Sakkinen <jarkko@kernel.org>
To: Lino Sanfilippo <LinoSanfilippo@gmx.de>
Cc: peterhuewe@gmx.de, jgg@ziepe.ca, stefanb@linux.vnet.ibm.com,
linux@mniewoehner.de, linux-integrity@vger.kernel.org,
linux-kernel@vger.kernel.org, l.sanfilippo@kunbus.com,
lukas@wunner.de, p.rosenberger@kunbus.com
Subject: Re: [PATCH v6 5/9] tpm, tpm_tis: Only handle supported interrupts
Date: Sun, 26 Jun 2022 09:40:43 +0300 [thread overview]
Message-ID: <Yrf/azvJlzWfOE9y@kernel.org> (raw)
In-Reply-To: <20220621132447.16281-6-LinoSanfilippo@gmx.de>
On Tue, Jun 21, 2022 at 03:24:43PM +0200, Lino Sanfilippo wrote:
> From: Lino Sanfilippo <l.sanfilippo@kunbus.com>
>
> According to the TPM Interface Specification (TIS) support for "stsValid"
> and "commandReady" interrupts is only optional.
> This has to be taken into account when handling the interrupts in functions
> like wait_for_tpm_stat(). To determine the supported interrupts use the
> capability query.
>
> Also adjust wait_for_tpm_stat() to only wait for interrupt reported status
> changes. After that process all the remaining status changes by polling
> the status register.
>
> Signed-off-by: Lino Sanfilippo <l.sanfilippo@kunbus.com>
> ---
> drivers/char/tpm/tpm_tis_core.c | 119 +++++++++++++++++++-------------
> drivers/char/tpm/tpm_tis_core.h | 1 +
> 2 files changed, 72 insertions(+), 48 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
> index 09d8f04cbc81..cb469591373a 100644
> --- a/drivers/char/tpm/tpm_tis_core.c
> +++ b/drivers/char/tpm/tpm_tis_core.c
> @@ -53,41 +53,63 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
> long rc;
> u8 status;
> bool canceled = false;
> + u8 sts_mask = 0;
> + int ret = 0;
>
> /* check current status */
> status = chip->ops->status(chip);
> if ((status & mask) == mask)
> return 0;
>
> - stop = jiffies + timeout;
> + /* check what status changes can be handled by irqs */
> + if (priv->int_mask & TPM_INTF_STS_VALID_INT)
> + sts_mask |= TPM_STS_VALID;
>
> - if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> + if (priv->int_mask & TPM_INTF_DATA_AVAIL_INT)
> + sts_mask |= TPM_STS_DATA_AVAIL;
> +
> + if (priv->int_mask & TPM_INTF_CMD_READY_INT)
> + sts_mask |= TPM_STS_COMMAND_READY;
> +
> + sts_mask &= mask;
I would instead mask out bits and write a helper function
taking care of this:
static u8 tpm_tis_filter_sts_mask(u8 int_mask, u8 sts_mask)
{
struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
if (!(int_mask & TPM_INTF_STS_VALID_INT))
sts_mask &= ~TPM_STS_VALID;
if (!(int_mask & TPM_INTF_DATA_AVAIL_INT))
sts_mask &= ~TPM_STS_DATA_AVAIL;
if (!(int_mask & TPM_INTF_CMD_READY_INT))
sts_mask &= ~TPM_STS_COMMAND_READY;
return sts_mask;
}
Less operations and imho somewhat cleaner structure.
Add suggested-by if you want.
BR, Jarkko
next prev parent reply other threads:[~2022-06-26 6:40 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-21 13:24 [PATCH v6 0/9] TPM IRQ fixes Lino Sanfilippo
2022-06-21 13:24 ` [PATCH v6 1/9] tpm, tpm_tis: Avoid cache incoherency in test for interrupts Lino Sanfilippo
2022-06-26 6:23 ` Jarkko Sakkinen
2022-06-21 13:24 ` [PATCH v6 2/9] tpm, tpm_tis: Claim locality before writing TPM_INT_ENABLE register Lino Sanfilippo
2022-06-21 13:24 ` [PATCH v6 3/9] tpm, tpm_tis: Disable interrupts if tpm_tis_probe_irq() failed Lino Sanfilippo
2022-06-21 13:24 ` [PATCH v6 4/9] tpm, tmp_tis: Claim locality before writing interrupt registers Lino Sanfilippo
2022-06-21 13:24 ` [PATCH v6 5/9] tpm, tpm_tis: Only handle supported interrupts Lino Sanfilippo
2022-06-26 6:40 ` Jarkko Sakkinen [this message]
2022-06-26 6:44 ` Jarkko Sakkinen
2022-06-26 12:18 ` Lino Sanfilippo
2022-06-27 23:09 ` Jarkko Sakkinen
2022-06-29 9:20 ` Lino Sanfilippo
2022-06-21 13:24 ` [PATCH v6 6/9] tmp, tmp_tis: Implement usage counter for locality Lino Sanfilippo
2022-06-21 13:24 ` [PATCH v6 7/9] tpm, tpm_tis: Request threaded interrupt handler Lino Sanfilippo
2022-06-21 13:24 ` [PATCH v6 8/9] tpm, tpm_tis: Claim locality in " Lino Sanfilippo
2022-06-21 13:24 ` [PATCH v6 9/9] tpm, tpm_tis: Enable interrupt test Lino Sanfilippo
2022-06-21 22:39 ` Michael Niewöhner
2022-06-22 9:53 ` Lino Sanfilippo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Yrf/azvJlzWfOE9y@kernel.org \
--to=jarkko@kernel.org \
--cc=LinoSanfilippo@gmx.de \
--cc=jgg@ziepe.ca \
--cc=l.sanfilippo@kunbus.com \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@mniewoehner.de \
--cc=lukas@wunner.de \
--cc=p.rosenberger@kunbus.com \
--cc=peterhuewe@gmx.de \
--cc=stefanb@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox