Skip to contentSkip to conversation

tpm: Pull tpm_tis_phy_ops and tpm_tis_i2c updates

PATCH In review Peter Delevoryas 3 participants 12 messages Aug 8, 2022 – Aug 22, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover tpm: Pull tpm_tis_phy_ops and tpm_tis_i2c updates

OpenBMC's Linux dev-5.15 has an old tpm_tis_i2c driver from Nuvoton, but it was never merged upstreamed and produces compilation warnings now.

Infineon took that driver, modified it, and merged it upstream. Nuvoton never merged theirs, so the first patch in this series reverts theirs.

Also, I included the "Remove read16, read32, write32" patch because otherwise Alexander's patches don't apply cleanly. But, I could actually resolve the merge conflicts. I figured it will be easier later to just include more patches from upstream to make it clean.

I also noticed there was one follow-up change submitted by alibaba to remove one line, so I included that.

Alexander didn't include the compatible strings from the old driver, even though it should be compatible, so I've included a patch at the end which fixes that. I did it as a separate patch so that we maintain a patch series closer to what the upstream will be.

cc'ing Alexander on this thread too to see if he has any suggestions, or thinks I missed anything.

I haven't cc'd the linux kernel mailing list aliases because I don't think this is relevant to them. Only the patch including the compatible strings will be relevant.

checkpath.pl warns agains MAINTAINERS, but I'm pretty sure it's fine. The upstream MAINTAINERS file hasn't been updated with these changes, so we probably don't need to do anything there.

This was a follow-up from the following OpenBMC mailing list thread:

https://lore.kernel.org/openbmc/[email protected]/

Thanks,
Peter

Alexander Steffen (3):
dt-bindings: trivial-devices: Add Infineon SLB9673 TPM
tpm: Add tpm_tis_verify_crc to the tpm_tis_phy_ops protocol layer
tpm: Add tpm_tis_i2c backend for tpm_tis_core

Johannes Holland (1):
tpm: Remove read16/read32/write32 calls from tpm_tis_phy_ops

Peter Delevoryas (2):
Revert "tpm: tpm_tis: Add tpm_tis_i2c driver"
tpm_tis_i2c: Add old compatible strings back

Yang Li (1):
tpm: fix platform_no_drv_owner.cocci warning

 .../devicetree/bindings/trivial-devices.yaml  |   2 +
 drivers/char/tpm/Kconfig                      |  24 +-
 drivers/char/tpm/tpm_tis.c                    |  67 ++-
 drivers/char/tpm/tpm_tis_core.c               |  14 +
 drivers/char/tpm/tpm_tis_core.h               |  68 ++-
 drivers/char/tpm/tpm_tis_i2c.c                | 431 ++++++++++++------
 drivers/char/tpm/tpm_tis_spi.h                |   4 -
 drivers/char/tpm/tpm_tis_spi_cr50.c           |   7 +-
 drivers/char/tpm/tpm_tis_spi_main.c           |  45 +-
 drivers/char/tpm/tpm_tis_synquacer.c          |  98 ++--
 10 files changed, 436 insertions(+), 324 deletions(-)
Signature · 1 line
2.37.1
#1 lore raw

PATCH 1/7 Revert "tpm: tpm_tis: Add tpm_tis_i2c driver"

This reverts commit 1caa2f764dc9d49d5a85eef9585fc6d2717c28bb.

Nuvoton is not planning on maintaining this driver, and Infineon has submitted a new version, so we'll remove this one and add Infineon's.

See this mail thread for more details:

https://lore.kernel.org/openbmc/[email protected]/

---
 drivers/char/tpm/Kconfig       |  12 --
 drivers/char/tpm/Makefile      |   1 -
 drivers/char/tpm/tpm_tis_i2c.c | 263 ---------------------------------
 3 files changed, 276 deletions(-)
 delete mode 100644 drivers/char/tpm/tpm_tis_i2c.c
drivers/char/tpm/Kconfig +0 -12
index f07ae63298ec..d6ba644f6b00 100644
@@ -86,18 +86,6 @@ config TCG_TIS_SYNQUACER
 	  To compile this driver as a module, choose  M here;
 	  the module will be called tpm_tis_synquacer.
 
-config TCG_TIS_I2C
-	tristate "TPM I2C Interface Specification"
-	depends on I2C
-	select CRC_CCITT
-	select TCG_TIS_CORE
-	help
-	  If you have a TPM security chip, compliant with the TCG TPM PTP
-	  (I2C interface) specification and connected to an I2C bus master,
-	  say Yes and it will be accessible from within Linux.
-	  To compile this driver as a module, choose M here;
-	  the module will be called tpm_tis_i2c.
-
 config TCG_TIS_I2C_CR50
 	tristate "TPM Interface Specification 2.0 Interface (I2C - CR50)"
 	depends on I2C
drivers/char/tpm/Makefile +0 -1
index 0222b1ddb310..66d39ea6bd10 100644
@@ -29,7 +29,6 @@ tpm_tis_spi-$(CONFIG_TCG_TIS_SPI_CR50) += tpm_tis_spi_cr50.o
 
 obj-$(CONFIG_TCG_TIS_I2C_CR50) += tpm_tis_i2c_cr50.o
 
-obj-$(CONFIG_TCG_TIS_I2C) += tpm_tis_i2c.o
 obj-$(CONFIG_TCG_TIS_I2C_ATMEL) += tpm_i2c_atmel.o
 obj-$(CONFIG_TCG_TIS_I2C_INFINEON) += tpm_i2c_infineon.o
 obj-$(CONFIG_TCG_TIS_I2C_NUVOTON) += tpm_i2c_nuvoton.o
drivers/char/tpm/tpm_tis_i2c.c deleted +0 -263

263 lines not on this page · raw message

Signature · 1 line
2.37.1
#2 lore raw

PATCH 2/7 tpm: Remove read16/read32/write32 calls from tpm_tis_phy_ops

In reply to Peter Delevoryas

From: Johannes Holland <[email protected]>

Only tpm_tis and tpm_tis_synquacer have a dedicated way to access multiple bytes at once, every other driver will just fall back to read_bytes/write_bytes. Therefore, remove the read16/read32/write32 calls and move their logic to read_bytes/write_bytes.

---
 drivers/char/tpm/tpm_tis.c           | 67 +++++++++----------
 drivers/char/tpm/tpm_tis_core.h      | 58 ++++++++++++----
 drivers/char/tpm/tpm_tis_spi.h       |  4 --
 drivers/char/tpm/tpm_tis_spi_cr50.c  |  7 +-
 drivers/char/tpm/tpm_tis_spi_main.c  | 45 +------------
 drivers/char/tpm/tpm_tis_synquacer.c | 98 +++++++++++-----------------
 6 files changed, 118 insertions(+), 161 deletions(-)
drivers/char/tpm/tpm_tis.c +30 -37
index d3f2e5364c27..bcff6429e0b4 100644
@@ -153,50 +153,46 @@ static int check_acpi_tpm2(struct device *dev)
 #endif
 
 static int tpm_tcg_read_bytes(struct tpm_tis_data *data, u32 addr, u16 len,
-			      u8 *result)
+			      u8 *result, enum tpm_tis_io_mode io_mode)
 {
 	struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
-
-	while (len--)
-		*result++ = ioread8(phy->iobase + addr);
+	__le16 result_le16;
+	__le32 result_le32;
+
+	switch (io_mode) {
+	case TPM_TIS_PHYS_8:
+		while (len--)
+			*result++ = ioread8(phy->iobase + addr);
+		break;
+	case TPM_TIS_PHYS_16:
+		result_le16 = cpu_to_le16(ioread16(phy->iobase + addr));
+		memcpy(result, &result_le16, sizeof(u16));
+		break;
+	case TPM_TIS_PHYS_32:
+		result_le32 = cpu_to_le32(ioread32(phy->iobase + addr));
+		memcpy(result, &result_le32, sizeof(u32));
+		break;
+	}
 
 	return 0;
 }
 
 static int tpm_tcg_write_bytes(struct tpm_tis_data *data, u32 addr, u16 len,
-			       const u8 *value)
+			       const u8 *value, enum tpm_tis_io_mode io_mode)
 {
 	struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
 
-	while (len--)
-		iowrite8(*value++, phy->iobase + addr);
-
-	return 0;
-}
-
-static int tpm_tcg_read16(struct tpm_tis_data *data, u32 addr, u16 *result)
-{
-	struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
-
-	*result = ioread16(phy->iobase + addr);
-
-	return 0;
-}
-
-static int tpm_tcg_read32(struct tpm_tis_data *data, u32 addr, u32 *result)
-{
-	struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
-
-	*result = ioread32(phy->iobase + addr);
-
-	return 0;
-}
-
-static int tpm_tcg_write32(struct tpm_tis_data *data, u32 addr, u32 value)
-{
-	struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
-
-	iowrite32(value, phy->iobase + addr);
+	switch (io_mode) {
+	case TPM_TIS_PHYS_8:
+		while (len--)
+			iowrite8(*value++, phy->iobase + addr);
+		break;
+	case TPM_TIS_PHYS_16:
+		return -EINVAL;
+	case TPM_TIS_PHYS_32:
+		iowrite32(le32_to_cpu(*((__le32 *)value)), phy->iobase + addr);
+		break;
+	}
 
 	return 0;
 }
@@ -204,9 +200,6 @@ static int tpm_tcg_write32(struct tpm_tis_data *data, u32 addr, u32 value)
 static const struct tpm_tis_phy_ops tpm_tcg = {
 	.read_bytes = tpm_tcg_read_bytes,
 	.write_bytes = tpm_tcg_write_bytes,
-	.read16 = tpm_tcg_read16,
-	.read32 = tpm_tcg_read32,
-	.write32 = tpm_tcg_write32,
 };
 
 static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info)
drivers/char/tpm/tpm_tis_core.h +46 -12

100 lines not on this page · raw message

drivers/char/tpm/tpm_tis_spi.h +0 -4
index bba73979c368..d0f66f6f1931 100644
@@ -31,10 +31,6 @@ extern int tpm_tis_spi_init(struct spi_device *spi, struct tpm_tis_spi_phy *phy,
 extern int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len,
 				u8 *in, const u8 *out);
 
-extern int tpm_tis_spi_read16(struct tpm_tis_data *data, u32 addr, u16 *result);
-extern int tpm_tis_spi_read32(struct tpm_tis_data *data, u32 addr, u32 *result);
-extern int tpm_tis_spi_write32(struct tpm_tis_data *data, u32 addr, u32 value);
-
 #ifdef CONFIG_TCG_TIS_SPI_CR50
 extern int cr50_spi_probe(struct spi_device *spi);
 #else
drivers/char/tpm/tpm_tis_spi_cr50.c +2 -5
index ea759af25634..6d3092e2df46 100644
@@ -206,13 +206,13 @@ static int tpm_tis_spi_cr50_transfer(struct tpm_tis_data *data, u32 addr, u16 le
 }
 
 static int tpm_tis_spi_cr50_read_bytes(struct tpm_tis_data *data, u32 addr,
-				       u16 len, u8 *result)
+				       u16 len, u8 *result, enum tpm_tis_io_mode io_mode)
 {
 	return tpm_tis_spi_cr50_transfer(data, addr, len, result, NULL);
 }
 
 static int tpm_tis_spi_cr50_write_bytes(struct tpm_tis_data *data, u32 addr,
-					u16 len, const u8 *value)
+					u16 len, const u8 *value, enum tpm_tis_io_mode io_mode)
 {
 	return tpm_tis_spi_cr50_transfer(data, addr, len, NULL, value);
 }
@@ -220,9 +220,6 @@ static int tpm_tis_spi_cr50_write_bytes(struct tpm_tis_data *data, u32 addr,
 static const struct tpm_tis_phy_ops tpm_spi_cr50_phy_ops = {
 	.read_bytes = tpm_tis_spi_cr50_read_bytes,
 	.write_bytes = tpm_tis_spi_cr50_write_bytes,
-	.read16 = tpm_tis_spi_read16,
-	.read32 = tpm_tis_spi_read32,
-	.write32 = tpm_tis_spi_write32,
 };
 
 static void cr50_print_fw_version(struct tpm_tis_data *data)
drivers/char/tpm/tpm_tis_spi_main.c +2 -43

66 lines not on this page · raw message

drivers/char/tpm/tpm_tis_synquacer.c +38 -60

119 lines not on this page · raw message

Signature · 1 line
2.37.1
#3 lore raw

PATCH 3/7 dt-bindings: trivial-devices: Add Infineon SLB9673 TPM

In reply to Peter Delevoryas

From: Alexander Steffen <[email protected]>

Initial device to be supported by the upcoming tpm_tis_i2c driver. More to be added later.

---
 Documentation/devicetree/bindings/trivial-devices.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/trivial-devices.yaml +2 -0
index 1e4b3464d734..9c37f57de919 100644
@@ -123,6 +123,8 @@ properties:
           - infineon,slb9635tt
             # Infineon SLB9645 I2C TPM (new protocol, max 400khz)
           - infineon,slb9645tt
+            # Infineon SLB9673 I2C TPM 2.0
+          - infineon,slb9673
             # Infineon TLV493D-A1B6 I2C 3D Magnetic Sensor
           - infineon,tlv493d-a1b6
             # Infineon Multi-phase Digital VR Controller xdpe12254
Signature · 1 line
2.37.1
#4 lore raw

PATCH 4/7 tpm: Add tpm_tis_verify_crc to the tpm_tis_phy_ops protocol layer

In reply to Peter Delevoryas

From: Alexander Steffen <[email protected]>

Some TPMs, e.g. those implementing the I2C variant of TIS, can verify data transfers to/from the FIFO with a CRC. The CRC is calculated over the entirety of the FIFO register. Since the phy_ops layer is not aware when the core layer is done reading/writing the FIFO, CRC verification must be triggered from the core layer. To this end, add an optional phy_ops API call.

---
 drivers/char/tpm/tpm_tis_core.c | 14 ++++++++++++++
 drivers/char/tpm/tpm_tis_core.h | 10 ++++++++++
 2 files changed, 24 insertions(+)
drivers/char/tpm/tpm_tis_core.c +14 -0
index d2fc3fe94146..21a706d8d737 100644
@@ -294,6 +294,7 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 	int size = 0;
 	int status;
 	u32 expected;
+	int rc;
 
 	if (count < TPM_HEADER_SIZE) {
 		size = -EIO;
@@ -334,6 +335,13 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 		goto out;
 	}
 
+	rc = tpm_tis_verify_crc(priv, (size_t)size, buf);
+	if (rc < 0) {
+		dev_err(&chip->dev, "CRC mismatch for response.\n");
+		size = rc;
+		goto out;
+	}
+
 out:
 	tpm_tis_ready(chip);
 	return size;
@@ -439,6 +447,12 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len)
 	if (rc < 0)
 		return rc;
 
+	rc = tpm_tis_verify_crc(priv, len, buf);
+	if (rc < 0) {
+		dev_err(&chip->dev, "CRC mismatch for command.\n");
+		return rc;
+	}
+
 	/* go and do it */
 	rc = tpm_tis_write8(priv, TPM_STS(priv->locality), TPM_STS_GO);
 	if (rc < 0)
drivers/char/tpm/tpm_tis_core.h +10 -0
index 6c203f36b8a1..66a5a13cd1df 100644
@@ -121,6 +121,8 @@ struct tpm_tis_phy_ops {
 			  u8 *result, enum tpm_tis_io_mode mode);
 	int (*write_bytes)(struct tpm_tis_data *data, u32 addr, u16 len,
 			   const u8 *value, enum tpm_tis_io_mode mode);
+	int (*verify_crc)(struct tpm_tis_data *data, size_t len,
+			  const u8 *value);
 };
 
 static inline int tpm_tis_read_bytes(struct tpm_tis_data *data, u32 addr,
@@ -188,6 +190,14 @@ static inline int tpm_tis_write32(struct tpm_tis_data *data, u32 addr,
 	return rc;
 }
 
+static inline int tpm_tis_verify_crc(struct tpm_tis_data *data, size_t len,
+				     const u8 *value)
+{
+	if (!data->phy_ops->verify_crc)
+		return 0;
+	return data->phy_ops->verify_crc(data, len, value);
+}
+
 static inline bool is_bsw(void)
 {
 #ifdef CONFIG_X86
Signature · 1 line
2.37.1
#5 lore raw

PATCH 5/7 tpm: Add tpm_tis_i2c backend for tpm_tis_core

In reply to Peter Delevoryas

From: Alexander Steffen <[email protected]>

Implement the TCG I2C Interface driver, as specified in the TCG PC Client Platform TPM Profile (PTP) specification for TPM 2.0 v1.04 revision 14, section 8, I2C Interface Definition.

This driver supports Guard Times. That is, if required by the TPM, the driver has to wait by a vendor-specific time after each I2C read/write. The specific time is read from the TPM_I2C_INTERFACE_CAPABILITY register.

Unfortunately, the TCG specified almost but not quite compatible register addresses. Therefore, the TIS register addresses need to be mapped to I2C ones. The locality is stripped because for now, only locality 0 is supported.

Add a sanity check to I2C reads of e.g. TPM_ACCESS and TPM_STS. This is to detect communication errors and issues due to non-standard behaviour (E.g. the clock stretching quirk in the BCM2835, see 4dbfb5f4401f). In case the sanity check fails, attempt a retry.

---
 drivers/char/tpm/Kconfig       |  12 +
 drivers/char/tpm/Makefile      |   1 +
 drivers/char/tpm/tpm_tis_i2c.c | 391 +++++++++++++++++++++++++++++++++
 3 files changed, 404 insertions(+)
 create mode 100644 drivers/char/tpm/tpm_tis_i2c.c
drivers/char/tpm/Kconfig +12 -0
index d6ba644f6b00..470dfc552eeb 100644
@@ -74,6 +74,18 @@ config TCG_TIS_SPI_CR50
 	  If you have a H1 secure module running Cr50 firmware on SPI bus,
 	  say Yes and it will be accessible from within Linux.
 
+config TCG_TIS_I2C
+	tristate "TPM Interface Specification 1.3 Interface / TPM 2.0 FIFO Interface - (I2C - generic)"
+	depends on I2C
+	select CRC_CCITT
+	select TCG_TIS_CORE
+	help
+	  If you have a TPM security chip, compliant with the TCG TPM PTP
+	  (I2C interface) specification and connected to an I2C bus master,
+	  say Yes and it will be accessible from within Linux.
+	  To compile this driver as a module, choose M here;
+	  the module will be called tpm_tis_i2c.
+
 config TCG_TIS_SYNQUACER
 	tristate "TPM Interface Specification 1.2 Interface / TPM 2.0 FIFO Interface (MMIO - SynQuacer)"
 	depends on ARCH_SYNQUACER
drivers/char/tpm/Makefile +1 -0
index 66d39ea6bd10..0222b1ddb310 100644
@@ -29,6 +29,7 @@ tpm_tis_spi-$(CONFIG_TCG_TIS_SPI_CR50) += tpm_tis_spi_cr50.o
 
 obj-$(CONFIG_TCG_TIS_I2C_CR50) += tpm_tis_i2c_cr50.o
 
+obj-$(CONFIG_TCG_TIS_I2C) += tpm_tis_i2c.o
 obj-$(CONFIG_TCG_TIS_I2C_ATMEL) += tpm_i2c_atmel.o
 obj-$(CONFIG_TCG_TIS_I2C_INFINEON) += tpm_i2c_infineon.o
 obj-$(CONFIG_TCG_TIS_I2C_NUVOTON) += tpm_i2c_nuvoton.o
drivers/char/tpm/tpm_tis_i2c.c new file +391 -0

391 lines not on this page · raw message

Signature · 1 line
2.37.1
#6 lore raw

PATCH 6/7 tpm: fix platform_no_drv_owner.cocci warning

In reply to Peter Delevoryas

From: Yang Li <[email protected]>

Eliminate the following coccicheck warning:
./drivers/char/tpm/tpm_tis_i2c.c:379:3-8: No need to set .owner here. The core will do it.

Remove .owner field if calls are used which set it automatically

---
 drivers/char/tpm/tpm_tis_i2c.c | 1 -
 1 file changed, 1 deletion(-)
drivers/char/tpm/tpm_tis_i2c.c +0 -1
index 8e0686fe4eb1..ba0911b1d1ff 100644
@@ -376,7 +376,6 @@ MODULE_DEVICE_TABLE(of, of_tis_i2c_match);
 
 static struct i2c_driver tpm_tis_i2c_driver = {
 	.driver = {
-		.owner = THIS_MODULE,
 		.name = "tpm_tis_i2c",
 		.pm = &tpm_tis_pm,
 		.of_match_table = of_match_ptr(of_tis_i2c_match),
Signature · 1 line
2.37.1
#7 lore raw

PATCH 7/7 tpm_tis_i2c: Add old compatible strings back

In reply to Peter Delevoryas

The old version of this driver from Nuvoton included different compatible strings, which are in-use by a few dts's.

$ egrep -r "npct75x|tpm-tis-i2c" arch/arm
arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts:           compatible = "nuvoton,npct75x", "tcg,tpm-tis-i2c";
arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts:           compatible = "nuvoton,npct75x";
arch/arm/boot/dts/aspeed-bmc-opp-tacoma.dts:            compatible = "tcg,tpm-tis-i2c";
---
 drivers/char/tpm/tpm_tis_i2c.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/char/tpm/tpm_tis_i2c.c +2 -0
index ba0911b1d1ff..a2ae2eafed6d 100644
@@ -369,6 +369,8 @@ MODULE_DEVICE_TABLE(i2c, tpm_tis_i2c_id);
 #ifdef CONFIG_OF
 static const struct of_device_id of_tis_i2c_match[] = {
 	{ .compatible = "infineon,slb9673", },
+	{ .compatible = "nuvoton,npct75x", },
+	{ .compatible = "tcg,tpm-tis-i2c", },
 	{}
 };
 MODULE_DEVICE_TABLE(of, of_tis_i2c_match);
Signature · 1 line
2.37.1
#8 lore raw
In reply to Peter Delevoryas
Quoted 6 lines · Peter Delevoryas

OpenBMC's Linux dev-5.15 has an old tpm_tis_i2c driver from Nuvoton, but it was never merged upstreamed and produces compilation warnings now.

Infineon took that driver, modified it, and merged it upstream. Nuvoton never merged theirs, so the first patch in this series reverts theirs.

Thanks Peter!

I've been testing this version of the driver (applied to v5.19 instead of our 5.15 tree, but it is the same code) and it doesn't work with the hardware we have:

[    1.571105] tpm tpm0: Operation Canceled
[    1.576301] tpm_tis_i2c 1-002e: 1.2 TPM (device-id 0xFC, rev-id 1)
[    1.610168] tpm tpm0: Operation Canceled
[    1.615580] tpm tpm0: A TPM error (-125) occurred attempting to
determine the timeouts
[    1.685651] tpm_tis_i2c: probe of 1-002e failed with error -125

This appears to be detected as a "1.2 TPM", when I am pretty sure it's a 2.0 device. I suspect I'm missing something.

The tree I was testing with is here:

https://github.com/shenki/linux/commits/dev-5.19

I've cc'd Eddie as he also has access to this hardware, and perhaps can help with the debugging.

Cheers,

Joel

Quoted 62 lines

Also, I included the "Remove read16, read32, write32" patch because otherwise Alexander's patches don't apply cleanly. But, I could actually resolve the merge conflicts. I figured it will be easier later to just include more patches from upstream to make it clean.

I also noticed there was one follow-up change submitted by alibaba to remove one line, so I included that.

Alexander didn't include the compatible strings from the old driver, even though it should be compatible, so I've included a patch at the end which fixes that. I did it as a separate patch so that we maintain a patch series closer to what the upstream will be.

cc'ing Alexander on this thread too to see if he has any suggestions, or thinks I missed anything.

I haven't cc'd the linux kernel mailing list aliases because I don't think this is relevant to them. Only the patch including the compatible strings will be relevant.

checkpath.pl warns agains MAINTAINERS, but I'm pretty sure it's fine. The upstream MAINTAINERS file hasn't been updated with these changes, so we probably don't need to do anything there.

This was a follow-up from the following OpenBMC mailing list thread:

https://lore.kernel.org/openbmc/[email protected]/

Thanks,
Peter

Alexander Steffen (3):
dt-bindings: trivial-devices: Add Infineon SLB9673 TPM
tpm: Add tpm_tis_verify_crc to the tpm_tis_phy_ops protocol layer
tpm: Add tpm_tis_i2c backend for tpm_tis_core

Johannes Holland (1):
tpm: Remove read16/read32/write32 calls from tpm_tis_phy_ops

Peter Delevoryas (2):
Revert "tpm: tpm_tis: Add tpm_tis_i2c driver"
tpm_tis_i2c: Add old compatible strings back

Yang Li (1):
tpm: fix platform_no_drv_owner.cocci warning

 .../devicetree/bindings/trivial-devices.yaml  |   2 +
 drivers/char/tpm/Kconfig                      |  24 +-
 drivers/char/tpm/tpm_tis.c                    |  67 ++-
 drivers/char/tpm/tpm_tis_core.c               |  14 +
 drivers/char/tpm/tpm_tis_core.h               |  68 ++-
 drivers/char/tpm/tpm_tis_i2c.c                | 431 ++++++++++++------
 drivers/char/tpm/tpm_tis_spi.h                |   4 -
 drivers/char/tpm/tpm_tis_spi_cr50.c           |   7 +-
 drivers/char/tpm/tpm_tis_spi_main.c           |  45 +-
 drivers/char/tpm/tpm_tis_synquacer.c          |  98 ++--
 10 files changed, 436 insertions(+), 324 deletions(-)

--
2.37.1

#9 lore raw
Quoted 24 lines · Joel Stanley
Quoted 6 lines · Peter Delevoryas

OpenBMC's Linux dev-5.15 has an old tpm_tis_i2c driver from Nuvoton, but it was never merged upstreamed and produces compilation warnings now.

Infineon took that driver, modified it, and merged it upstream. Nuvoton never merged theirs, so the first patch in this series reverts theirs.

Thanks Peter!

I've been testing this version of the driver (applied to v5.19 instead of our 5.15 tree, but it is the same code) and it doesn't work with the hardware we have:

[    1.571105] tpm tpm0: Operation Canceled
[    1.576301] tpm_tis_i2c 1-002e: 1.2 TPM (device-id 0xFC, rev-id 1)
[    1.610168] tpm tpm0: Operation Canceled
[    1.615580] tpm tpm0: A TPM error (-125) occurred attempting to
determine the timeouts
[    1.685651] tpm_tis_i2c: probe of 1-002e failed with error -125

This appears to be detected as a "1.2 TPM", when I am pretty sure it's a 2.0 device. I suspect I'm missing something.

Quoted 7 lines

The tree I was testing with is here:

https://github.com/shenki/linux/commits/dev-5.19

I've cc'd Eddie as he also has access to this hardware, and perhaps can help with the debugging.

Oh, yikes, ok. That's not good. Maybe I can help debug this too. We have some lab systems that connected to the TPM through I2C, but that might have been a TPM 1.2 chip, not a TPM 2 chip. Thanks though.

Quoted 69 lines

Cheers,

Joel

Quoted 62 lines

Also, I included the "Remove read16, read32, write32" patch because otherwise Alexander's patches don't apply cleanly. But, I could actually resolve the merge conflicts. I figured it will be easier later to just include more patches from upstream to make it clean.

I also noticed there was one follow-up change submitted by alibaba to remove one line, so I included that.

Alexander didn't include the compatible strings from the old driver, even though it should be compatible, so I've included a patch at the end which fixes that. I did it as a separate patch so that we maintain a patch series closer to what the upstream will be.

cc'ing Alexander on this thread too to see if he has any suggestions, or thinks I missed anything.

I haven't cc'd the linux kernel mailing list aliases because I don't think this is relevant to them. Only the patch including the compatible strings will be relevant.

checkpath.pl warns agains MAINTAINERS, but I'm pretty sure it's fine. The upstream MAINTAINERS file hasn't been updated with these changes, so we probably don't need to do anything there.

This was a follow-up from the following OpenBMC mailing list thread:

https://lore.kernel.org/openbmc/[email protected]/

Thanks,
Peter

Alexander Steffen (3):
dt-bindings: trivial-devices: Add Infineon SLB9673 TPM
tpm: Add tpm_tis_verify_crc to the tpm_tis_phy_ops protocol layer
tpm: Add tpm_tis_i2c backend for tpm_tis_core

Johannes Holland (1):
tpm: Remove read16/read32/write32 calls from tpm_tis_phy_ops

Peter Delevoryas (2):
Revert "tpm: tpm_tis: Add tpm_tis_i2c driver"
tpm_tis_i2c: Add old compatible strings back

Yang Li (1):
tpm: fix platform_no_drv_owner.cocci warning

 .../devicetree/bindings/trivial-devices.yaml  |   2 +
 drivers/char/tpm/Kconfig                      |  24 +-
 drivers/char/tpm/tpm_tis.c                    |  67 ++-
 drivers/char/tpm/tpm_tis_core.c               |  14 +
 drivers/char/tpm/tpm_tis_core.h               |  68 ++-
 drivers/char/tpm/tpm_tis_i2c.c                | 431 ++++++++++++------
 drivers/char/tpm/tpm_tis_spi.h                |   4 -
 drivers/char/tpm/tpm_tis_spi_cr50.c           |   7 +-
 drivers/char/tpm/tpm_tis_spi_main.c           |  45 +-
 drivers/char/tpm/tpm_tis_synquacer.c          |  98 ++--
 10 files changed, 436 insertions(+), 324 deletions(-)

--
2.37.1

#10 lore raw
In reply to Peter Delevoryas

Hi Peter,

sorry for the late response.

Quoted 4 lines · Peter Delevoryas

Alexander didn't include the compatible strings from the old driver, even though it should be compatible, so I've included a patch at the end which fixes that. I did it as a separate patch so that we maintain a patch series closer to what the upstream will be.

There were some objections to add them and/or to document them in trivial-devices.yaml, so I left them out to get at least the driver code merged. Makes sense to add them back if they are already in use.

I still plan to clean up the TPM compatibles and their documentation, to make it easier to manage them in the future, and then also add back the missing compatibles.

Quoted 2 lines

cc'ing Alexander on this thread too to see if he has any suggestions, or thinks I missed anything.

Looks good to me.

Alexander

#11 lore raw
Quoted 3 lines · Alexander Steffen

Hi Peter,

sorry for the late response.

No problem! We unblocked our development on this issue by just disabling the TPM I2C driver in our kernel config, so there's no particular rush for us.

In fact, if Joel wants to just avoid figuring this out and merge the 5.19 kernel, that would probably be fine. But, that might still break the machines he referenced, that are using an I2C TPM interface.

Quoted 10 lines · Peter Delevoryas
Quoted 4 lines

Alexander didn't include the compatible strings from the old driver, even though it should be compatible, so I've included a patch at the end which fixes that. I did it as a separate patch so that we maintain a patch series closer to what the upstream will be.

There were some objections to add them and/or to document them in trivial-devices.yaml, so I left them out to get at least the driver code merged. Makes sense to add them back if they are already in use.

I see, thanks for explaining the context.

Quoted 4 lines

I still plan to clean up the TPM compatibles and their documentation, to make it easier to manage them in the future, and then also add back the missing compatibles.

Oh that would be great, thanks.

Quoted 7 lines
Quoted 3 lines

cc'ing Alexander on this thread too to see if he has any suggestions, or thinks I missed anything.

Looks good to me.

Alexander