Skip to content

Commit 301c8f5

Browse files
jhnikulawsakernel
authored andcommitted
i2c: designware: Fix handling of real but unexpected device interrupts
Commit c7b79a7 ("mfd: intel-lpss: Add Intel Alder Lake PCH-S PCI IDs") caused a regression on certain Gigabyte motherboards for Intel Alder Lake-S where system crashes to NULL pointer dereference in i2c_dw_xfer_msg() when system resumes from S3 sleep state ("deep"). I was able to debug the issue on Gigabyte Z690 AORUS ELITE and made following notes: - Issue happens when resuming from S3 but not when resuming from "s2idle" - PCI device 00:15.0 == i2c_designware.0 is already in D0 state when system enters into pci_pm_resume_noirq() while all other i2c_designware PCI devices are in D3. Devices were runtime suspended and in D3 prior entering into suspend - Interrupt comes after pci_pm_resume_noirq() when device interrupts are re-enabled - According to register dump the interrupt really comes from the i2c_designware.0. Controller is enabled, I2C target address register points to a one detectable I2C device address 0x60 and the DW_IC_RAW_INTR_STAT register START_DET, STOP_DET, ACTIVITY and TX_EMPTY bits are set indicating completed I2C transaction. My guess is that the firmware uses this controller to communicate with an on-board I2C device during resume but does not disable the controller before giving control to an operating system. I was told the UEFI update fixes this but never the less it revealed the driver is not ready to handle TX_EMPTY (or RX_FULL) interrupt when device is supposed to be idle and state variables are not set (especially the dev->msgs pointer which may point to NULL or stale old data). Introduce a new software status flag STATUS_ACTIVE indicating when the controller is active in driver point of view. Now treat all interrupts that occur when is not set as unexpected and mask all interrupts from the controller. Fixes: c7b79a7 ("mfd: intel-lpss: Add Intel Alder Lake PCH-S PCI IDs") Reported-by: Samuel Clark <[email protected]> Link: https://bugzilla.kernel.org/show_bug.cgi?id=215907 Cc: [email protected] # v5.12+ Signed-off-by: Jarkko Nikula <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent d046bd1 commit 301c8f5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

drivers/i2c/busses/i2c-designware-core.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@
126126
* status codes
127127
*/
128128
#define STATUS_IDLE 0x0
129-
#define STATUS_WRITE_IN_PROGRESS 0x1
130-
#define STATUS_READ_IN_PROGRESS 0x2
129+
#define STATUS_ACTIVE 0x1
130+
#define STATUS_WRITE_IN_PROGRESS 0x2
131+
#define STATUS_READ_IN_PROGRESS 0x4
131132

132133
/*
133134
* operation modes
@@ -334,12 +335,14 @@ void i2c_dw_disable_int(struct dw_i2c_dev *dev);
334335

335336
static inline void __i2c_dw_enable(struct dw_i2c_dev *dev)
336337
{
338+
dev->status |= STATUS_ACTIVE;
337339
regmap_write(dev->map, DW_IC_ENABLE, 1);
338340
}
339341

340342
static inline void __i2c_dw_disable_nowait(struct dw_i2c_dev *dev)
341343
{
342344
regmap_write(dev->map, DW_IC_ENABLE, 0);
345+
dev->status &= ~STATUS_ACTIVE;
343346
}
344347

345348
void __i2c_dw_disable(struct dw_i2c_dev *dev);

drivers/i2c/busses/i2c-designware-master.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,19 @@ static int i2c_dw_irq_handler_master(struct dw_i2c_dev *dev)
716716
u32 stat;
717717

718718
stat = i2c_dw_read_clear_intrbits(dev);
719+
720+
if (!(dev->status & STATUS_ACTIVE)) {
721+
/*
722+
* Unexpected interrupt in driver point of view. State
723+
* variables are either unset or stale so acknowledge and
724+
* disable interrupts for suppressing further interrupts if
725+
* interrupt really came from this HW (E.g. firmware has left
726+
* the HW active).
727+
*/
728+
regmap_write(dev->map, DW_IC_INTR_MASK, 0);
729+
return 0;
730+
}
731+
719732
if (stat & DW_IC_INTR_TX_ABRT) {
720733
dev->cmd_err |= DW_IC_ERR_TX_ABRT;
721734
dev->status = STATUS_IDLE;

0 commit comments

Comments
 (0)