diff mbox series

p8-i2c: Don't write the watermark register at init

Message ID 20171110025036.27832-1-oohall@gmail.com
State Accepted
Headers show
Series p8-i2c: Don't write the watermark register at init | expand

Commit Message

Oliver O'Halloran Nov. 10, 2017, 2:50 a.m. UTC
On P9 the I2C master is shared with the OCC. Currently the watermark
values are set once at init time which is bad for two reasons:

a) We don't take the OCC master lock before setting it. Which
   may cause issues if the OCC is currently using the master.
b) The OCC might change the watermark levels and we need to reset
   them.

Change this so that we set the watermark value when a new transaction
is started rather than at init time.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 hw/p8-i2c.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

Comments

Stewart Smith Nov. 14, 2017, 6:47 a.m. UTC | #1
Oliver O'Halloran <oohall@gmail.com> writes:
> On P9 the I2C master is shared with the OCC. Currently the watermark
> values are set once at init time which is bad for two reasons:
>
> a) We don't take the OCC master lock before setting it. Which
>    may cause issues if the OCC is currently using the master.
> b) The OCC might change the watermark levels and we need to reset
>    them.
>
> Change this so that we set the watermark value when a new transaction
> is started rather than at init time.
>
> Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
> ---
>  hw/p8-i2c.c | 20 ++++++++------------
>  1 file changed, 8 insertions(+), 12 deletions(-)

Thanks.

Merged to master as of d0f06269ed3cd3e09a9b04c5f70cb3d53a77a689

and seeing as we have possibly seen this be a problem, merged to 5.9.x
as of 0cc1fe4e23308fc4f4002c74b475475e96fedcb9.

Obviously, we should do some good testing.
diff mbox series

Patch

diff --git a/hw/p8-i2c.c b/hw/p8-i2c.c
index ce56b268154a..ec2f7fc0b47c 100644
--- a/hw/p8-i2c.c
+++ b/hw/p8-i2c.c
@@ -1223,6 +1223,14 @@  static int p8_i2c_start_request(struct p8_i2c_master *master,
 	if (rc)
 		return rc;
 
+	/* program the watermark register */
+	rc = p8_i2c_prog_watermark(master);
+	if (rc) {
+		log_simple_error(&e_info(OPAL_RC_I2C_INIT),
+			 "I2C: Failed to program the WATERMARK_REG\n");
+		return rc;
+	}
+
 	/* Initialize bytes_sent */
 	master->bytes_sent = 0;
 
@@ -1680,22 +1688,10 @@  static void p8_i2c_init_one(struct dt_node *i2cm, enum p8_i2c_master_type type)
 		      master->irq_ok ? "" : "non-");
 	}
 
-	/* Program the watermark register */
-	rc = p8_i2c_prog_watermark(master);
-
 	/* Re-enable the sensor cache, we aren't touching HW anymore */
 	if (master->type == I2C_CENTAUR)
 		centaur_enable_sensor_cache(master->chip_id);
 
-	/* Handle errors from p8_i2c_prog_watermark */
-	if (rc) {
-		log_simple_error(&e_info(OPAL_RC_I2C_INIT),
-				 "I2C: Failed to program the "
-				 "WATERMARK_REG\n");
-		free(master);
-		return;
-	}
-
 	/* Allocate ports driven by this master */
 	count = 0;
 	dt_for_each_child(i2cm, i2cm_port)