diff mbox series

p8-i2c: Limit number of retry attempts

Message ID 20171117060411.18124-1-oohall@gmail.com
State Accepted
Headers show
Series p8-i2c: Limit number of retry attempts | expand

Commit Message

Oliver O'Halloran Nov. 17, 2017, 6:04 a.m. UTC
Current we will attempt to start an I2C transaction until it succeeds.
In the event that the OCC does not release the lock on an I2C bus this
results in an async token being held forever and the kernel thread that
started the transaction will block forever while waiting for an async
completion message. Fix this by limiting the number of attempts to
start the transaction.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 hw/p8-i2c.c   | 12 ++++++++++--
 include/i2c.h |  1 +
 2 files changed, 11 insertions(+), 2 deletions(-)

Comments

Stewart Smith Nov. 21, 2017, 8:36 p.m. UTC | #1
Oliver O'Halloran <oohall@gmail.com> writes:
> Current we will attempt to start an I2C transaction until it succeeds.
> In the event that the OCC does not release the lock on an I2C bus this
> results in an async token being held forever and the kernel thread that
> started the transaction will block forever while waiting for an async
> completion message. Fix this by limiting the number of attempts to
> start the transaction.
>
> Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
> ---
>  hw/p8-i2c.c   | 12 ++++++++++--
>  include/i2c.h |  1 +
>  2 files changed, 11 insertions(+), 2 deletions(-)

Thanks, merged to master as of c2e404aedd52da91fdf605e24b9d1ae7894974c5.
diff mbox series

Patch

diff --git a/hw/p8-i2c.c b/hw/p8-i2c.c
index ec2f7fc0b47c..d029854d5c54 100644
--- a/hw/p8-i2c.c
+++ b/hw/p8-i2c.c
@@ -1303,8 +1303,16 @@  static void p8_i2c_check_work(struct p8_i2c_master *master)
 	while (master->state == state_idle && !list_empty(&master->req_list)) {
 		req = list_top(&master->req_list, struct i2c_request, link);
 		rc = p8_i2c_start_request(master, req);
-		if (rc && rc != OPAL_BUSY)
-			p8_i2c_complete_request(master, req, rc);
+		if (rc) {
+			/*
+			 * If it didn't work the first three times then
+			 * odds are it's not going to work on the 4th.
+			 */
+			if (rc && req->retries > 3)
+				p8_i2c_complete_request(master, req, rc);
+			else
+				req->retries++;
+		}
 	}
 }
 
diff --git a/include/i2c.h b/include/i2c.h
index 669c30a2fcfb..28c762891b70 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -64,6 +64,7 @@  struct i2c_request {
 	void			(*completion)(	/* Completion callback */
 					      int rc, struct i2c_request *req);
 	void			*user_data;	/* Client data */
+	int			retries;
 };
 
 /* Generic i2c */