Add tpm i2c ptp driver
Subsystems (3)
v8 cover Add tpm i2c ptp driver
From: Amir Mizinski <[email protected]>
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.
Interrupts are not implemented yet, preparing it for the next patch.
This patch is based on initial work by oshri Alkoby, Alexander Steffen and Christophe Ricard
Changes since version 1:
-"char:tpm:Add check_data handle to tpm_tis_phy_ops in order to check data integrity"
- Fixed and extended commit description.
- Fixed an issue regarding handling max retries.
-"dt-bindings: tpm: Add YAML schema for TPM TIS I2C options":
-Converted "tpm_tis_i2c.txt" to "tpm-tis-i2c.yaml".
- Renamed "tpm_tis-i2c" to "tpm-tis-i2c".
- Removed interrupts properties.
-"char: tpm: add tpm_tis_i2c driver"
- Replaced "tpm_tis-i2c" with "tpm-tis-i2c" in "tpm_tis_i2c.c".
Addressed comments from:
- Jarkko Sakkinen: https://patchwork.kernel.org/patch/11236257/
- Rob Herring: https://patchwork.kernel.org/patch/11236253/
Changes since version 2:
- Added 2 new commits with improvements suggested by Benoit Houyere.
-"Fix expected bit handling and send all bytes in one shot without last byte in exception" -"Handle an exception for TPM Firmware Update mode."
- Updated patch to latest v5.5
-"dt-bindings: tpm: Add YAML schema for TPM TIS I2C options"
- Added "interrupts" and "crc-checksum" to properties.
- Updated binding description and commit info.
-"char: tpm: add tpm_tis_i2c driver" (suggested by Benoit Houyere)
- Added repeat I2C frame after NACK.
- Checksum I2C feature activation in DTS file configuration.
Addressed comments from:
- Rob Herring: https://lore.kernel.org/patchwork/patch/1161287/
Changes since version 3:
- Updated patch to latest v5.6
- Updated commits headlines and development credit format by Jarkko Sakkinen suggestion -"tpm: tpm_tis: Make implementation of read16 read32 write32 optional"
- Updated commit description.
-"dt-bindings: tpm: Add YAML schema for TPM TIS I2C options"
- Fixed 'make dt_binding_check' errors on YAML file.
- Removed interrupts from required and examples since there is no use for them in current patch.
Addressed comments from:
- Jarkko Sakkinen: https://lore.kernel.org/patchwork/patch/1192101/
- Rob Herring: https://lore.kernel.org/patchwork/patch/1192099/
Changes since version 4:
-"tpm: tpm_tis: Make implementation of read16 read32 write32 optional"
-Added a "Reviewed-by" tag:
-"tpm: tpm_tis: Add check_data handle to tpm_tis_phy_ops in order to check data integrity"
-Fixed credit typos.
-"tpm: tpm_tis: rewrite "tpm_tis_req_canceled()""
-Added fixes tag and removed changes for STM.
-"tpm: tpm_tis: Fix expected bit handling and send all bytes in one shot without last byte in exception"
-Fixed typos, edited description to be clearer, and added a "Suggested-by" tag.
-"tpm: Handle an exception for TPM Firmware Update mode."
-Added a "Suggested-by" tag.
-"dt-bindings: tpm: Add YAML schema for TPM TIS I2C options"
-Fixed 'make dt_binding_check' errors.
-"tpm: tpm_tis: add tpm_tis_i2c driver"
-Added tested-by tag by Eddie James.
-Fixed indent in Kconfig file.
-Fixed 'MODULE_DESCRIPTION'.
Addressed comments from:
- Jarkko Sakkinen: https://patchwork.kernel.org/patch/11467645/
https://patchwork.kernel.org/patch/11467655/ https://patchwork.kernel.org/patch/11467643/ https://patchwork.kernel.org/patch/11467659/ https://patchwork.kernel.org/patch/11467651/
- Rob Herring: https://patchwork.kernel.org/patch/11467653/
- Randy Dunlap: https://patchwork.kernel.org/patch/11467651/
- Eddie James: https://lore.kernel.org/patchwork/patch/1192104/
Changes since version 5:
-"tpm: tpm_tis: Add check_data handle to tpm_tis_phy_ops"
-Updated short description and fixed long description to be more clear.
Addressed comments from:
- Jarkko Sakkinen: https://lkml.org/lkml/2020/4/6/748
Changes since version 6:
-"tpm: tpm_tis: Make implementation of read16, read32 and write32 optional"
-Fixed short description.
-fixed long description proofreading issues.
-"tpm: tpm_tis: Add check_data handle to tpm_tis_phy_ops"
-Fixed long description by Jarkko comments and proofreading issues. -Replaced "check_data" with verify_data_integrity". -New line before return statement.
-"tpm: tpm_tis: rewrite "tpm_tis_req_canceled()"
-Fixed line over 80 characters.
-fixed long description proofreading issues.
-" tpm: tpm_tis: Fix expected bit handling and send all bytes in one shot"
-fixed long description proofreading issues.
-"dt-bindings: tpm: Add YAML schema for TPM TIS I2C option"
-Replaced "tpm-tis-i2c@2e" with "tpm_tis@2e".
-Fixed CRC_Checksum description.
-"tpm: tpm_tis: add tpm_tis_i2c driver"
-Replaced "depends on CRC_CCIT" with "select CRC_CCIT". -Added tested-by tag by Joel Stanley.
-Fixed checkpatch.pl warnings.
Addressed comments from:
- Jarkko Sakkinen:
https://lore.kernel.org/patchwork/patch/1221336/ https://lore.kernel.org/patchwork/patch/1221337/ https://lore.kernel.org/patchwork/patch/1221339/ - Joel Stanley: https://lore.kernel.org/patchwork/patch/1220543/ - Rob Herring: https://lore.kernel.org/patchwork/patch/1221334/
Changes since version 7:
- Added a new commit with improvements suggested by Benoit Houyere. -"tpm: tpm_tis: verify TPM_STS register is valid after locality request"
-"tpm: tpm_tis: Rewrite "tpm_tis_req_canceled()""
-Fixed Hash for Fixes tag.
-"tpm: Add YAML schema for TPM TIS I2C options"
-Added a compatible string specific to the nuvoton npct75x chip.
-"tpm: tpm_tis: add tpm_tis_i2c driver"
- added a compatible string according to yaml file.
Addressed comments from:
- Jarkko Sakkinen:
https://lore.kernel.org/patchwork/patch/1231524/ - Rob Herring: https://lore.kernel.org/patchwork/patch/1231526/
Amir Mizinski (8):
tpm: tpm_tis: Make implementation of read16, read32 and write32
optional
tpm: tpm_tis: Add verify_data_integrity handle toy tpm_tis_phy_ops
tpm: tpm_tis: Rewrite "tpm_tis_req_canceled()"
tpm: tpm_tis: Fix expected bit handling and send all bytes in one shot
without last byte in exception
tpm: Handle an exception for TPM Firmware Update mode.
verify TPM_STS register is valid after locality request
tpm: Add YAML schema for TPM TIS I2C options
tpm: tpm_tis: add tpm_tis_i2c driver
.../bindings/security/tpm/tpm-tis-i2c.yaml | 51 ++++ drivers/char/tpm/Kconfig | 12 + drivers/char/tpm/Makefile | 1 + drivers/char/tpm/tpm2-cmd.c | 4 + drivers/char/tpm/tpm_tis_core.c | 188 +++++++------ drivers/char/tpm/tpm_tis_core.h | 41 ++- drivers/char/tpm/tpm_tis_i2c.c | 292 +++++++++++++++++++++ drivers/char/tpm/tpm_tis_spi_main.c | 41 --- include/linux/tpm.h | 1 + 9 files changed, 502 insertions(+), 129 deletions(-) create mode 100644 Documentation/devicetree/bindings/security/tpm/tpm-tis-i2c.yaml create mode 100644 drivers/char/tpm/tpm_tis_i2c.c
Signature · 1 line
2.7.4
PATCH v8 1/8 tpm: tpm_tis: Make implementation of read16, read32 and write32 optional
From: Amir Mizinski <[email protected]>
Only tpm_tis can use memory-mapped I/O, which is truly mapped into the kernel's memory space. Therefore, using ioread16/ioread32/iowrite32 turns into a straightforward pointer dereference.
Every other driver requires more complicated operations to read more than one byte at a time and will just fall back to read_bytes/write_bytes. Therefore, move this common code out of tpm_tis_spi and into tpm_tis_core so that it is used automatically when low-level drivers do not implement the specialized methods.
--- drivers/char/tpm/tpm_tis_core.h | 38 +++++++++++++++++++++++++++++++--- drivers/char/tpm/tpm_tis_spi_main.c | 41 ------------------------------------- 2 files changed, 35 insertions(+), 44 deletions(-)
drivers/char/tpm/tpm_tis_core.h +35 -3
@@ -122,13 +122,35 @@ static inline int tpm_tis_read8(struct tpm_tis_data *data, u32 addr, u8 *result)static inline int tpm_tis_read16 (struct tpm_tis_data *data,u32 addr,u16 *result) { -return data->phy_ops->read16 (data, addr, result); +__le16 result_le; +int rc; + +if (data->phy_ops->read16) +return data->phy_ops->read16 (data, addr, result); + + rc = data->phy_ops->read_bytes (data, addr,sizeof (u16), + (u8 *)&result_le); +if (!rc) + *result =le16_to_cpu (result_le); + +return rc; }static inline int tpm_tis_read32 (struct tpm_tis_data *data,u32 addr,u32 *result) { -return data->phy_ops->read32 (data, addr, result); +__le32 result_le; +int rc; + +if (data->phy_ops->read32) +return data->phy_ops->read32 (data, addr, result); + + rc = data->phy_ops->read_bytes (data, addr,sizeof (u32), + (u8 *)&result_le); +if (!rc) + *result =le32_to_cpu (result_le); + +return rc; } static inline int tpm_tis_write_bytes(struct tpm_tis_data *data, u32 addr,
@@ -145,7 +167,17 @@ static inline int tpm_tis_write8(struct tpm_tis_data *data, u32 addr, u8 value)static inline int tpm_tis_write32 (struct tpm_tis_data *data,u32 addr,u32 value) { -return data->phy_ops->write32 (data, addr, value); +__le32 value_le; +int rc; + +if (data->phy_ops->write32) +return data->phy_ops->write32 (data, addr, value); + + value_le =cpu_to_le32 (value); + rc = data->phy_ops->write_bytes (data, addr,sizeof (u32), + (u8 *)&value_le); + +return rc; }static inline bool is_bsw (void )
drivers/char/tpm/tpm_tis_spi_main.c +0 -41
53 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v8 1/8] tpm: tpm_tis: Make implementation of read16, read32 and write32 optional
Quoted 11 lines · On Tue, 2020-05-12 at 17:14 +0300, [email protected] wrote:
From: Amir Mizinski <[email protected]>
Only
tpm_tiscan use memory-mapped I/O, which is truly mapped into the kernel's memory space. Therefore, using ioread16/ioread32/iowrite32 turns into a straightforward pointer dereference.
Every other driver requires more complicated operations to read more than one byte at a time and will just fall back to read_bytes/write_bytes. Therefore, move this common code out oftpm_tis_spiand intotpm_tis_coreso that it is used automatically when low-level drivers do not implement the specialized methods.
Quoted 4 lines
Co-developed-by Alexander Steffen <[email protected]>Signed-off-by Alexander Steffen <[email protected]>Signed-off-by Amir Mizinski <[email protected]>Reviewed-by Jarkko Sakkinen <[email protected]>
OK, so I applied this one:
http://git.infradead.org/users/jjs/linux-tpmdd.git/commit/fa05dc792ea02043f3c21467cb4485a38ac19bdf
I.e. no need to carry this one any more in the series. Sorry that I haven't done this before (should have).
/Jarkko
Re: [PATCH v8 1/8] tpm: tpm_tis: Make implementation of read16, read32 and write32 optional
Quoted 17 lines · Jarkko Sakkinen
Quoted 11 lines · On Tue, 2020-05-12 at 17:14 +0300, [email protected] wrote:
From: Amir Mizinski <[email protected]>
Only
tpm_tiscan use memory-mapped I/O, which is truly mapped into the kernel's memory space. Therefore, using ioread16/ioread32/iowrite32 turns into a straightforward pointer dereference.
Every other driver requires more complicated operations to read more than one byte at a time and will just fall back to read_bytes/write_bytes. Therefore, move this common code out oftpm_tis_spiand intotpm_tis_coreso that it is used automatically when low-level drivers do not implement the specialized methods.Quoted 4 lines
Co-developed-by Alexander Steffen <[email protected]>Signed-off-by Alexander Steffen <[email protected]>Signed-off-by Amir Mizinski <[email protected]>Reviewed-by Jarkko Sakkinen <[email protected]>
Quoted 6 lines
OK, so I applied this one:
http://git.infradead.org/users/jjs/linux-tpmdd.git/commit/fa05dc792ea02043f3c21467cb4485a38ac19bdf
I.e. no need to carry this one any more in the series. Sorry that I haven't done this before (should have).
Dropped it. Breaks the compilation:
ld: drivers/char/tpm/tpm_tis_spi_cr50.o:(.rodata+0x10): undefined reference to `tpm_tis_spi_read16'
ld: drivers/char/tpm/tpm_tis_spi_cr50.o:(.rodata+0x18): undefined reference to `tpm_tis_spi_read32'
ld: drivers/char/tpm/tpm_tis_spi_cr50.o:(.rodata+0x20): undefined reference to `tpm_tis_spi_write32'
Please fix this issue in the next version of the patch and remove my reviewed-by. I will have to re-review the patch.
/Jarkko
kbuild test robot
build botRe: [PATCH v8 1/8] tpm: tpm_tis: Make implementation of read16, read32 and write32 optional
In reply to [email protected]Thank you for the patch! Yet something to improve:
Hi,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on robh/for-next arm-soc/for-next linus/master v5.7-rc5 next-20200512] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/amirmizi6-gmail-com/Add-tpm-i2c-ptp-driver/20200514-154109 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 84c1e51d7df85332705ffebc40ef135205492036 config: h8300-randconfig-r024-20200514 (attached as .config) compiler: h8300-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=h8300
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>, old ones prefixed by <<):
h8300-linux-ld: section .init.text LMA [00000000004a1318,00000000004ed689] overlaps section .text LMA [0000000000000158,0000000000be5e95]
h8300-linux-ld: section .data VMA [0000000000400000,00000000004a1317] overlaps section .text VMA [0000000000000158,0000000000be5e95]
h8300-linux-ld: arch/h8300/kernel/entry.o: in function `resume_kernel':arch/h8300/kernel/entry.S:324: undefined reference to `TI_PRE_COUNT'
>> h8300-linux-ld: drivers/char/tpm/tpm_tis_spi_cr50.o:(.rodata+0x8): undefined reference to `tpm_tis_spi_read16' >> h8300-linux-ld: drivers/char/tpm/tpm_tis_spi_cr50.o:(.rodata+0xc): undefined reference to `tpm_tis_spi_read32' >> h8300-linux-ld: drivers/char/tpm/tpm_tis_spi_cr50.o:(.rodata+0x10): undefined reference to `tpm_tis_spi_write32'
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kbuild test robot
build botRe: [PATCH v8 1/8] tpm: tpm_tis: Make implementation of read16, read32 and write32 optional
In reply to [email protected]Thank you for the patch! Yet something to improve:
Hi,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on robh/for-next arm-soc/for-next linus/master v5.7-rc5] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/amirmizi6-gmail-com/Add-tpm-i2c-ptp-driver/20200514-154109 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 84c1e51d7df85332705ffebc40ef135205492036 config: alpha-allyesconfig (attached as .config) compiler: alpha-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=alpha
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> alpha-linux-ld: drivers/char/tpm/tpm_tis_spi_cr50.o:(.data.rel.ro+0x10): undefined reference to `tpm_tis_spi_read16' >> alpha-linux-ld: drivers/char/tpm/tpm_tis_spi_cr50.o:(.data.rel.ro+0x18): undefined reference to `tpm_tis_spi_read32' >> alpha-linux-ld: drivers/char/tpm/tpm_tis_spi_cr50.o:(.data.rel.ro+0x20): undefined reference to `tpm_tis_spi_write32'
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH v8 2/8 tpm: tpm_tis: Add verify_data_integrity handle toy tpm_tis_phy_ops
In reply to [email protected]From: Amir Mizinski <[email protected]>
To validate data integrity we need to compute the CRC over the data sent at a lower layer (I2C for instance).
To do this, tpm_tis_verify_data_integrity() calls a "verify_data_integrity" operation (if available).
If the data integrity check fails, a retry to save the sent/received data is implemented in the tpm_tis_send_main()/tpm_tis_recv() functions.
--- drivers/char/tpm/tpm_tis_core.c | 104 +++++++++++++++++++++++++--------------- drivers/char/tpm/tpm_tis_core.h | 3 ++ 2 files changed, 69 insertions(+), 38 deletions(-)
drivers/char/tpm/tpm_tis_core.c +66 -38
@@ -242,6 +242,17 @@ static u8 tpm_tis_status(struct tpm_chip *chip)return status; } +static bool tpm_tis_verify_data_integrity (struct tpm_chip *chip,const u8 *buf, +size_t len) +{ +struct tpm_tis_data *priv =dev_get_drvdata (&chip->dev); + +if (priv->phy_ops->verify_data_integrity) +return priv->phy_ops->verify_data_integrity (priv, buf, len); + +return true; +} +static void tpm_tis_ready (struct tpm_chip *chip) {struct tpm_tis_data *priv =dev_get_drvdata (&chip->dev);
@@ -308,47 +319,59 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count) {struct tpm_tis_data *priv =dev_get_drvdata (&chip->dev);int size =0 ; -int status; +int status, i;u32 expected; +bool data_valid = false; -if (count <TPM_HEADER_SIZE ) { - size = -EIO ; - goto out; - } +for (i =0 ; i <TPM_RETRY ; i++) { +if (count <TPM_HEADER_SIZE ) { + size = -EIO ; + goto out; + } - size =recv_data (chip, buf,TPM_HEADER_SIZE ); -/* read first 10 bytes, including tag, paramsize, and result */ -if (size <TPM_HEADER_SIZE ) { -dev_err (&chip->dev,"Unable to read header\n" ); - goto out; - } + size =recv_data (chip, buf,TPM_HEADER_SIZE ); +/* read first 10 bytes, including tag, paramsize, and result */ +if (size <TPM_HEADER_SIZE ) { +dev_err (&chip->dev,"Unable to read header\n" ); + goto out; + } - expected =be32_to_cpu (*(__be32 *) (buf +2 )); -if (expected > count || expected <TPM_HEADER_SIZE ) { - size = -EIO ; - goto out; - } + expected =be32_to_cpu (*(__be32 *) (buf +2 )); +if (expected > count || expected <TPM_HEADER_SIZE ) { + size = -EIO ; + goto out; + } - size +=recv_data (chip, &buf[TPM_HEADER_SIZE ], - expected -TPM_HEADER_SIZE ); -if (size < expected) { -dev_err (&chip->dev,"Unable to read remainder of result\n" ); - size = -ETIME ; - goto out; - } + size +=recv_data (chip, &buf[TPM_HEADER_SIZE ], + expected -TPM_HEADER_SIZE ); +if (size < expected) { +dev_err (&chip->dev,"Unable to read remainder of result\n" ); + size = -ETIME ; + goto out; + } -if (wait_for_tpm_stat (chip,TPM_STS_VALID , chip->timeout_c, - &priv->int_queue, false) <0 ) { - size = -ETIME ; - goto out; +if (wait_for_tpm_stat (chip,TPM_STS_VALID , chip->timeout_c, + &priv->int_queue, false) <0 ) { + size = -ETIME ; + goto out; + } + + status =tpm_tis_status (chip); +if (status &TPM_STS_DATA_AVAIL ) {/* retry? */ +dev_err (&chip->dev,"Error left over data\n" ); + size = -EIO ; + goto out; + } + + data_valid =tpm_tis_verify_data_integrity (chip, buf, size); +if (!data_valid) +tpm_tis_write8 (priv,TPM_STS (priv->locality), +TPM_STS_RESPONSE_RETRY ); +else +break ; } - status =tpm_tis_status (chip); -if (status &TPM_STS_DATA_AVAIL ) {/* retry? */ -dev_err (&chip->dev,"Error left over data\n" ); +if (!data_valid) size = -EIO ; - goto out; - } - out:tpm_tis_ready (chip);return size;
@@ -453,14 +476,19 @@ static void disable_interrupts(struct tpm_chip *chip)static int tpm_tis_send_main (struct tpm_chip *chip,const u8 *buf,size_t len) {struct tpm_tis_data *priv =dev_get_drvdata (&chip->dev); -int rc; +int rc, i;u32 ordinal;unsigned long dur; +bool data_valid = false; - rc =tpm_tis_send_data (chip, buf, len); -if (rc <0 ) -return rc; - +for (i =0 ; i <TPM_RETRY && !data_valid; i++) { + rc =tpm_tis_send_data (chip, buf, len); +if (rc <0 ) +return rc; + data_valid =tpm_tis_verify_data_integrity (chip, buf, len); + } +if (!data_valid) +return -EIO ;/* 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 +3 -0
@@ -34,6 +34,7 @@ enum tis_status {TPM_STS_GO =0x20 ,TPM_STS_DATA_AVAIL =0x10 ,TPM_STS_DATA_EXPECT =0x08 , + TPM_STS_RESPONSE_RETRY = 0x02, }; enum tis_int_flags {
@@ -106,6 +107,8 @@ struct tpm_tis_phy_ops {int (*read16)(struct tpm_tis_data *data,u32 addr,u16 *result);int (*read32)(struct tpm_tis_data *data,u32 addr,u32 *result);int (*write32)(struct tpm_tis_data *data,u32 addr,u32 src); +bool (*verify_data_integrity)(struct tpm_tis_data *data,const u8 *buf, +size_t len); }; static inline int tpm_tis_read_bytes(struct tpm_tis_data *data, u32 addr,
Signature · 1 line
2.7.4
PATCH v8 3/8 tpm: tpm_tis: Rewrite "tpm_tis_req_canceled()"
In reply to [email protected]From: Amir Mizinski <[email protected]>
Using this function while reading/writing data resulted in an aborted operation.
After investigating the issue according to the TCG TPM Profile (PTP) Specifications, I found that "request to cancel" should occur only if TPM_STS.commandReady bit is lit.
Note that i couldn't find a case where the present condition (in the linux kernel) is valid, so I'm removing the case for "TPM_VID_WINBOND" since we have no need for it.
Also, the default comparison is wrong. Only cmdReady bit needs to be compared instead of the full lower status register byte.
--- drivers/char/tpm/tpm_tis_core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/char/tpm/tpm_tis_core.c +2 -4
@@ -715,13 +715,11 @@ static bool tpm_tis_req_canceled(struct tpm_chip *chip, u8 status)struct tpm_tis_data *priv =dev_get_drvdata (&chip->dev);switch (priv->manufacturer_id) { -case TPM_VID_WINBOND : -return ((status ==TPM_STS_VALID ) || - (status == (TPM_STS_VALID |TPM_STS_COMMAND_READY )));case TPM_VID_STM :return (status == (TPM_STS_VALID |TPM_STS_COMMAND_READY ));default : -return (status ==TPM_STS_COMMAND_READY ); +return ((status &TPM_STS_COMMAND_READY ) == +TPM_STS_COMMAND_READY ); } }
Signature · 1 line
2.7.4
PATCH v8 4/8 tpm: tpm_tis: Fix expected bit handling and send all bytes in one shot without last byte in exception
In reply to [email protected]From: Amir Mizinski <[email protected]>
Incorrect implementation of send message was detected. We polled only TPM_STS.stsValid bit and then we single-checked the TPM_STS.expect bit value.
TPM_STS.expected bit should be checked at the same time as TPM_STS.stsValid bit, and this should be repeated until timeout_A.
To detect a TPM_STS.expected bit reset, the "wait_for_tpm_stat" function is modified to "wait_for_tpm_stat_result". This function regularly reads the status register and check the bits defined by "mask" to reach the value defined in "mask_result".
This correct implementation is required for using the new CRC calculation on I2C TPM command bytes or I2C TPM answer bytes. TPM_STS.expected bit is reset after all bytes are acquired and the CRC result is inserted in the dedicated register. It introduces a normal latency for TPM_STS.expected bit reset.
Respectively, to send a message, as defined in TCG_DesignPrinciples_TPM2p0Driver_vp24_pubrev.pdf, all bytes should be sent in one shot instead of sending the last byte separately.
--- drivers/char/tpm/tpm_tis_core.c | 74 +++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 44 deletions(-)
drivers/char/tpm/tpm_tis_core.c +30 -44
@@ -44,9 +44,10 @@ static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,return false; } -static int wait_for_tpm_stat (struct tpm_chip *chip,u8 mask, -unsigned long timeout,wait_queue_head_t *queue, -bool check_cancel) +static int wait_for_tpm_stat_result (struct tpm_chip *chip,u8 mask, +u8 mask_result,unsigned long timeout, +wait_queue_head_t *queue, +bool check_cancel) {unsigned long stop;long rc;
@@ -55,7 +56,7 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,/* check current status */ status = chip->ops->status (chip); -if ((status & mask) == mask) +if ((status & mask) == mask_result)return 0 ; stop = jiffies + timeout;
@@ -83,7 +84,7 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,usleep_range (TPM_TIMEOUT_USECS_MIN ,TPM_TIMEOUT_USECS_MAX ); status = chip->ops->status (chip); -if ((status & mask) == mask) +if ((status & mask) == mask_result)return 0 ; }while (time_before (jiffies, stop)); }
@@ -292,10 +293,13 @@ static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)int size =0 , burstcnt, rc;while (size < count) { - rc =wait_for_tpm_stat (chip, -TPM_STS_DATA_AVAIL |TPM_STS_VALID , - chip->timeout_c, - &priv->read_queue, true); + rc =wait_for_tpm_stat_result (chip, +TPM_STS_DATA_AVAIL | +TPM_STS_VALID , +TPM_STS_DATA_AVAIL | +TPM_STS_VALID , + chip->timeout_c, + &priv->read_queue, true);if (rc <0 )return rc; burstcnt =get_burstcount (chip);
@@ -350,8 +354,9 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count) goto out; } -if (wait_for_tpm_stat (chip,TPM_STS_VALID , chip->timeout_c, - &priv->int_queue, false) <0 ) { +if (wait_for_tpm_stat_result (chip,TPM_STS_VALID , +TPM_STS_VALID , chip->timeout_c, + &priv->int_queue, false) <0 ) { size = -ETIME ; goto out; }
@@ -387,61 +392,40 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len)struct tpm_tis_data *priv =dev_get_drvdata (&chip->dev);int rc, status, burstcnt;size_t count =0 ; -bool itpm = priv->flags &TPM_TIS_ITPM_WORKAROUND ; status =tpm_tis_status (chip);if ((status &TPM_STS_COMMAND_READY ) ==0 ) {tpm_tis_ready (chip); -if (wait_for_tpm_stat - (chip,TPM_STS_COMMAND_READY , chip->timeout_b, - &priv->int_queue, false) <0 ) { +if (wait_for_tpm_stat_result (chip,TPM_STS_COMMAND_READY , +TPM_STS_COMMAND_READY , + chip->timeout_b, + &priv->int_queue, false) <0 ) { rc = -ETIME ; goto out_err; } } -while (count < len -1 ) { +while (count < len) { burstcnt =get_burstcount (chip);if (burstcnt <0 ) {dev_err (&chip->dev,"Unable to read burstcount\n" ); rc = burstcnt; goto out_err; } - burstcnt =min_t (int, burstcnt, len - count -1 ); + burstcnt =min_t (int, burstcnt, len - count); rc =tpm_tis_write_bytes (priv,TPM_DATA_FIFO (priv->locality), burstcnt, buf + count);if (rc <0 ) goto out_err; count += burstcnt; - -if (wait_for_tpm_stat (chip,TPM_STS_VALID , chip->timeout_c, - &priv->int_queue, false) <0 ) { - rc = -ETIME ; - goto out_err; - } - status =tpm_tis_status (chip); -if (!itpm && (status &TPM_STS_DATA_EXPECT ) ==0 ) { - rc = -EIO ; - goto out_err; - } } - -/* write last byte */ - rc =tpm_tis_write8 (priv,TPM_DATA_FIFO (priv->locality), buf[count]); -if (rc <0 ) - goto out_err; - -if (wait_for_tpm_stat (chip,TPM_STS_VALID , chip->timeout_c, - &priv->int_queue, false) <0 ) { +if (wait_for_tpm_stat_result (chip,TPM_STS_VALID |TPM_STS_DATA_EXPECT , +TPM_STS_VALID , chip->timeout_a, + &priv->int_queue, false) <0 ) { rc = -ETIME ; goto out_err; } - status =tpm_tis_status (chip); -if (!itpm && (status &TPM_STS_DATA_EXPECT ) !=0 ) { - rc = -EIO ; - goto out_err; - }return 0 ;
@@ -498,9 +482,11 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len) ordinal =be32_to_cpu (*((__be32 *) (buf +6 ))); dur =tpm_calc_ordinal_duration (chip, ordinal); -if (wait_for_tpm_stat - (chip,TPM_STS_DATA_AVAIL |TPM_STS_VALID , dur, - &priv->read_queue, false) <0 ) { +if (wait_for_tpm_stat_result (chip, +TPM_STS_DATA_AVAIL |TPM_STS_VALID , +TPM_STS_DATA_AVAIL |TPM_STS_VALID , + dur, + &priv->read_queue, false) <0 ) { rc = -ETIME ; goto out_err; }
Signature · 1 line
2.7.4
PATCH v8 5/8 tpm: Handle an exception for TPM Firmware Update mode.
In reply to [email protected]From: Amir Mizinski <[email protected]>
An extra precaution for TPM Firmware Update Mode.
For example if TPM power was cut while in Firmware update, platform should ignore "selftest" failure and skip TPM initialization sequence.
--- drivers/char/tpm/tpm2-cmd.c | 4 ++++ include/linux/tpm.h | 1 + 2 files changed, 5 insertions(+)
drivers/char/tpm/tpm2-cmd.c +4 -0
@@ -727,6 +727,10 @@ int tpm2_auto_startup(struct tpm_chip *chip) goto out; rc =tpm2_do_selftest (chip); + +if (rc ==TPM2_RC_UPGRADE || rc ==TPM2_RC_COMMAND_CODE ) +return 0 ; +if (rc && rc !=TPM2_RC_INITIALIZE ) goto out;
include/linux/tpm.h +1 -0
@@ -199,6 +199,7 @@ enum tpm2_return_codes {TPM2_RC_INITIALIZE =0x0100 ,/* RC_VER1 */ TPM2_RC_FAILURE =0x0101 ,TPM2_RC_DISABLED =0x0120 , +TPM2_RC_UPGRADE =0x012D ,TPM2_RC_COMMAND_CODE =0x0143 ,TPM2_RC_TESTING =0x090A ,/* RC_WARN */ TPM2_RC_REFERENCE_H0 = 0x0910,
Signature · 1 line
2.7.4
PATCH v8 6/8 verify TPM_STS register is valid after locality request
In reply to [email protected]From: Amir Mizinski <[email protected]>
Issue could result when the TPM does not update TPM_STS register after a locality request (TPM_STS Initial value = 0xFF) and a TPM_STS register read occurs (tpm_tis_status(chip)).
Checking the next condition("if ((status & TPM_STS_COMMAND_READY) == 0)"), the status will be at 0xFF and will be considered, wrongly, in "Ready" state (by checking only one bit). However, at this moment the TPM is, in fact, in "Idle" state and remains in "Idle" state because "tpm_tis_ready(chip);" was not executed.
--- drivers/char/tpm/tpm_tis_core.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_tis_core.c +7 -1
@@ -222,8 +222,14 @@ static int request_locality(struct tpm_chip *chip, int l) }else {/* wait for burstcount */ do { -if (check_locality (chip, l)) +if (check_locality (chip, l)) { +if (wait_for_tpm_stat_result (chip,TPM_STS_GO , +0 , chip->timeout_c, + &priv->int_queue, + false) <0 ) +return -ETIME ;return l; + }tpm_msleep (TPM_TIMEOUT ); }while (time_before (jiffies, stop)); }
Signature · 1 line
2.7.4
PATCH v8 7/8 tpm: Add YAML schema for TPM TIS I2C options
In reply to [email protected]From: Amir Mizinski <[email protected]>
Added a YAML schema to support tpm tis i2c related dt-bindings for the I2c PTP based physical layer.
This patch adds the documentation for corresponding device tree bindings of I2C based Physical TPM.
Refer to the 'I2C Interface Definition' section in
'TCG PC Client PlatformTPMProfile(PTP) Specification' publication for specification.
--- .../bindings/security/tpm/tpm-tis-i2c.yaml | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/security/tpm/tpm-tis-i2c.yaml
Documentation/devicetree/bindings/security/tpm/tpm-tis-i2c.yaml new file +51 -0
@@ -0,0 +1,51 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/security/tpm/tpm-tis-i2c.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: I2C PTP based TPM Device Tree Bindings + +maintainers: + - Amir Mizinski <[email protected]> + +description: + Device Tree Bindings for I2C based Trusted Platform Module(TPM). + +properties: + compatible: + oneOf: + - items: + - enum: + # Nuvoton's Trusted Platform Module (TPM) (NPCT75x) + - nuvoton,npct75x + - const: tcg,tpm-tis-i2c + + reg: + maxItems: 1 + + interrupt: + maxItems: 1 + + crc-checksum: + $ref: /schemas/types.yaml#/definitions/flag + description: + Set this flag to enable CRC checksum. + +required: + - compatible + - reg + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + tpm_tis@2e { + compatible = "nuvoton,npct75x", "tcg,tpm-tis-i2c"; + reg = <0x2e>; + crc-checksum; + }; + }; +...
Signature · 1 line
2.7.4
Rob Herring
maintainerRe: [PATCH v8 7/8] tpm: Add YAML schema for TPM TIS I2C options
Quoted 23 lines · On Tue, May 12, 2020 at 05:14:30PM +0300, [email protected] wrote:
From: Amir Mizinski <[email protected]>
Added a YAML schema to support tpm tis i2c related dt-bindings for the I2c PTP based physical layer.
This patch adds the documentation for corresponding device tree bindings of I2C based Physical TPM.
Refer to the 'I2C Interface Definition' section in
'TCG PC Client PlatformTPMProfile(PTP) Specification' publication for specification.Signed-off-by Amir Mizinski <[email protected]>--- .../bindings/security/tpm/tpm-tis-i2c.yaml | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/security/tpm/tpm-tis-i2c.yamlDocumentation/devicetree/bindings/security/tpm/tpm-tis-i2c.yaml new file +0
-0
Documentation/devicetree/bindings/security/tpm/tpm-tis-i2c.yaml line 1
Quoted 1 line
Documentation/devicetree/bindings/security/tpm/tpm-tis-i2c.yaml new file +1
-0@@ -0,0 +1,51 @@ +# SPDX-License-Identifier: GPL-2.0
Dual license new bindings please:
(GPL-2.0-only OR BSD-2-Clause)
Quoted 7 lines
Documentation/devicetree/bindings/security/tpm/tpm-tis-i2c.yaml new file +7
-0+%YAML 1.2 +--- +$id: http://devicetree.org/schemas/security/tpm/tpm-tis-i2c.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: I2C PTP based TPM Device Tree Bindings +
Documentation/devicetree/bindings/security/tpm/tpm-tis-i2c.yaml line 18
Quoted 10 lines
Documentation/devicetree/bindings/security/tpm/tpm-tis-i2c.yaml new file +10
-0+maintainers: + - Amir Mizinski <[email protected]> + +description: + Device Tree Bindings for I2C based Trusted Platform Module(TPM). + +properties: + compatible: + oneOf: + - items:
You don't need 'oneOf'.
Quoted 17 lines
Documentation/devicetree/bindings/security/tpm/tpm-tis-i2c.yaml new file +17
-0+ - enum: + # Nuvoton's Trusted Platform Module (TPM) (NPCT75x) + - nuvoton,npct75x + - const: tcg,tpm-tis-i2c + + reg: + maxItems: 1 + + interrupt: + maxItems: 1 + + crc-checksum: + $ref: /schemas/types.yaml#/definitions/flag + description: + Set this flag to enable CRC checksum. + +required:
Documentation/devicetree/bindings/security/tpm/tpm-tis-i2c.yaml line 45
Quoted 10 lines
Documentation/devicetree/bindings/security/tpm/tpm-tis-i2c.yaml new file +10
-0+ - compatible + - reg + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + tpm_tis@2e {
tpm@2e
Quoted 9 lines
Documentation/devicetree/bindings/security/tpm/tpm-tis-i2c.yaml new file +6
-0+ compatible = "nuvoton,npct75x", "tcg,tpm-tis-i2c"; + reg = <0x2e>; + crc-checksum; + }; + }; +...Signature · 1 line
2.7.4
PATCH v8 8/8 tpm: tpm_tis: add tpm_tis_i2c driver
In reply to [email protected]From: Amir Mizinski <[email protected]>
Implements the functionality needed to communicate with an I2C TPM according to the TCG TPM I2C Interface Specification.
--- drivers/char/tpm/Kconfig | 12 ++ drivers/char/tpm/Makefile | 1 + drivers/char/tpm/tpm_tis_i2c.c | 292 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 305 insertions(+) create mode 100644 drivers/char/tpm/tpm_tis_i2c.c
drivers/char/tpm/Kconfig +12 -0
@@ -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 I2C Interface Specification" + depends on I2C + select CRC_CCITT + select TCG_TIS_CORE + help + If you have a TPM security chip which is connected to a regular + I2C master (i.e. most embedded platforms) that is compliant with the + TCG TPM I2C Interface Specification 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_ATMEL tristate "TPM Interface Specification 1.2 Interface (I2C - Atmel)" depends on I2C
drivers/char/tpm/Makefile +1 -0
@@ -26,6 +26,7 @@ obj-$(CONFIG_TCG_TIS_SPI) += tpm_tis_spi.o tpm_tis_spi-y := tpm_tis_spi_main.o tpm_tis_spi-$(CONFIG_TCG_TIS_SPI_CR50) += tpm_tis_spi_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 +292 -0
292 lines not on this page · raw message
Signature · 1 line
2.7.4