From: Arun Menon <armenon@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Jarkko Sakkinen <jarkko@kernel.org>,
Jason Gunthorpe <jgg@ziepe.ca>, Peter Huewe <peterhuewe@gmx.de>,
linux-integrity@vger.kernel.org, Arun Menon <armenon@redhat.com>
Subject: [PATCH v5 6/7] tpm_crb: Factor crb_send()/crb_recv() bodies into helpers
Date: Thu, 29 Oct 2026 23:45:40 +0530 [thread overview]
Message-ID: <20261029181541.99505-7-armenon@redhat.com> (raw)
In-Reply-To: <20261029181541.99505-1-armenon@redhat.com>
From: Arun Menon <armenon@redhat.com>
A later patch adds CRB chunking, which needs its own send/receive
loops alongside the existing single-shot transfer. Move the body of
crb_send() into tpm_crb_send_no_chunks() and the body of crb_recv()
into tpm_crb_recv_no_chunks().
Pure code motion, no behavior change. Also fix the block comment to the
kernel's preferred multi-line style.
Signed-off-by: Arun Menon <armenon@redhat.com>
---
drivers/char/tpm/tpm_crb.c | 71 ++++++++++++++++++++++++--------------
1 file changed, 45 insertions(+), 26 deletions(-)
diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
index 30ca8192d3a8..f0bac9e1f1e8 100644
--- a/drivers/char/tpm/tpm_crb.c
+++ b/drivers/char/tpm/tpm_crb.c
@@ -369,24 +369,13 @@ static u8 crb_status(struct tpm_chip *chip)
return sts;
}
-static int crb_recv(struct tpm_chip *chip, u8 *buf, size_t count)
+static int tpm_crb_recv_no_chunks(struct tpm_chip *chip, u8 *buf, size_t count)
{
struct crb_priv *priv = dev_get_drvdata(&chip->dev);
unsigned int expected;
- /* A sanity check that the upper layer wants to get at least the header
- * as that is the minimum size for any TPM response.
- */
- if (count < TPM_HEADER_SIZE)
- return -EIO;
-
- /* If this bit is set, according to the spec, the TPM is in
- * unrecoverable condition.
- */
- if (ioread32(&priv->regs_t->ctrl_sts) & CRB_CTRL_STS_ERROR)
- return -EIO;
-
- /* Read the first 8 bytes in order to get the length of the response.
+ /*
+ * Read the first 8 bytes in order to get the length of the response.
* We read exactly a quad word in order to make sure that the remaining
* reads will be aligned.
*/
@@ -399,6 +388,28 @@ static int crb_recv(struct tpm_chip *chip, u8 *buf, size_t count)
memcpy_fromio(&buf[8], &priv->rsp[8], expected - 8);
return expected;
+
+}
+
+static int crb_recv(struct tpm_chip *chip, u8 *buf, size_t count)
+{
+ struct crb_priv *priv = dev_get_drvdata(&chip->dev);
+
+ /*
+ * A sanity check that the upper layer wants to get at least the header
+ * as that is the minimum size for any TPM response.
+ */
+ if (count < TPM_HEADER_SIZE)
+ return -EIO;
+
+ /*
+ * If this bit is set, according to the spec, the TPM is in
+ * unrecoverable condition.
+ */
+ if (ioread32(&priv->regs_t->ctrl_sts) & CRB_CTRL_STS_ERROR)
+ return -EIO;
+
+ return tpm_crb_recv_no_chunks(chip, buf, count);
}
static int crb_do_acpi_start(struct tpm_chip *chip)
@@ -474,12 +485,29 @@ static int tpm_crb_start(struct tpm_chip *chip, u32 start_cmd)
return rc;
}
-static int crb_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz, size_t len)
+static int tpm_crb_send_no_chunks(struct tpm_chip *chip, u8 *buf, size_t len)
{
struct crb_priv *priv = dev_get_drvdata(&chip->dev);
int rc = 0;
- /* Zero the cancel register so that the next command will not get
+ memcpy_toio(priv->cmd, buf, len);
+
+ /* Make sure that cmd is populated before issuing start. */
+ wmb();
+
+ rc = tpm_crb_start(chip, CRB_START_INVOKE);
+ if (rc)
+ return rc;
+
+ return crb_try_pluton_doorbell(priv, false);
+}
+
+static int crb_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz, size_t len)
+{
+ struct crb_priv *priv = dev_get_drvdata(&chip->dev);
+
+ /*
+ * Zero the cancel register so that the next command will not get
* canceled.
*/
iowrite32(0, &priv->regs_t->ctrl_cancel);
@@ -494,16 +522,7 @@ static int crb_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz, size_t len)
if (priv->sm == ACPI_TPM2_COMMAND_BUFFER_WITH_PLUTON)
__crb_cmd_ready(&chip->dev, priv, chip->locality);
- memcpy_toio(priv->cmd, buf, len);
-
- /* Make sure that cmd is populated before issuing start. */
- wmb();
-
- rc = tpm_crb_start(chip, CRB_START_INVOKE);
- if (rc)
- return rc;
-
- return crb_try_pluton_doorbell(priv, false);
+ return tpm_crb_send_no_chunks(chip, buf, len);
}
static void crb_cancel(struct tpm_chip *chip)
--
2.56.0
next prev parent reply other threads:[~2026-10-29 18:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 18:15 [PATCH v5 0/7] tpm_crb: Add command and response buffer chunking support Arun Menon
2026-10-29 18:15 ` [PATCH v5 1/7] tpm_crb: Add register definitions of TPM CRB chunking fields Arun Menon
2026-10-29 18:15 ` [PATCH v5 2/7] tpm_crb: Split start method into a separate header Arun Menon
2026-10-29 18:15 ` [PATCH v5 3/7] tpm_crb: Add start_cmd parameter to tpm_crb_start wrapper Arun Menon
2026-10-29 18:15 ` [PATCH v5 4/7] tpm: tis_i2c: Use local 4KB buffer to limit memory usage Arun Menon
2026-10-29 18:15 ` [PATCH v5 5/7] tpm: Increase TPM_BUFSIZE to 8KB for chunking support Arun Menon
2026-10-29 18:55 ` Jarkko Sakkinen
2026-10-29 18:15 ` Arun Menon [this message]
2026-10-29 19:27 ` [PATCH v5 6/7] tpm_crb: Factor crb_send()/crb_recv() bodies into helpers Jarkko Sakkinen
2026-10-29 18:15 ` [PATCH v5 7/7] tpm_crb: Implement command and response chunking logic Arun Menon
2026-10-29 19:28 ` Jarkko Sakkinen
2026-10-29 23:30 ` [PATCH v5 0/7] tpm_crb: Add command and response buffer chunking support Jarkko Sakkinen
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=20261029181541.99505-7-armenon@redhat.com \
--to=armenon@redhat.com \
--cc=jarkko@kernel.org \
--cc=jgg@ziepe.ca \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterhuewe@gmx.de \
/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