Skip to contentSkip to conversation

char: tpm: add new driver for tpm i2c ptp

PATCH In review Oshri Alkoby 6 participants 19 messages Jun 28, 2019 – Sep 6, 2019 1 message not in the archive

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

v2 cover char: tpm: add new driver for tpm i2c ptp

This patch set adds support for TPM devices that implement the I2C interface defined by TCG PTP specification:
https://trustedcomputinggroup.org/wp-content/uploads/TCG_PC_Client_Platform_TPM_Profile_PTP_2.0_r1.03_v22.pdf

The driver was tested on Raspberry-Pie 3, using Nuvoton NPCT75X TPM.

changes
-------

v2:
- Extended device tree binding description

v1:
- Initial version

Oshri Alkoby (2):
dt-bindings: tpm: add the TPM I2C PTP device tree binding
documentation
char: tpm: add new driver for tpm i2c ptp

 .../bindings/security/tpm/tpm-i2c-ptp.txt     |   24 +
 drivers/char/tpm/Kconfig                      |   22 +
 drivers/char/tpm/Makefile                     |    1 +
 drivers/char/tpm/tpm_i2c_ptp.c                | 1099 +++++++++++++++++
 4 files changed, 1146 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/security/tpm/tpm-i2c-ptp.txt
 create mode 100644 drivers/char/tpm/tpm_i2c_ptp.c
Signature · 1 line
2.18.0
#1 lore raw

PATCH v2 1/2 dt-bindings: tpm: add the TPM I2C PTP device tree binding documentation

---
 .../bindings/security/tpm/tpm-i2c-ptp.txt     | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/security/tpm/tpm-i2c-ptp.txt
Documentation/devicetree/bindings/security/tpm/tpm-i2c-ptp.txt new file +24 -0
new file mode 100644
index 000000000000..8b0207fdf3e2
@@ -0,0 +1,24 @@
+* Device Tree Bindings for I2C PTP based Trusted Platform Module(TPM)
+
+The TCG defines a hardware protocol, registers and interface (based
+on the TPM Interface Specification) for accessing TPM devices
+implemented with an I2C interface.
+
+Refer to the 'I2C Interface Definition' section in 'TCG PC Client
+PlatformTPMProfile(PTP) Specification' publication for specification.
+
+Required properties:
+
+- compatible     : Should be "tcg,tpm_i2c_ptp"
+- reg            : Address on the bus
+- tpm-pirq       : Input gpio pin, used for host interrupts
+
+Example (for Raspberry Pie 3 Board with Nuvoton's NPCT75X (2.0)
+-------------------------------------------------------------------
+
+tpm_i2c_ptp: tpm_i2c_ptp@2e {
+
+	compatible = "tcg,tpm_i2c_ptp";
+	reg = <0x2e>;
+	tpm-pirq = <&gpio 24 GPIO_ACTIVE_HIGH>;
+};
Signature · 1 line
2.18.0
#2 lore raw

PATCH v2 2/2 char: tpm: add new driver for tpm i2c ptp

In reply to Oshri Alkoby
---
 drivers/char/tpm/Kconfig       |   22 +
 drivers/char/tpm/Makefile      |    1 +
 drivers/char/tpm/tpm_i2c_ptp.c | 1099 ++++++++++++++++++++++++++++++++
 3 files changed, 1122 insertions(+)
 create mode 100644 drivers/char/tpm/tpm_i2c_ptp.c
drivers/char/tpm/Kconfig +22 -0
index 88a3c06fc153..ea4138145191 100644
@@ -97,6 +97,28 @@ config TCG_TIS_I2C_NUVOTON
 	  To compile this driver as a module, choose M here; the module
 	  will be called tpm_i2c_nuvoton.
 
+config TCG_TIS_I2C_PTP
+	tristate "TPM Interface Specification 1.2/2.0 Interface (I2C - PTP)"
+	depends on I2C
+	select CRC_CCITT
+	---help---
+	  If you have a TPM security chip with an I2C interface that impelements
+	  the TPM I2C interface protocol defined by the PTP 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_i2c_ptp.
+
+config TCG_TIS_I2C_PTP_MAX_SIZE
+	prompt "Max I2C Buffer Size"
+	depends on TCG_TIS_I2C_PTP
+	int
+	default 32
+	help
+	  Set the maximal I2C buffer size. This will alter the default value. A
+	  different size can be set by using a module parameter (i2c_max_size)
+	  as well. If no parameter is provided when loading, this is the value
+	  that will be used.
+
 config TCG_NSC
 	tristate "National Semiconductor TPM Interface"
 	depends on X86
drivers/char/tpm/Makefile +1 -0
index a01c4cab902a..d736f22205cb 100644
@@ -25,6 +25,7 @@ obj-$(CONFIG_TCG_TIS_SPI) += tpm_tis_spi.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
+obj-$(CONFIG_TCG_TIS_I2C_PTP) += tpm_i2c_ptp.o
 obj-$(CONFIG_TCG_NSC) += tpm_nsc.o
 obj-$(CONFIG_TCG_ATMEL) += tpm_atmel.o
 obj-$(CONFIG_TCG_INFINEON) += tpm_infineon.o
drivers/char/tpm/tpm_i2c_ptp.c new file +1099 -0

1,099 lines not on this page · raw message

Signature · 1 line
2.18.0
#3 lore raw
In reply to Oshri Alkoby

On Fri, 2019-06-28 at 18:13 +0300, Oshri Alkoby wrote:

The long descriptions are still missing. Please take the time and write a proper commit messages that clearly tell what the patch does.

Check out tpm_tis_core.c and tpm_tis_spi.c. TPM TIS driver implements that spec so you should only implement a new physical layer.

/Jarkko

#4 lore raw
Quoted 2 lines · Jarkko Sakkinen

Check out tpm_tis_core.c and tpm_tis_spi.c. TPM TIS driver implements that spec so you should only implement a new physical layer.

I had the same thought. Unfortunately, the I2C-TIS specification introduces two relevant changes compared to tpm_tis/tpm_tis_spi:

1. Locality is not encoded into register addresses anymore, but stored in a separate register.
2. Several register addresses have changed (but still contain compatible contents).

I'd still prefer not to duplicate all the high-level logic from tpm_tis_core. But this will probably mean to introduce some new interfaces between tpm_tis_core and the physical layers.

Also, shouldn't the new driver be called tpm_tis_i2c, to group it with all the other (TIS) drivers, that implement a vendor-independent protocol? With tpm_i2c_ptp users might assume that ptp is just another vendor.

Alexander

#5 lore raw

Alex, Jarkko, thank you very much for your feedbacks!

Quoted 1 line

The long descriptions are still missing

Will be expanded

Quoted 1 line

I'd still prefer not to duplicate all the high-level logic from

tpm_tis_core. But this will probably mean to introduce some new interfaces between tpm_tis_core and the physical layers.

I totally agree, there are some duplications that can be common, indeed it will require some work in tpm_tis_core.

Since I believe it is not going to happen soon, I would suggest to examine what duplications can currently be dropped from the new driver, so the kernel will support the PTP I2C interface in the meantime.

I will appreciate getting ideas about any tpm_tis_core logic that currently can be used as is by the new drive.

Quoted 7 lines

Also, shouldn't the new driver be called tpm_tis_i2c, to group it with

all the other (TIS) drivers, that implement a vendor-independent

protocol? With tpm_i2c_ptp users might assume that ptp is just another

vendor

Since the TIS is an old specification that mostly defines FIFO for TPM1.2 I would say the name tpm_tis_i2c does not completely reflect its goal. However we really don't have any problem with any name that the group will agree on.

Does tpm_ptp_i2c sound better than the current name?

Oshri

Quoted 23 lines · Alexander Steffen
Quoted 2 lines · Jarkko Sakkinen

Check out tpm_tis_core.c and tpm_tis_spi.c. TPM TIS driver implements that spec so you should only implement a new physical layer.

I had the same thought. Unfortunately, the I2C-TIS specification introduces two relevant changes compared to tpm_tis/tpm_tis_spi:

1. Locality is not encoded into register addresses anymore, but stored in a separate register.
2. Several register addresses have changed (but still contain compatible contents).

I'd still prefer not to duplicate all the high-level logic from tpm_tis_core. But this will probably mean to introduce some new interfaces between tpm_tis_core and the physical layers.

Also, shouldn't the new driver be called tpm_tis_i2c, to group it with all the other (TIS) drivers, that implement a vendor-independent protocol? With tpm_i2c_ptp users might assume that ptp is just another vendor.

Alexander

#6 lore raw
Quoted 1 line · Oshri Alkobi

Alex, Jarkko, thank you very much for your feedbacks!

Please configure your email client to use plain text.

Quoted 7 lines

I totally agree, there are some duplications that can be common, indeed it will require some work in tpm_tis_core.
Since I believe it is not going to happen soon, I would suggest to examine what duplications can currently be dropped from the new driver, so the kernel will support the PTP I2C interface in the meantime.
I will appreciate getting ideas about any tpm_tis_core logic that currently can be used as is by the new drive.

I rather wait for a solution that integrates with our mature stack for TIS (or these days FIFO) than integrate something half-baked. If you want something in, please do right things right.

What you are proposing would mean maintaining duplicate stacks forever.

Quoted 4 lines

Since the TIS is an old specification that mostly defines FIFO for TPM1.2 I would say the name tpm_tis_i2c does not completely reflect its goal. However we really don't have any problem with any name that the group will agree on. Does tpm_ptp_i2c sound better than the current name?

Absolutely not going to use that name. The naming convention is what it is for other drivers that are adapt tpm_tis_core to different HW interfaces.

/Jarkko

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

Hi Jarkko and All,

Thanks for your feedback and sorry for the late response.

Due to the amount of work required to handle this technical feedback and project constraints we need to put this task on hold for the near future. In the meantime, anyone from the community is welcome to take over this code and handle the re-design for the benefit of the entire TPM community.

Thanks again,

Tomer

Quoted 61 lines · On Mon, 15 Jul 2019 at 10:54, <[email protected]> wrote:

-----Original Message-----
From: Jarkko Sakkinen <[email protected]>
Sent: Friday, 5 July 2019 14:28
To: Oshri Alkobi <[email protected]>; Alexander Steffen < [email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; IS20 Oshri Alkoby <[email protected]>; [email protected]; AP MS30 Linux Kernel community <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; IS30 Dan Morav <[email protected]>; IS20 Tomer Maimon <[email protected]>
Subject: Re: [PATCH v2 0/2] char: tpm: add new driver for tpm i2c ptp

Quoted 1 line · Oshri Alkobi

Alex, Jarkko, thank you very much for your feedbacks!

Please configure your email client to use plain text.

Quoted 7 lines

I totally agree, there are some duplications that can be common, indeed it will require some work in tpm_tis_core.
Since I believe it is not going to happen soon, I would suggest to examine what duplications can currently be dropped from the new driver, so the kernel will support the PTP I2C interface in the meantime. I will appreciate getting ideas about any tpm_tis_core logic that currently can be used as is by the new drive.

I rather wait for a solution that integrates with our mature stack for TIS (or these days FIFO) than integrate something half-baked. If you want something in, please do right things right.

What you are proposing would mean maintaining duplicate stacks forever.

Quoted 3 lines

Since the TIS is an old specification that mostly defines FIFO for TPM1.2 I would say the name tpm_tis_i2c does not completely reflect its goal. However we really don't have any problem with any name that

the group will agree on.

Quoted 1 line

Does tpm_ptp_i2c sound better than the current name?

Absolutely not going to use that name. The naming convention is what it is for other drivers that are adapt tpm_tis_core to different HW interfaces.

/Jarkko

===========================================================================================
The privileged confidential information contained in this email is intended for use only by the addressees as indicated by the original sender of this email. If you are not the addressee indicated in this email or are not responsible for delivery of the email to such a person, please kindly reply to the sender indicating this fact and delete all copies of it from your computer and network server immediately. Your cooperation is highly appreciated. It is advised that any unauthorized use of confidential information of Nuvoton is strictly prohibited; and any information in this email irrelevant to the official business of Nuvoton shall be deemed as neither given nor endorsed by Nuvoton.

#9 lore raw
Quoted 7 lines · Tomer Maimon

Thanks for your feedback and sorry for the late response.

Due to the amount of work required to handle this technical feedback and project constraints we need to put this task on hold for the near future.

In the meantime, anyone from the community is welcome to take over this code and handle the re-design for the benefit of the entire TPM community.

Ok, so there is already driver for this called tpm_tis_core.

So you go and create a new module, whose name given the framework of things that we already have deployed, is destined to be tpm_tis_i2c.

Then you roughly implement a new physical layer by using a callback interface provided to you by tpm_tis_core.

The so called re-design was already addressed by Alexander [1].

How hard can it be seriously?

[1] https://lkml.org/lkml/2019/7/4/331

/Jarkko

#10 lore raw

Hi Jarkko and Alexander,

We have made an additional code review on the TPM TIS core driver, it looks quite good and we can connect our new I2C driver to this layer. However, there are several differences between the SPI interface and the I2C interface that will require changes to the TIS core. At a minimum we thought of:
1. Handling TPM Localities in I2C is different
2. Handling I2C CRC - relevant only to I2C bus hence not supported today by TIS core
3. Handling Chip specific issues, since I2C implementation might be slightly different across the various TPM vendors
4. Modify tpm_tis_send_data and tpm_tis_recv_data to work according the TCG Device Driver Guide (optimization on TPM_STS access and send/recv retry) Besides this, during development we might encounter additional differences between SPI and I2C.

We currently target to allocate an eng. to work on this on the second half of August with a goal to have the driver ready for the next kernel merge window.

Regards,
Eyal.

-----Original Message-----
From: Jarkko Sakkinen <[email protected]>
Sent: Monday, July 15, 2019 12:46 PM
To: Tomer Maimon <[email protected]>
Cc: Oshri Alkobi <[email protected]>; Alexander Steffen <[email protected]>; Rob Herring <[email protected]>; Mark Rutland <[email protected]>; [email protected]; [email protected]; Arnd Bergmann <[email protected]>; Greg KH <[email protected]>; IS20 Oshri Alkoby <[email protected]>; devicetree <[email protected]>; AP MS30 Linux Kernel community <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; IS30 Dan Morav <[email protected]>; IS20 Eyal Cohen <[email protected]>
Subject: Re: [PATCH v2 0/2] char: tpm: add new driver for tpm i2c ptp

Quoted 7 lines · Tomer Maimon

Thanks for your feedback and sorry for the late response.

Due to the amount of work required to handle this technical feedback and project constraints we need to put this task on hold for the near future.

In the meantime, anyone from the community is welcome to take over this code and handle the re-design for the benefit of the entire TPM community.

Ok, so there is already driver for this called tpm_tis_core.

So you go and create a new module, whose name given the framework of things that we already have deployed, is destined to be tpm_tis_i2c.

Then you roughly implement a new physical layer by using a callback interface provided to you by tpm_tis_core.

The so called re-design was already addressed by Alexander [1].

How hard can it be seriously?

[1] https://urldefense.proofpoint.com/v2/url?u=https-3A__lkml.org_lkml_2019_7_4_331&d=DwIBAg&c=ue8mO8zgC4VZ4q_aNVKt8G9MC01UFDmisvMR1k-EoDM&r=hjzIxEsS8wf3Ezr__r0ZOjw3kki8jIlQK-SQ5pWhXaM&m=aYs86sTFmxqvlI5rE2AWLGRl0lb9XRuiRKVtsCaXdRM&s=_3MMoq5UISFwMfK4OfgLbA2kMfZVgEfgkaWKqDEUXGw&e=

/Jarkko

===========================================================================================
The privileged confidential information contained in this email is intended for use only by the addressees as indicated by the original sender of this email. If you are not the addressee indicated in this email or are not responsible for delivery of the email to such a person, please kindly reply to the sender indicating this fact and delete all copies of it from your computer and network server immediately. Your cooperation is highly appreciated. It is advised that any unauthorized use of confidential information of Nuvoton is strictly prohibited; and any information in this email irrelevant to the official business of Nuvoton shall be deemed as neither given nor endorsed by Nuvoton.

#11 lore raw
Quoted 3 lines · On 18.07.2019 14:51, [email protected] wrote:

Hi Jarkko and Alexander,

We have made an additional code review on the TPM TIS core driver, it looks quite good and we can connect our new I2C driver to this layer.

Great :) In the meantime, I've done some experiments creating an I2C driver based on tpm_tis_core, see https://patchwork.kernel.org/patch/11049363/ Please have a look at that and provide your feedback (and/or use it as a basis for further implementations).

Quoted 3 lines

However, there are several differences between the SPI interface and the I2C interface that will require changes to the TIS core. At a minimum we thought of:
1. Handling TPM Localities in I2C is different

It turned out not to be that different in the end, see the code mentioned above and my comment here: https://patchwork.kernel.org/cover/11049365/

Quoted 1 line

2. Handling I2C CRC - relevant only to I2C bus hence not supported today by TIS core

That is completely optional, so there is no need to implement it in the beginning. Also, do you expect a huge benefit from that functionality? Are bit flips that much more likely on I2C compared to SPI, which has no CRC at all, but still works fine?

Quoted 1 line

3. Handling Chip specific issues, since I2C implementation might be slightly different across the various TPM vendors

Right, that seems similar to the cr50 issues (https://lkml.org/lkml/2019/7/17/677), so there should probably be a similar way to do it.

Quoted 1 line

4. Modify tpm_tis_send_data and tpm_tis_recv_data to work according the TCG Device Driver Guide (optimization on TPM_STS access and send/recv retry)

Optimizations are always welcome, but I'd expect basic communication to work already with the current code (though maybe not as efficiently as possible).

Quoted 6 lines

Besides this, during development we might encounter additional differences between SPI and I2C.

We currently target to allocate an eng. to work on this on the second half of August with a goal to have the driver ready for the next kernel merge window.

Regards,
Eyal.

#12 lore raw

Hi Alexander, Jarkko and Eyal,

A first I2C TCG patch (tpm_tis_i2c.c) has been proposed in the same time as tpm_tis_spi.c by Christophe 3 years ago.

https://patchwork.kernel.org/patch/8628681/

At the time, we have had two concerns :
1) I2C TPM component number, in the market, compliant with new I2C TCG specification to validate new I2C driver.
2) Lots changing was already provided by tpm_tis_spi.c on 4.8.

That's why Tpm_tis_i2c.c has been postponed.

Tpm_tis_spi Linux driver is now robust, if we have several different I2C TPM solutions today to validate a tpm_tis_i2c driver, I 'm ready to contribute to it for validation (STmicro TPM) or propose a solution compatible on 5.1 linux driver if needed under timeframe proposed (second half of august).

Best Regards,

Benoit

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Alexander Steffen
Sent: jeudi 18 juillet 2019 19:10
To: [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 0/2] char: tpm: add new driver for tpm i2c ptp

Quoted 3 lines · On 18.07.2019 14:51, [email protected] wrote:

Hi Jarkko and Alexander,

We have made an additional code review on the TPM TIS core driver, it looks quite good and we can connect our new I2C driver to this layer.

Great :) In the meantime, I've done some experiments creating an I2C driver based on tpm_tis_core, see https://patchwork.kernel.org/patch/11049363/ Please have a look at that and provide your feedback (and/or use it as a basis for further implementations).

Quoted 3 lines

However, there are several differences between the SPI interface and the I2C interface that will require changes to the TIS core. At a minimum we thought of:
1. Handling TPM Localities in I2C is different

It turned out not to be that different in the end, see the code mentioned above and my comment here:
https://patchwork.kernel.org/cover/11049365/

Quoted 2 lines

2. Handling I2C CRC - relevant only to I2C bus hence not supported today by TIS core

That is completely optional, so there is no need to implement it in the beginning. Also, do you expect a huge benefit from that functionality? Are bit flips that much more likely on I2C compared to SPI, which has no CRC at all, but still works fine?

Quoted 2 lines

3. Handling Chip specific issues, since I2C implementation might be slightly different across the various TPM vendors

Right, that seems similar to the cr50 issues (https://lkml.org/lkml/2019/7/17/677), so there should probably be a similar way to do it.

Quoted 3 lines

4. Modify tpm_tis_send_data and tpm_tis_recv_data to work according the TCG Device Driver Guide (optimization on TPM_STS access and send/recv retry)

Optimizations are always welcome, but I'd expect basic communication to work already with the current code (though maybe not as efficiently as possible).

Quoted 6 lines

Besides this, during development we might encounter additional differences between SPI and I2C.

We currently target to allocate an eng. to work on this on the second half of August with a goal to have the driver ready for the next kernel merge window.

Regards,
Eyal.

#13 lore raw

Hi Benoit,

good to see you're still around.

Quoted 5 lines · Benoit HOUYERE

Hi Alexander, Jarkko and Eyal,

A first I2C TCG patch (tpm_tis_i2c.c) has been proposed in the same time as tpm_tis_spi.c by Christophe 3 years ago.

https://patchwork.kernel.org/patch/8628681/

Thanks for mentioning this. I forgot it exists, since it was still on the old mailing list.

Quoted 7 lines

At the time, we have had two concerns :
1) I2C TPM component number, in the market, compliant with new I2C TCG specification to validate new I2C driver.
2) Lots changing was already provided by tpm_tis_spi.c on 4.8.

That's why Tpm_tis_i2c.c has been postponed.

Tpm_tis_spi Linux driver is now robust, if we have several different I2C TPM solutions today to validate a tpm_tis_i2c driver, I 'm ready to contribute to it for validation (STmicro TPM) or propose a solution compatible on 5.1 linux driver if needed under timeframe proposed (second half of august).

Could you run your tests against the simple implementation that I posted a while ago (https://patchwork.kernel.org/cover/11049365/) and provide your feedback? Since it is already based on the current tpm_tis_core, it is probably easier to integrate necessary changes there.

By the way, has it gotten any easier in the meantime to get hold of your TPMs to use them for kernel tests?

Alexander

#14 lore raw

Hi Steffen,

We have performed test against your simple implementation. For basic test it was ok, however for stress test, your implementation does not take in account NACK and it failed.

In PTP document, in chapter7.2.2.1.2 (Register write with address NACK), it indicates : "it's a good practice to repeat the current cycle using the correct I2C device address".

In other implementation,
https://patchwork.kernel.org/patch/8628681/

tpm_tis_i2c_read_bytes and tpm_tis_i2c_write_bytes handle NACK with a for loop.

+ for (i = 0; i < TPM_RETRY && ret < 0; i++) {
+ tpm_tis_i2c_sleep_guard_time(phy, TPM_I2C_SEND);
+ ret = i2c_master_send(phy->client, &i2c_reg, 1);
+ mod_timer(&phy->guard_timer, phy->guard_time);
+ }
+
+ if (ret < 0)
+ goto exit;
+
+ ret = -1;
+ for (i = 0; i < TPM_RETRY && ret < 0; i++) {
+ tpm_tis_i2c_sleep_guard_time(phy, TPM_I2C_RECV);
+ ret = i2c_master_recv(phy->client, result, len * size);
+ mod_timer(&phy->guard_timer, phy->guard_time);
+ }

I think that we should implement it before to include tpm_tis_i2c.c officially.

Thanks in advance,

Best Regards,

Benoit

-----Original Message-----
From: Alexander Steffen <[email protected]>
Sent: mardi 30 juillet 2019 19:42
To: Benoit HOUYERE <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Christophe Ricard ([email protected]) <[email protected]>; Elena WILLIS <[email protected]>; Olivier COLLART <[email protected]>
Subject: Re: [PATCH v2 0/2] char: tpm: add new driver for tpm i2c ptp

Hi Benoit,

good to see you're still around.

Quoted 5 lines · Benoit HOUYERE

Hi Alexander, Jarkko and Eyal,

A first I2C TCG patch (tpm_tis_i2c.c) has been proposed in the same time as tpm_tis_spi.c by Christophe 3 years ago.

https://patchwork.kernel.org/patch/8628681/

Thanks for mentioning this. I forgot it exists, since it was still on the old mailing list.

Quoted 7 lines

At the time, we have had two concerns :
1) I2C TPM component number, in the market, compliant with new I2C TCG specification to validate new I2C driver.
2) Lots changing was already provided by tpm_tis_spi.c on 4.8.

That's why Tpm_tis_i2c.c has been postponed.

Tpm_tis_spi Linux driver is now robust, if we have several different I2C TPM solutions today to validate a tpm_tis_i2c driver, I 'm ready to contribute to it for validation (STmicro TPM) or propose a solution compatible on 5.1 linux driver if needed under timeframe proposed (second half of august).

Could you run your tests against the simple implementation that I posted a while ago (https://patchwork.kernel.org/cover/11049365/) and provide your feedback? Since it is already based on the current tpm_tis_core, it is probably easier to integrate necessary changes there.

By the way, has it gotten any easier in the meantime to get hold of your TPMs to use them for kernel tests?

Alexander

#15 lore raw
In reply to Alexander Steffen
Quoted 4 lines · Alexander Steffen
Quoted 2 lines · On 18.07.2019 14:51, [email protected] wrote:

Hi Jarkko and Alexander,

Quoted 8 lines
Quoted 1 line

We have made an additional code review on the TPM TIS core driver, it looks quite good and we can connect our new I2C driver to this layer.

Great :) In the meantime, I've done some experiments creating an I2C driver based on tpm_tis_core, see
https://patchwork.kernel.org/patch/11049363/ Please have a look at that and provide your feedback (and/or use it as a basis for further implementations).

Sorry for the late response.

Thanks Alexander, indeed it looks much simpler.
I've checked it with Nuvoton's TPM - basic TPM commands work, I only had to remove the first msg from the read/write I2C transmitting (from/to TPM_LOC_SEL), the TPM couldn't handle two register writes in a sequence.
Actually it is more efficient to set TPM_LOC_SEL only before locality check/request/relinquish - it is sticky.
I still didn't manage to work with interrupts, will debug it.

We weren't aware to the implementation of Christophe/ST which looks good and can be complement to yours.
If no one is currently working on that, we can prepare a new patch that is based on both.
Please let us know.

Quoted 8 lines
Quoted 3 lines

However, there are several differences between the SPI interface and the I2C interface that will require changes to the TIS core. At a minimum we thought of:
1. Handling TPM Localities in I2C is different

It turned out not to be that different in the end, see the code mentioned above and my comment here:
https://patchwork.kernel.org/cover/11049365/

Quoted 7 lines
Quoted 1 line

2. Handling I2C CRC - relevant only to I2C bus hence not supported today by TIS core

That is completely optional, so there is no need to implement it in the beginning. Also, do you expect a huge benefit from that functionality? Are bit flips that much more likely on I2C compared to SPI, which has no CRC at all, but still works fine?

I2C is noisy bus with potentially more devices with larger variety than SPI. I2C may have more than one master and may have collisions and/or arbitration.
Still we can start w/o CRC for the first stage and add it later. BTW, Christophe already did most of the work
(https://patchwork.kernel.org/patch/8628661/)

Quoted 5 lines
Quoted 1 line

3. Handling Chip specific issues, since I2C implementation might be slightly different across the various TPM vendors

Right, that seems similar to the cr50 issues
(https://lkml.org/lkml/2019/7/17/677), so there should probably be a similar way to do it.

Got it. We hope things will work for us without having another driver, but it's an option.

Quoted 13 lines
Quoted 2 lines

4. Modify tpm_tis_send_data and tpm_tis_recv_data to work according the TCG Device Driver Guide (optimization on TPM_STS access and send/recv retry)

Optimizations are always welcome, but I'd expect basic communication to work already with the current code (though maybe not as efficiently as possible).

Quoted 6 lines

Besides this, during development we might encounter additional differences between SPI and I2C.

We currently target to allocate an eng. to work on this on the second half of August with a goal to have the driver ready for the next kernel merge window.

Regards,
Eyal.

#16 lore raw
Quoted 15 lines · Oshri Alkobi
Quoted 4 lines · Alexander Steffen
Quoted 2 lines · On 18.07.2019 14:51, [email protected] wrote:

Hi Jarkko and Alexander,

Quoted 8 lines
Quoted 1 line

We have made an additional code review on the TPM TIS core driver, it looks quite good and we can connect our new I2C driver to this layer.

Great :) In the meantime, I've done some experiments creating an I2C driver based on tpm_tis_core, see
https://patchwork.kernel.org/patch/11049363/ Please have a look at that and provide your feedback (and/or use it as a basis for further implementations).

Quoted 4 lines

Sorry for the late response.

Thanks Alexander, indeed it looks much simpler. I've checked it with Nuvoton's TPM - basic TPM commands work

Nice :)

Quoted 6 lines

I only
had to remove the first msg from the read/write I2C transmitting (from/to TPM_LOC_SEL), the TPM couldn't handle two register writes in a sequence.
Actually it is more efficient to set TPM_LOC_SEL only before locality check/request/relinquish - it is sticky.

There is one problem though: Do we assume that only the kernel driver will communicate with the TPM or might there be something else that also talks to the TPM?

If it is only the kernel driver, we could probably skip setting TPM_LOC_SEL at all, since it defaults to 0 and the driver will never use anything else. If something else does its own I2C communication with the TPM, it might write different values to TPM_LOC_SEL at any time, causing the kernel driver to use a different locality than intended. This was the reason I always set TPM_LOC_SEL within the same transaction.

Quoted 1 line

I still didn't manage to work with interrupts, will debug it.

Interrupt support might be broken in general at the moment, see this thread: https://www.spinics.net/lists/linux-integrity/msg08663.html

Quoted 5 lines

We weren't aware to the implementation of Christophe/ST which looks good and can be complement to yours.
If no one is currently working on that, we can prepare a new patch that is based on both.
Please let us know.

I won't have the time to do anything, at least for the next two weeks, so feel free to pick it up.

Quoted 16 lines
Quoted 8 lines
Quoted 3 lines

However, there are several differences between the SPI interface and the I2C interface that will require changes to the TIS core. At a minimum we thought of:
1. Handling TPM Localities in I2C is different

It turned out not to be that different in the end, see the code mentioned above and my comment here:
https://patchwork.kernel.org/cover/11049365/

Quoted 7 lines
Quoted 1 line

2. Handling I2C CRC - relevant only to I2C bus hence not supported today by TIS core

That is completely optional, so there is no need to implement it in the beginning. Also, do you expect a huge benefit from that functionality? Are bit flips that much more likely on I2C compared to SPI, which has no CRC at all, but still works fine?

Quoted 3 lines

I2C is noisy bus with potentially more devices with larger variety than SPI. I2C may have more than one master and may have collisions and/or arbitration.

If multi-master usage is a concern, there are probably a lot more places in the driver that need to be adapted to deal with concurrent access/data corruption. For now, I'd assume a single master, similar to SPI.

Alexander

#17 lore raw
Quoted 47 lines · Alexander Steffen
Quoted 15 lines · Oshri Alkobi
Quoted 4 lines · Alexander Steffen
Quoted 2 lines · On 18.07.2019 14:51, [email protected] wrote:

Hi Jarkko and Alexander,

Quoted 8 lines
Quoted 1 line

We have made an additional code review on the TPM TIS core driver, it looks quite good and we can connect our new I2C driver to this layer.

Great :) In the meantime, I've done some experiments creating an I2C driver based on tpm_tis_core, see
https://patchwork.kernel.org/patch/11049363/ Please have a look at that and provide your feedback (and/or use it as a basis for further implementations).

Quoted 4 lines

Sorry for the late response.

Thanks Alexander, indeed it looks much simpler. I've checked it with Nuvoton's TPM - basic TPM commands work

Nice :)

Quoted 6 lines

I only
had to remove the first msg from the read/write I2C transmitting (from/to TPM_LOC_SEL), the TPM couldn't handle two register writes in a sequence.
Actually it is more efficient to set TPM_LOC_SEL only before locality check/request/relinquish - it is sticky.

There is one problem though: Do we assume that only the kernel driver will communicate with the TPM or might there be something else that also talks to the TPM?

If it is only the kernel driver, we could probably skip setting TPM_LOC_SEL at all, since it defaults to 0 and the driver will never use anything else. If something else does its own I2C communication with the TPM, it might write different values to TPM_LOC_SEL at any time, causing the kernel driver to use a different locality than intended. This was the reason I always set TPM_LOC_SEL within the same transaction.

Quoted 1 line

I still didn't manage to work with interrupts, will debug it.

Interrupt support might be broken in general at the moment, see this
thread: https://www.spinics.net/lists/linux-integrity/msg08663.html

Quoted 9 lines
Quoted 5 lines

We weren't aware to the implementation of Christophe/ST which looks good and can be complement to yours.
If no one is currently working on that, we can prepare a new patch that is based on both.
Please let us know.

I won't have the time to do anything, at least for the next two weeks, so feel free to pick it up.

Great, we will start working on it.

Quoted 20 lines
Quoted 16 lines
Quoted 8 lines
Quoted 3 lines

However, there are several differences between the SPI interface and the I2C interface that will require changes to the TIS core. At a minimum we thought of:
1. Handling TPM Localities in I2C is different

It turned out not to be that different in the end, see the code mentioned above and my comment here:
https://patchwork.kernel.org/cover/11049365/

Quoted 7 lines
Quoted 1 line

2. Handling I2C CRC - relevant only to I2C bus hence not supported today by TIS core

That is completely optional, so there is no need to implement it in the beginning. Also, do you expect a huge benefit from that functionality? Are bit flips that much more likely on I2C compared to SPI, which has no CRC at all, but still works fine?

Quoted 3 lines

I2C is noisy bus with potentially more devices with larger variety than SPI. I2C may have more than one master and may have collisions and/or arbitration.

Quoted 5 lines

If multi-master usage is a concern, there are probably a lot more places in the driver that need to be adapted to deal with concurrent access/data corruption. For now, I'd assume a single master, similar to SPI.

Alexander

Oshri

#18 lore raw
In reply to Tomer Maimon
Quoted 8 lines · Tomer Maimon

Hi Jarkko and All,

Thanks for your feedback and sorry for the late response.

Due to the amount of work required to handle this technical feedback and project constraints we need to put this task on hold for the near future.

In the meantime, anyone from the community is welcome to take over this code and handle the re-design for the benefit of the entire TPM community.

Too bad you lack the time to finish this.

If somebody else were to pick it up, would it be possible for you to provide a couple of TPMs that implement this protocol, so that it can be properly tested?

Alexander

#19 lore raw
In reply to Alexander Steffen
Quoted 6 lines · Alexander Steffen
Quoted 2 lines · Jarkko Sakkinen

Check out tpm_tis_core.c and tpm_tis_spi.c. TPM TIS driver implements that spec so you should only implement a new physical layer.

I had the same thought. Unfortunately, the I2C-TIS specification introduces two relevant changes compared to tpm_tis/tpm_tis_spi:

I doubt that there was any comparison made.

Quoted 8 lines

1. Locality is not encoded into register addresses anymore, but stored in a separate register.
2. Several register addresses have changed (but still contain compatible contents).

I'd still prefer not to duplicate all the high-level logic from tpm_tis_core. But this will probably mean to introduce some new interfaces between tpm_tis_core and the physical layers.

Agreed. Some plumbing needs to be done in tpm_tis_core to make it work for this. We definitely do not want to duplicate code that has been field tested for years.

Quoted 4 lines

Also, shouldn't the new driver be called tpm_tis_i2c, to group it with all the other (TIS) drivers, that implement a vendor-independent protocol? With tpm_i2c_ptp users might assume that ptp is just another vendor.

Yes, absolutely. I guess the driver has been done without looking at what already exist in the TPM kernel stack.

/Jarkko