[Skiboot] [PATCH 4/4] tpm_i2c_interface: decouple rc from being done with i2c request

Stewart Smith stewart at linux.vnet.ibm.com
Wed Nov 23 16:46:02 AEDT 2016


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 at linux.vnet.ibm.com>
---
 libstb/drivers/tpm_i2c_interface.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/libstb/drivers/tpm_i2c_interface.c b/libstb/drivers/tpm_i2c_interface.c
index 89f5ba6..133d3a0 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,7 @@ 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;
+	req->user_data = &ud;
 
 	/*
 	 * Set the request timeout to 10ms per byte. Otherwise, we get
@@ -101,7 +109,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 +119,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;
-- 
2.7.4



More information about the Skiboot mailing list