[PATCH] hw/misc/i2c-echo: Fix quick smbus transfer

Chaitanya Dhere posted 1 patch 3 days, 16 hours ago
hw/misc/i2c-echo.c                                    | 10 +++++++---
tests/functional/arm/test_aspeed_ast2600_buildroot.py |  6 ++++++
2 files changed, 13 insertions(+), 3 deletions(-)
[PATCH] hw/misc/i2c-echo: Fix quick smbus transfer
Posted by Chaitanya Dhere 3 days, 16 hours ago
Avoid initiating a echo transfer when I2C_FINISH
is received with zero payload bytes. This is
observed during an quick transfer leading to a
interrupt mismatch.

Fix the i2c-echo code to handle both the cases
when payload is zero and otherwise. Add a check
in functional test to validate the change.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4457

Signed-off-by: Chaitanya Dhere <dherechaitanya@gmail.com>
---
 hw/misc/i2c-echo.c                                    | 10 +++++++---
 tests/functional/arm/test_aspeed_ast2600_buildroot.py |  6 ++++++
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/hw/misc/i2c-echo.c b/hw/misc/i2c-echo.c
index 54d07db6fa..936a4cc05b 100644
--- a/hw/misc/i2c-echo.c
+++ b/hw/misc/i2c-echo.c
@@ -90,9 +90,13 @@ static int i2c_echo_event(I2CSlave *s, enum i2c_event event)
         break;
 
     case I2C_FINISH:
-        state->pos = 0;
-        state->state = I2C_ECHO_STATE_START_SEND;
-        i2c_bus_master(state->bus, state->bh);
+        if (state->pos == 0) {
+            state->state = I2C_ECHO_STATE_IDLE;
+        } else {
+            state->pos = 0;
+            state->state = I2C_ECHO_STATE_START_SEND;
+            i2c_bus_master(state->bus, state->bh);
+        }
 
         trace_i2c_echo_event(DEVICE(s)->canonical_path, "I2C_FINISH");
         break;
diff --git a/tests/functional/arm/test_aspeed_ast2600_buildroot.py b/tests/functional/arm/test_aspeed_ast2600_buildroot.py
index cc5ab9796a..5d7ff56738 100755
--- a/tests/functional/arm/test_aspeed_ast2600_buildroot.py
+++ b/tests/functional/arm/test_aspeed_ast2600_buildroot.py
@@ -51,6 +51,12 @@ def test_arm_ast2600_evb_buildroot(self):
         year = time.strftime("%Y")
         exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year)
 
+        exec_command_and_wait_for_pattern(self,
+            "i2cdetect -y 3 0x42 0x42 | grep -q '42' && "
+            "printf 'I2C_ECHO_QUICK_%s\\n' OK",
+            "I2C_ECHO_QUICK_OK",
+            "irq handled != irq")
+
         exec_command_and_wait_for_pattern(self,
              'echo slave-24c02 0x1064 > /sys/bus/i2c/devices/i2c-3/new_device',
              'i2c i2c-3: new_device: Instantiated device slave-24c02 at 0x64')

---
base-commit: 3c061218fcf37a98c944ecb88cff56f94f5c0a43
change-id: 20261202-fix-i2c-echo-bug-497b05a82bce

Best regards,
--  
Chaitanya Dhere <dherechaitanya@gmail.com>