Skip to contentSkip to conversation

i2c-i801: Make interrupt mode more robust

PATCH Applied Jean Delvare 2 participants 6 messages Nov 12, 2014 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover i2c-i801: Make interrupt mode more robust

Hi all,

This is a patch series aiming at making the interrupt mode of the i2c-i801 driver more robust. A number of driver lock-ups have been reported on a few systems over the past few years, all related to interrupt mode. So let's make it more tolerant to unreliable hardware or whatever the actual problem is.

i2c-i801: Use wait_event_timeout to wait for interrupts
i2c-i801: Fallback to polling if request_irq() fails
i2c-i801: Check if interrupts are disabled
i2c-i801: Drop useless debug message

Changes since v1:
* Updated according to Wolfram's review. Thanks!

Signature · 2 lines
Jean Delvare
SUSE L3 Support

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

PATCH v2 1/4 i2c-i801: Use wait_event_timeout to wait for interrupts

Some systems have been reported to have trouble with interrupts. Use wait_event_timeout() instead of wait_event() so we don't get stuck in that case, and log the problem.

Cc Wolfram Sang <wsa-z923LK4zBo2bacvFa/[email protected]>

---
No change since v1.

 drivers/i2c/busses/i2c-i801.c |   25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-i801.c +22 -3
@@ -2,7 +2,7 @@
     Copyright (c) 1998 - 2002  Frodo Looijaard <[email protected]>,
     Philip Edelbrock <[email protected]>, and Mark D. Studebaker
     <mdsxyz123-/[email protected]>
-    Copyright (C) 2007 - 2012  Jean Delvare <[email protected]>
+    Copyright (C) 2007 - 2014  Jean Delvare <[email protected]>
     Copyright (C) 2010         Intel Corporation,
                                David Woodhouse <[email protected]>
 
@@ -373,6 +373,7 @@ static int i801_transaction(struct i801_
 {
 	int status;
 	int result;
+	const struct i2c_adapter *adap = &priv->adapter;
 
 	result = i801_check_pre(priv);
 	if (result < 0)
@@ -381,7 +382,14 @@ static int i801_transaction(struct i801_
 	if (priv->features & FEATURE_IRQ) {
 		outb_p(xact | SMBHSTCNT_INTREN | SMBHSTCNT_START,
 		       SMBHSTCNT(priv));
-		wait_event(priv->waitq, (status = priv->status));
+		result = wait_event_timeout(priv->waitq,
+					    (status = priv->status),
+					    adap->timeout);
+		if (!result) {
+			status = -ETIMEDOUT;
+			dev_warn(&priv->pci_dev->dev,
+				 "Timeout waiting for interrupt!\n");
+		}
 		priv->status = 0;
 		return i801_check_post(priv, status);
 	}
@@ -529,6 +537,7 @@ static int i801_block_transaction_byte_b
 	int smbcmd;
 	int status;
 	int result;
+	const struct i2c_adapter *adap = &priv->adapter;
 
 	result = i801_check_pre(priv);
 	if (result < 0)
@@ -557,7 +566,14 @@ static int i801_block_transaction_byte_b
 		priv->data = &data->block[1];
 
 		outb_p(priv->cmd | SMBHSTCNT_START, SMBHSTCNT(priv));
-		wait_event(priv->waitq, (status = priv->status));
+		result = wait_event_timeout(priv->waitq,
+					    (status = priv->status),
+					    adap->timeout);
+		if (!result) {
+			status = -ETIMEDOUT;
+			dev_warn(&priv->pci_dev->dev,
+				 "Timeout waiting for interrupt!\n");
+		}
 		priv->status = 0;
 		return i801_check_post(priv, status);
 	}
@@ -1215,6 +1231,9 @@ static int i801_probe(struct pci_dev *de
 		outb_p(inb_p(SMBAUXCTL(priv)) &
 		       ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
 
+	/* Default timeout in interrupt mode: 200 ms */
+	priv->adapter.timeout = HZ / 5;
+
 	if (priv->features & FEATURE_IRQ) {
 		init_waitqueue_head(&priv->waitq);
 
Signature · 2 lines
Jean Delvare
SUSE L3 Support
#3 lore raw

PATCH v2 2/4 i2c-i801: Fallback to polling if request_irq() fails

In reply to a message not in the archive

The i2c-i801 driver can work without interrupts, so there is no reason to make a request_irq failure fatal. Instead we can simply fallback to polling.

Cc Wolfram Sang <wsa-z923LK4zBo2bacvFa/[email protected]>

---
Changes since v1:
* Always log whether the driver is using polling or PCI interrupt.

 drivers/i2c/busses/i2c-i801.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-i801.c +3 -3
@@ -1242,10 +1242,11 @@ static int i801_probe(struct pci_dev *de
 		if (err) {
 			dev_err(&dev->dev, "Failed to allocate irq %d: %d\n",
 				dev->irq, err);
-			goto exit_release;
+			priv->features &= ~FEATURE_IRQ;
 		}
-		dev_info(&dev->dev, "SMBus using PCI Interrupt\n");
 	}
+	dev_info(&dev->dev, "SMBus using %s\n",
+		 priv->features & FEATURE_IRQ ? "PCI interrupt" : "polling");
 
 	/* set up the sysfs linkage to our parent device */
 	priv->adapter.dev.parent = &dev->dev;
@@ -1272,7 +1273,6 @@ static int i801_probe(struct pci_dev *de
 exit_free_irq:
 	if (priv->features & FEATURE_IRQ)
 		free_irq(dev->irq, priv);
-exit_release:
 	pci_release_region(dev, SMBBAR);
 exit:
 	kfree(priv);
Signature · 2 lines
Jean Delvare
SUSE L3 Support
#4 lore raw

PATCH v2 3/4 i2c-i801: Check if interrupts are disabled

In reply to a message not in the archive

There is a control bit in the PCI configuration space which disables interrupts. If this bit is set, the driver should not try to make use of interrupts, it won't receive any.

Cc Wolfram Sang <wsa-z923LK4zBo2bacvFa/[email protected]>

---
Changes since v1:
* Turned warning message into info message and made it shorter.

 drivers/i2c/busses/i2c-i801.c |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/i2c/busses/i2c-i801.c +20 -0
@@ -110,12 +110,16 @@
 
 /* PCI Address Constants */
 #define SMBBAR		4
+#define SMBPCICTL	0x004
 #define SMBPCISTS	0x006
 #define SMBHSTCFG	0x040
 
 /* Host status bits for SMBPCISTS */
 #define SMBPCISTS_INTS		0x08
 
+/* Control bits for SMBPCICTL */
+#define SMBPCICTL_INTDIS	0x0400
+
 /* Host configuration bits for SMBHSTCFG */
 #define SMBHSTCFG_HST_EN	1
 #define SMBHSTCFG_SMB_SMI_EN	2
@@ -1235,6 +1239,22 @@ static int i801_probe(struct pci_dev *de
 	priv->adapter.timeout = HZ / 5;
 
 	if (priv->features & FEATURE_IRQ) {
+		u16 pcictl, pcists;
+
+		/* Complain if an interrupt is already pending */
+		pci_read_config_word(priv->pci_dev, SMBPCISTS, &pcists);
+		if (pcists & SMBPCISTS_INTS)
+			dev_warn(&dev->dev, "An interrupt is pending!\n");
+
+		/* Check if interrupts have been disabled */
+		pci_read_config_word(priv->pci_dev, SMBPCICTL, &pcictl);
+		if (pcictl & SMBPCICTL_INTDIS) {
+			dev_info(&dev->dev, "Interrupts are disabled\n");
+			priv->features &= ~FEATURE_IRQ;
+		}
+	}
+
+	if (priv->features & FEATURE_IRQ) {
 		init_waitqueue_head(&priv->waitq);
 
 		err = request_irq(dev->irq, i801_isr, IRQF_SHARED,
Signature · 2 lines
Jean Delvare
SUSE L3 Support
#5 lore raw

PATCH v2 4/4 i2c-i801: Drop useless debug message

In reply to a message not in the archive

Don't log the host status register value in i801_isr(), it has very little value and fills up the log when debugging is enabled.

Cc Wolfram Sang <wsa-z923LK4zBo2bacvFa/[email protected]>

---
No change since v1.

 drivers/i2c/busses/i2c-i801.c |    3 ---
 1 file changed, 3 deletions(-)
drivers/i2c/busses/i2c-i801.c +0 -3
@@ -507,9 +507,6 @@ static irqreturn_t i801_isr(int irq, voi
 		return IRQ_NONE;
 
 	status = inb_p(SMBHSTSTS(priv));
-	if (status != 0x42)
-		dev_dbg(&priv->pci_dev->dev, "irq: status = %02x\n", status);
-
 	if (status & SMBHSTSTS_BYTE_DONE)
 		i801_isr_byte_done(priv);
 
Signature · 2 lines
Jean Delvare
SUSE L3 Support
Applied
#6 lore raw
In reply to a message not in the archive
Quoted 8 lines · Jean Delvare

Hi all,

This is a patch series aiming at making the interrupt mode of the i2c-i801 driver more robust. A number of driver lock-ups have been reported on a few systems over the past few years, all related to interrupt mode. So let's make it more tolerant to unreliable hardware or whatever the actual problem is.

Quoted 4 lines

i2c-i801: Use wait_event_timeout to wait for interrupts
i2c-i801: Fallback to polling if request_irq() fails
i2c-i801: Check if interrupts are disabled
i2c-i801: Drop useless debug message

Applied to for-next, thanks!