diff options
author | Stewart Smith <stewart@linux.vnet.ibm.com> | 2016-11-23 17:30:08 +1100 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2016-11-24 16:47:16 +1100 |
commit | 9c471e0e6eafca3b0f249b649e5cf8ac752bffd1 (patch) | |
tree | 299d001f5e7fccb2677e102b559e299307125db3 /libstb | |
parent | dab67b5d19b0e004249d5a850e283823a0e60d40 (diff) | |
download | skiboot-9c471e0e6eafca3b0f249b649e5cf8ac752bffd1.zip skiboot-9c471e0e6eafca3b0f249b649e5cf8ac752bffd1.tar.gz skiboot-9c471e0e6eafca3b0f249b649e5cf8ac752bffd1.tar.bz2 |
tpm_i2c_interface: decouple rc from being done with i2c request
This ensures the i2c subsystem is done with the i2c request before
we continue. Since it handles timeouts, we don't have to here.
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Tested-by: Claudio Carvalho <cclaudio@linux.vnet.ibm.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'libstb')
-rw-r--r-- | libstb/drivers/tpm_i2c_interface.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/libstb/drivers/tpm_i2c_interface.c b/libstb/drivers/tpm_i2c_interface.c index 89f5ba6..cc7bf1a 100644 --- a/libstb/drivers/tpm_i2c_interface.c +++ b/libstb/drivers/tpm_i2c_interface.c @@ -30,9 +30,16 @@ #define REQ_COMPLETE_POLLING 5 /* Check if req is complete in 5ms interval */ +struct tpm_i2c_userdata { + int rc; + bool done; +}; + void tpm_i2c_request_complete(int rc, struct i2c_request *req) { - *(int*)req->user_data = rc; + struct tpm_i2c_userdata *ud = req->user_data; + ud->rc = rc; + ud->done = true; } /** @@ -58,6 +65,7 @@ int tpm_i2c_request_send(int tpm_bus_id, int tpm_dev_addr, int read_write, struct i2c_request *req; struct i2c_bus *bus; uint64_t time_to_wait = 0; + struct tpm_i2c_userdata ud; bus = i2c_find_bus_by_id(tpm_bus_id); if (!bus) { @@ -91,7 +99,8 @@ int tpm_i2c_request_send(int tpm_bus_id, int tpm_dev_addr, int read_write, req->rw_buf = (void*) buf; req->rw_len = buflen; req->completion = tpm_i2c_request_complete; - req->user_data = &rc; + ud.done = false; + req->user_data = &ud; /* * Set the request timeout to 10ms per byte. Otherwise, we get @@ -101,7 +110,6 @@ int tpm_i2c_request_send(int tpm_bus_id, int tpm_dev_addr, int read_write, timeout = (buflen + offset_bytes + 2) * I2C_BYTE_TIMEOUT_MS; for (retries = 0; retries <= TPM_MAX_NACK_RETRIES; retries++) { - rc = 1; waited = 0; i2c_set_req_timeout(req, timeout); i2c_queue_req(req); @@ -112,7 +120,9 @@ int tpm_i2c_request_send(int tpm_bus_id, int tpm_dev_addr, int read_write, time_to_wait = REQ_COMPLETE_POLLING; time_wait(time_to_wait); waited += time_to_wait; - } while (tb_to_msecs(waited) < timeout && rc == 1); + } while (!ud.done); + + rc = ud.rc; if (rc == OPAL_I2C_NACK_RCVD) continue; |