Skip to contentSkip to conversation

tpm: tpm_i2c_nuvoton: use correct command duration for TPM 2.x

PATCH In review Tomas Winkler 3 participants 4 messages Oct 17, 2018 – Oct 19, 2018

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

PATCH 1/1 tpm: tpm_i2c_nuvoton: use correct command duration for TPM 2.x

tpm_i2c_nuvoton calculated commands duration using TPM 1.x values via tpm_calc_ordinal_duration() also for TPM 2.x chips. Call tpm2_calc_ordinal_duration() for retrieving ordinal duration for TPM 2.X chips.

---
 drivers/char/tpm/tpm_i2c_nuvoton.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/char/tpm/tpm_i2c_nuvoton.c +7 -4
index caa86b19c76d..f74f451baf6a 100644
@@ -369,6 +369,7 @@ static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len)
 	struct device *dev = chip->dev.parent;
 	struct i2c_client *client = to_i2c_client(dev);
 	u32 ordinal;
+	unsigned long duration;
 	size_t count = 0;
 	int burst_count, bytes2write, retries, rc = -EIO;
 
@@ -455,10 +456,12 @@ static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len)
 		return rc;
 	}
 	ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
-	rc = i2c_nuvoton_wait_for_data_avail(chip,
-					     tpm_calc_ordinal_duration(chip,
-								       ordinal),
-					     &priv->read_queue);
+	if (chip->flags & TPM_CHIP_FLAG_TPM2)
+		duration = tpm2_calc_ordinal_duration(chip, ordinal);
+	else
+		duration = tpm_calc_ordinal_duration(chip, ordinal);
+
+	rc = i2c_nuvoton_wait_for_data_avail(chip, duration, &priv->read_queue);
 	if (rc) {
 		dev_err(dev, "%s() timeout command duration\n", __func__);
 		i2c_nuvoton_ready(chip);
Signature · 1 line
2.14.4
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 19 lines · Tomas Winkler
drivers/char/tpm/tpm_i2c_nuvoton.c +1 -3
index caa86b19c76d..f74f451baf6a 100644
@@ -369,6 +369,7 @@ static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len)
  	struct device *dev = chip->dev.parent;
  	struct i2c_client *client = to_i2c_client(dev);
  	u32 ordinal;
+	unsigned long duration;
  	size_t count = 0;
  	int burst_count, bytes2write, retries, rc = -EIO;
 
@@ -455,10 +456,12 @@ static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len)
  		return rc;
  	}
  	ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
-	rc = i2c_nuvoton_wait_for_data_avail(chip,
-					     tpm_calc_ordinal_duration(chip,
-								       ordinal),

drivers/char/tpm/tpm_i2c_nuvoton.c static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 467

Quoted 10 lines
drivers/char/tpm/tpm_i2c_nuvoton.c +6 -1
-					     &priv->read_queue);
+	if (chip->flags & TPM_CHIP_FLAG_TPM2)
+		duration = tpm2_calc_ordinal_duration(chip, ordinal);
+	else
+		duration = tpm_calc_ordinal_duration(chip, ordinal);
+
+	rc = i2c_nuvoton_wait_for_data_avail(chip, duration, &priv->read_queue);
  	if (rc) {
  		dev_err(dev, "%s() timeout command duration\n", __func__);
  		i2c_nuvoton_ready(chip);

I only have Nuvoton TPM 2.0, tested for that.

Thanks & Regards,
    - Nayna

#2 lore raw
Quoted 34 lines · Nayna Jain
Quoted 19 lines · Tomas Winkler
drivers/char/tpm/tpm_i2c_nuvoton.c +1 -3
index caa86b19c76d..f74f451baf6a 100644
@@ -369,6 +369,7 @@ static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len)
  	struct device *dev = chip->dev.parent;
  	struct i2c_client *client = to_i2c_client(dev);
  	u32 ordinal;
+	unsigned long duration;
  	size_t count = 0;
  	int burst_count, bytes2write, retries, rc = -EIO;
 
@@ -455,10 +456,12 @@ static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len)
  		return rc;
  	}
  	ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
-	rc = i2c_nuvoton_wait_for_data_avail(chip,
-					     tpm_calc_ordinal_duration(chip,
-								       ordinal),

drivers/char/tpm/tpm_i2c_nuvoton.c static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 467

Quoted 10 lines
drivers/char/tpm/tpm_i2c_nuvoton.c +6 -1
-					     &priv->read_queue);
+	if (chip->flags & TPM_CHIP_FLAG_TPM2)
+		duration = tpm2_calc_ordinal_duration(chip, ordinal);
+	else
+		duration = tpm_calc_ordinal_duration(chip, ordinal);
+
+	rc = i2c_nuvoton_wait_for_data_avail(chip, duration, &priv->read_queue);
  	if (rc) {
  		dev_err(dev, "%s() timeout command duration\n", __func__);
  		i2c_nuvoton_ready(chip);

I only have Nuvoton TPM 2.0, tested for that.

Quoted 2 lines

That's what we needed as TPM 1.2 should be unchanged.
Really appreciate the quick response. I will rebase the series on to of this patch.

Thanks
Tomas