Skip to contentSkip to conversation

hw/i2c: Reset fixes

PATCH In review Joe Komlodi 3 participants 5 messages Mar 20, 2023 – Mar 21, 2023

lore
Share & tools
lore
#0 lore raw

cover hw/i2c: Reset fixes

Hi all,

This series fixes some I2C state variables not being reset when a reset would happen.

These stale variables would infrequently cause issues, something around the order of 5/1000 runs, since the machine would have to be reset at a point where they would be in a state that would cause problems.

Thanks!
Joe

Joe Komlodi (2):
hw/i2c: smbus_slave: Reset state on reset
hw/i2c: core: Add reset

 hw/i2c/core.c        | 25 ++++++++++++++++++++++---
 hw/i2c/smbus_slave.c |  9 +++++++++
 2 files changed, 31 insertions(+), 3 deletions(-)
Signature · 1 line
2.40.0.rc2.332.ga46443480c-goog
#1 lore raw

PATCH 1/2 hw/i2c: smbus_slave: Reset state on reset

If a reset comes while the SMBus device is not in its idle state, it's possible for it to get confused on valid transactions post-reset.

---
 hw/i2c/smbus_slave.c | 9 +++++++++
 1 file changed, 9 insertions(+)
hw/i2c/smbus_slave.c +9 -0
index feb3ec6333..7b9d8780ae 100644
@@ -197,10 +197,19 @@ static int smbus_i2c_send(I2CSlave *s, uint8_t data)
     return 0;
 }
 
+static void smbus_device_enter_reset(Object *obj, ResetType type)
+{
+    SMBusDevice *dev = SMBUS_DEVICE(obj);
+    dev->mode = SMBUS_IDLE;
+    dev->data_len = 0;
+}
+
 static void smbus_device_class_init(ObjectClass *klass, void *data)
 {
     I2CSlaveClass *sc = I2C_SLAVE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
+    rc->phases.enter = smbus_device_enter_reset;
     sc->event = smbus_i2c_event;
     sc->recv = smbus_i2c_recv;
     sc->send = smbus_i2c_send;
Signature · 1 line
2.40.0.rc2.332.ga46443480c-goog
#3 lore raw

PATCH 2/2 hw/i2c: core: Add reset

In reply to Joe Komlodi

It's possible for a reset to come in the middle of a transaction, which causes the bus to be in an old state when a new transaction comes in.

---
 hw/i2c/core.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
hw/i2c/core.c +22 -3
index bed594fe59..2aecbfb334 100644
@@ -23,10 +23,29 @@ static Property i2c_props[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
+static void i2c_bus_enter_reset(Object *obj, ResetType type)
+{
+    I2CBus *bus = I2C_BUS(obj);
+    I2CNode *node, *next;
+
+    bus->broadcast = false;
+    QLIST_FOREACH_SAFE(node, &bus->current_devs, next, next) {
+        QLIST_REMOVE(node, next);
+        g_free(node);
+    }
+}
+
+static void i2c_bus_class_init(ObjectClass *klass, void *data)
+{
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
+    rc->phases.enter = i2c_bus_enter_reset;
+}
+
 static const TypeInfo i2c_bus_info = {
-    .name = TYPE_I2C_BUS,
-    .parent = TYPE_BUS,
-    .instance_size = sizeof(I2CBus),
+   .name = TYPE_I2C_BUS,
+   .parent = TYPE_BUS,
+   .instance_size = sizeof(I2CBus),
+   .class_init = i2c_bus_class_init,
 };
 
 static int i2c_bus_pre_save(void *opaque)
Signature · 1 line
2.40.0.rc2.332.ga46443480c-goog
Acked-by on the v1 series
#4 lore raw
In reply to Joe Komlodi
Quoted 8 lines · Joe Komlodi

Hi all,

This series fixes some I2C state variables not being reset when a reset would happen.

These stale variables would infrequently cause issues, something around the order of 5/1000 runs, since the machine would have to be reset at a point where they would be in a state that would cause problems.

These look good to me. Definitely a missing needed function. Looking through the way it's handled, I think the proper things are being reset and the proper ones are being left alone. There's no checking of the reset type, but there's only one reset type right now, so I guess any changes due to reset type will have to come when new types come.

for another tree, or I can take them.

Thanks,

-corey

Quoted 15 lines

Thanks!
Joe

Joe Komlodi (2):
hw/i2c: smbus_slave: Reset state on reset
hw/i2c: core: Add reset

 hw/i2c/core.c        | 25 ++++++++++++++++++++++---
 hw/i2c/smbus_slave.c |  9 +++++++++
 2 files changed, 31 insertions(+), 3 deletions(-)
Signature · 1 line
2.40.0.rc2.332.ga46443480c-goog