[Skiboot] [PATCH v7 03/17] hw/p8-i2c: Allow to set timeout

Gavin Shan gwshan at linux.vnet.ibm.com
Thu Jun 4 16:18:55 AEST 2015


When changing power supply status to PCI slot during bootup, which
is done through I2C requests, the interrupt stuff isn't working yet
and we have to invoke polling timers proactively at fixed interval.
Unfortunately, the I2C master's timeout is usually very short and
we will encounter master timeout on the first poll at system bootup
time. The patch allows users to set override the default short
timeout binding with the specified I2C request, to avoid above
problem.

Signed-off-by: Gavin Shan <gwshan at linux.vnet.ibm.com>
---
 hw/p8-i2c.c   | 25 +++++++++++++++++++++++--
 include/i2c.h |  9 +++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/hw/p8-i2c.c b/hw/p8-i2c.c
index 7b6e87c..1dbcfc4 100644
--- a/hw/p8-i2c.c
+++ b/hw/p8-i2c.c
@@ -369,10 +369,15 @@ static int p8_i2c_prog_mode(struct p8_i2c_master_port *port, bool enhanced_mode)
 static void p8_i2c_complete_request(struct p8_i2c_master *master,
 				    struct i2c_request *req, int ret)
 {
+	struct p8_i2c_request *request =
+		container_of(req, struct p8_i2c_request, req);
+
 	/* We only complete the current top level request */
 	assert(req == list_top(&master->req_list, struct i2c_request, link));
 
 	cancel_timer_async(&master->timeout);
+	request->timeout = 0x0ul;
+
 	list_del(&req->link);
 	master->state = state_idle;
 	unlock(&master->lock);
@@ -922,8 +927,12 @@ static int p8_i2c_start_request(struct p8_i2c_master *master,
 	now = schedule_timer(&master->poller, master->poll_interval);
 
 	/* Calculate and start timeout */
-	tbytes = req->rw_len + req->offset_bytes + 2;
-	request->timeout = now + tbytes * master->byte_timeout;
+	if (request->timeout) {
+		request->timeout += now;
+	} else {
+		tbytes = req->rw_len + req->offset_bytes + 2;
+		request->timeout = now + tbytes * master->byte_timeout;
+	}
 
 	/* Start the timeout */
 	schedule_timer_at(&master->timeout, request->timeout);
@@ -995,6 +1004,15 @@ static void p8_i2c_free_request(struct i2c_request *req)
 	free(request);
 }
 
+static void p8_i2c_set_request_timeout(struct i2c_request *req,
+				       uint64_t duration)
+{
+	struct p8_i2c_request *request =
+		container_of(req, struct p8_i2c_request, req);
+
+	request->timeout = msecs_to_tb(duration);
+}
+
 static inline uint32_t p8_i2c_get_bit_rate_divisor(uint32_t lb_freq,
 						   uint32_t bus_speed)
 {
@@ -1039,6 +1057,8 @@ static void p8_i2c_timeout(struct timer *t __unused, void *data)
 		DBG("I2C: Timeout with request not expired\n");
 		goto exit;
 	}
+
+	request->timeout = 0ul;
 	port = container_of(req->bus, struct p8_i2c_master_port, bus);
 
 	/* Allright, we have a request and it has timed out ... */
@@ -1261,6 +1281,7 @@ static void p8_i2c_init_one(struct dt_node *i2cm, enum p8_i2c_master_type type)
 		port->bus.queue_req = p8_i2c_queue_request;
 		port->bus.alloc_req = p8_i2c_alloc_request;
 		port->bus.free_req = p8_i2c_free_request;
+		port->bus.set_req_timeout = p8_i2c_set_request_timeout;
 		i2c_add_bus(&port->bus);
 
 		/* Add OPAL properties to the bus node */
diff --git a/include/i2c.h b/include/i2c.h
index dea0644..83c6ec5 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -26,6 +26,8 @@ struct i2c_bus {
 	int			(*queue_req)(struct i2c_request *req);
 	struct i2c_request	*(*alloc_req)(struct i2c_bus *bus);
 	void			(*free_req)(struct i2c_request *req);
+	void			(*set_req_timeout)(struct i2c_request *req,
+						   uint64_t duration);
 };
 
 /*
@@ -80,6 +82,13 @@ static inline int i2c_queue_req(struct i2c_request *req)
 	return req->bus->queue_req(req);
 }
 
+static inline void i2c_set_req_timeout(struct i2c_request *req,
+				       uint64_t duration)
+{
+	if (req->bus->set_req_timeout)
+		req->bus->set_req_timeout(req, duration);
+}
+
 /* P8 implementation details */
 extern void p8_i2c_init(void);
 extern void p8_i2c_interrupt(uint32_t chip_id);
-- 
2.1.0



More information about the Skiboot mailing list