i2c: rcar: avoid race condition with SMIs
authorWolfram Sang <wsa+renesas@sang-engineering.com>
Fri, 20 May 2022 10:33:24 +0000 (12:33 +0200)
committerWolfram Sang <wsa@kernel.org>
Sat, 21 May 2022 06:36:53 +0000 (08:36 +0200)
commita0fb48c9bd7e99c1cad6a5d592c0686fbe0d1803
treec410c92e597dd6e46b4717a567b1b3af2514f8a8
parent3c9fedf9903108430d36c20ed640069eef032f68
i2c: rcar: avoid race condition with SMIs

A customer experienced a race condition with 'repeated starts' when a
System Management Interrupt took over for 30us and more. The problem was
that during the SMI a new MAT interrupt came in because we set up the
'repeated start' condition. But the old one was not acknowledged yet.
So, when it was acknowledged after the SMI, the new MAT interrupt was
lost, confusing the state machine of the driver.

The fix consists of two parts. First, we do not clear the status
register for 'repeated starts' when preparing the next message anymore.
The interrupt handlers for sending and receiving data is now solely
responsible for that and it makes the code easier to follow, in fact.
Secondly, clearing the status register is now split up to handle MAT
interrupts independently. This avoids the race condition because the old
MAT interrupt will be now cleared before we initiate the "repeated
start" condition.

Reported-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
drivers/i2c/busses/i2c-rcar.c