• Finn Thain's avatar
    macintosh/adb-iop: Always wait for reply message from IOP · 2c9cfbad
    Finn Thain authored
    A recent patch incorrectly altered the adb-iop state machine behaviour
    and introduced a regression that can appear intermittently as a
    malfunctioning ADB input device. This seems to be caused when reply
    packets from different ADB commands become mixed up, especially during
    the adb bus scan. Fix this by unconditionally entering the awaiting_reply
    state after sending an explicit command, even when the ADB command won't
    generate a reply from the ADB device.
    
    It turns out that the IOP always generates reply messages, even when the
    ADB command does not produce a reply packet (e.g. ADB Listen command).
    So it's not really the ADB reply packets that are being mixed up, it's the
    IOP messages that enclose them. The bug goes like this:
    
      1. CPU sends a message to the IOP, expecting no response because this
         message contains an ADB Listen command. The ADB command is now
         considered complete.
    
      2. CPU sends a second message to the IOP, this time expecting a
         response because this message contains an ADB Talk command. This
         ADB command needs a reply before it can be completed.
    
      3. adb-iop driver receives an IOP message and assumes that it relates
         to the Talk command. It's actually an empty one (with flags ==
         ADB_IOP_EXPLICIT|ADB_IOP_TIMEOUT) for the previous command. The
         Talk command is now considered complete but it gets the wrong reply
         data.
    
      4. adb-iop driver gets another IOP response message, which contains
         the actual reply data for the Talk command, but this is dropped
         (the driver is no longer in awaiting_reply state).
    
    Cc: Joshua Thompson <funaho@jurai.org>
    Fixes: e2954e5f ("macintosh/adb-iop: Implement sending -> idle state transition")
    Tested-by: default avatarStan Johnson <userm57@yahoo.com>
    Signed-off-by: default avatarFinn Thain <fthain@telegraphics.com.au>
    Link: https://lore.kernel.org/r/0f0a25855391e7eaa53a50f651aea0124e8525dd.1605847196.git.fthain@telegraphics.com.auSigned-off-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
    2c9cfbad
adb-iop.c 5.67 KB