From: Peter Huewe <peter.huewe@infineon.com>
To: <srajiv@linux.vnet.ibm.com>
Cc: <tpmdd@selhorst.net>, <tpmdd-devel@lists.sourceforge.net>,
<linux-kernel@vger.kernel.org>, Olof Johansson <olof@lixom.net>,
Luigi Semenzato <semenzato@google.com>, <andi.shyti@gmail.com>,
Bryan Freed <bfreed@chromium.org>,
Peter Huewe <peter.huewe@infineon.com>
Subject: [PATCH 2/2] CHROMIUM: tpm: tpm_i2c_infineon: Lock the I2C adapter for a sequence of requests.
Date: Tue, 12 Jun 2012 14:43:54 +0200 [thread overview]
Message-ID: <1339505034-6400-2-git-send-email-peter.huewe@infineon.com> (raw)
In-Reply-To: <1339505034-6400-1-git-send-email-peter.huewe@infineon.com>
From: Bryan Freed <bfreed@chromium.org>
This is derived from Peter Huewe's recommended fix:
On some ChromeOS systems, a TPM sharing the I2C bus with another device
gets confused when it sees I2C requests to that other device.
This change locks the I2C adapter for the duration of the full sequence
of I2C requests the TPM needs to complete.
smbus_xfer is not supported, but SMBUS is not supported by the original
driver, either.
Signed-off-by: Bryan Freed <bfreed@chromium.org>
Signed-off-by: Peter Huewe <peter.huewe@infineon.com>
---
drivers/char/tpm/tpm_i2c_infineon.c | 45 +++++++++++++++++++++++++++++++---
1 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/drivers/char/tpm/tpm_i2c_infineon.c b/drivers/char/tpm/tpm_i2c_infineon.c
index 54b9a5e..1794a09 100644
--- a/drivers/char/tpm/tpm_i2c_infineon.c
+++ b/drivers/char/tpm/tpm_i2c_infineon.c
@@ -68,6 +68,31 @@ struct tpm_inf_dev {
static struct tpm_inf_dev tpm_dev;
static struct i2c_driver tpm_tis_i2c_driver;
+
+/*
+ * Copy i2c-core:i2c_transfer() as close as possible without the adapter locks
+ * and algorithm check. These are done by the caller for atomicity.
+ * Unfortunately we have to use this as a workaround in multislave environments
+ * as no other suitable and working mechanism is available.
+ */
+static int i2c_transfer_nolock(struct i2c_adapter *adap, struct i2c_msg *msgs,
+ int num)
+{
+ unsigned long orig_jiffies;
+ int ret, try;
+
+ /* Retry automatically on arbitration loss */
+ orig_jiffies = jiffies;
+ for (ret = 0, try = 0; try <= adap->retries; try++) {
+ ret = adap->algo->master_xfer(adap, msgs, num);
+ if (ret != -EAGAIN)
+ break;
+ if (time_after(jiffies, orig_jiffies + adap->timeout))
+ break;
+ }
+ return ret;
+}
+
/*
* iic_tpm_read() - read from TPM register
* @addr: register address to read from
@@ -96,8 +121,13 @@ static int iic_tpm_read(u8 addr, u8 *buffer, size_t len)
int rc;
int count;
+ /* Lock the adapter for the duration of the whole sequence. */
+ if (!tpm_dev.client->adapter->algo->master_xfer)
+ return -EOPNOTSUPP;
+ i2c_lock_adapter(tpm_dev.client->adapter);
+
for (count = 0; count < MAX_COUNT; count++) {
- rc = i2c_transfer(tpm_dev.client->adapter, &msg1, 1);
+ rc = i2c_transfer_nolock(tpm_dev.client->adapter, &msg1, 1);
if (rc > 0)
break; /* break here to skip sleep */
@@ -105,19 +135,21 @@ static int iic_tpm_read(u8 addr, u8 *buffer, size_t len)
}
if (rc <= 0)
- return -EIO;
+ goto out;
/* After the TPM has successfully received the register address it needs
* some time, thus we're sleeping here again, before retrieving the data
*/
for (count = 0; count < MAX_COUNT; count++) {
usleep_range(SLEEP_DURATION_LOW, SLEEP_DURATION_HI);
- rc = i2c_transfer(tpm_dev.client->adapter, &msg2, 1);
+ rc = i2c_transfer_nolock(tpm_dev.client->adapter, &msg2, 1);
if (rc > 0)
break;
}
+out:
+ i2c_unlock_adapter(tpm_dev.client->adapter);
if (rc <= 0)
return -EIO;
@@ -136,6 +168,10 @@ static int iic_tpm_write_generic(u8 addr, u8 *buffer, size_t len,
if (len > TPM_BUFSIZE)
return -EINVAL;
+ if (!tpm_dev.client->adapter->algo->master_xfer)
+ return -EOPNOTSUPP;
+ i2c_lock_adapter(tpm_dev.client->adapter);
+
/* prepend the 'register address' to the buffer */
tpm_dev.buf[0] = addr;
memcpy(&(tpm_dev.buf[1]), buffer, len);
@@ -145,13 +181,14 @@ static int iic_tpm_write_generic(u8 addr, u8 *buffer, size_t len,
* cannot rely on the standard behavior of i2c_transfer.
*/
for (count = 0; count < max_count; count++) {
- rc = i2c_transfer(tpm_dev.client->adapter, &msg1, 1);
+ rc = i2c_transfer_nolock(tpm_dev.client->adapter, &msg1, 1);
if (rc > 0)
break;
usleep_range(sleep_low, sleep_hi);
}
+ i2c_unlock_adapter(tpm_dev.client->adapter);
if (rc <= 0)
return -EIO;
--
1.7.6.msysgit.0
next prev parent reply other threads:[~2012-06-12 12:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-12 12:43 [PATCH 1/2] char/tpm: Add new driver for Infineon I2C TIS TPM Peter Huewe
2012-06-12 12:43 ` Peter Huewe [this message]
2012-06-13 7:38 ` [PATCH 2/2] CHROMIUM: tpm: tpm_i2c_infineon: Lock the I2C adapter for a sequence of requests Marcel Selhorst
2012-07-11 15:19 ` Kent Yoder
2012-06-13 7:37 ` [PATCH 1/2] char/tpm: Add new driver for Infineon I2C TIS TPM Marcel Selhorst
2012-06-13 8:02 ` Olof Johansson
2012-06-13 13:19 ` Rajiv Andrade
2012-06-13 17:04 ` Marcel Selhorst
2012-07-10 15:14 ` Kent Yoder
2012-06-13 8:35 ` Andi
2012-07-11 15:16 ` Kent Yoder
2012-07-11 15:21 ` [tpmdd-devel] " Peter.Huewe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1339505034-6400-2-git-send-email-peter.huewe@infineon.com \
--to=peter.huewe@infineon.com \
--cc=andi.shyti@gmail.com \
--cc=bfreed@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=olof@lixom.net \
--cc=semenzato@google.com \
--cc=srajiv@linux.vnet.ibm.com \
--cc=tpmdd-devel@lists.sourceforge.net \
--cc=tpmdd@selhorst.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®