mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] i2c: piix4: Reset AMD FCH SMBus controller when HOST_BUSY is stuck
@ 2026-11-30 14:07 Yannick Voßen via B4 Relay
  2026-11-30 16:04 ` Mario Limonciello
  0 siblings, 1 reply; 2+ messages in thread
From: Yannick Voßen via B4 Relay @ 2026-11-30 14:07 UTC (permalink / raw)
  To: Jean Delvare, Andi Shyti
  Cc: linux-i2c, linux-kernel, Shyam Sundar S K, Mario Limonciello,
	stable, Yannick Voßen

From: Yannick Voßen <Y.Vossen@beckhoff.com>

On AMD KERNCZ FCH SMBus controllers, HOST_BUSY can remain set after a
transaction collided with another bus master. Clearing the status
register does not recover the controller, so all following
transactions fail with -EBUSY until the next reboot.

The FCH host control register provides a controller reset in bit 7.
Use it when a transaction failed and HOST_BUSY is still set, while the
SMBus semaphore is held and the port is still selected. Restrict this
to the KERNCZ main SMBus controller, since bit 7 is reserved on PIIX4
and has a different meaning on the ASF controller. The reset is only
issued in this error case and holds the semaphore for at most 10 ms.

Tested on a Beckhoff CX20x3 (AMD Ryzen Embedded V1202B, FCH SMBus
[1022:790b] rev 0x61) with a second SMBus master on the same bus that
sends a transaction every few milliseconds. Without this patch, the
first collision (presumably arbitration loss) leaves HOST_BUSY set and
the bus unusable until reboot. With this patch the controller is
reset and subsequent transactions succeed.

Cc: stable@vger.kernel.org
Signed-off-by: Yannick Voßen <Y.Vossen@beckhoff.com>
---
On boards with an additional SMBus master on the same bus, the AMD FCH
host controller can end up with HOST_BUSY stuck after a collision. The
hang is sporadic: it may not show up for hours, or it may happen within
minutes. Once it does, the bus stays unusable until reboot, so Cc
stable for boards that already ship with such a setup.

There is no Fixes: tag, as the driver never had a recovery path for
this condition.

It would be great if someone at AMD could confirm that bit 7 is a
full controller reset on KERNCZ FCH and whether it affects any other
SMBus/ASF state.
---
 drivers/i2c/busses/i2c-piix4.c | 47 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 7b6a4e201be4..f32f5ba8df22 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -34,6 +34,7 @@
 #include <linux/dmi.h>
 #include <linux/acpi.h>
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/platform_data/x86/amd-fch.h>
 
 #include "i2c-piix4.h"
@@ -153,6 +154,7 @@ struct i2c_piix4_adapdata {
 	/* SB800 */
 	bool sb800_main;
 	bool notify_imc;
+	bool fch_reset;
 	u8 port;		/* Port number, shifted */
 	struct sb800_mmio_cfg mmio_cfg;
 };
@@ -769,6 +771,43 @@ int piix4_sb800_port_sel(u8 port, struct sb800_mmio_cfg *mmio_cfg)
 }
 EXPORT_SYMBOL_NS_GPL(piix4_sb800_port_sel, "PIIX4_SMBUS");
 
+/*
+ * HOST_BUSY can get stuck on AMD FCH SMBus controllers, e.g. after a
+ * collision with another bus master. Clearing the status register does
+ * not recover from this, only a controller reset does.
+ */
+static void piix4_fch_reset(struct i2c_adapter *adap,
+			    unsigned short piix4_smba)
+{
+	int ret;
+	u8 sts;
+
+	dev_warn_ratelimited(&adap->dev,
+			     "SMBus host stuck busy, resetting controller\n");
+
+	/*
+	 * Bit 7 resets the controller. This is only valid on the AMD FCH main
+	 * SMBus controller: the bit is reserved on PIIX4 and means DataEn on
+	 * the AMD ASF controller.
+	 */
+	outb_p(0x80, SMBHSTCNT);
+
+	/*
+	 * The reset does not generate bus traffic and is expected to complete
+	 * within microseconds, no value is documented. 10 ms is a generous
+	 * upper bound that keeps the time the SMBus semaphore is held short.
+	 */
+	ret = read_poll_timeout(inb_p, sts, !(sts & 0x01),
+				100, 10 * USEC_PER_MSEC, false, SMBHSTSTS);
+	outb_p(0, SMBHSTCNT);
+	outb_p(inb_p(SMBHSTSTS), SMBHSTSTS);
+
+	if (ret)
+		dev_err_ratelimited(&adap->dev,
+				    "SMBus controller reset failed (%02x)\n",
+				    inb_p(SMBHSTSTS));
+}
+
 /*
  * Handles access to multiple SMBus ports on the SB800.
  * The port is selected by bits 2:1 of the smb_en register (0x2c).
@@ -850,6 +889,11 @@ static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr,
 	retval = piix4_access(adap, addr, flags, read_write,
 			      command, size, data);
 
+	/* Recover while we still own the semaphore and the port is selected */
+	if (retval && adapdata->fch_reset &&
+	    (inb_p(SMBHSTSTS) & 0x01))
+		piix4_fch_reset(adap, piix4_smba);
+
 	piix4_sb800_port_sel(prev_port, &adapdata->mmio_cfg);
 
 	/* Release the semaphore */
@@ -942,6 +986,9 @@ static int piix4_add_adapter(struct pci_dev *dev, unsigned short smba,
 	adapdata->sb800_main = sb800_main;
 	adapdata->port = port << piix4_port_shift_sb800;
 	adapdata->notify_imc = notify_imc;
+	adapdata->fch_reset = sb800_main &&
+			      dev->vendor == PCI_VENDOR_ID_AMD &&
+			      dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS;
 
 	/* set up the sysfs linkage to our parent device */
 	adap->dev.parent = &dev->dev;

---
base-commit: 04e9bf1648f846976b543e91c1838a712433772a
change-id: 20261130-piix4-fch-reset-6bc408e51c2a

Best regards,
--  
Yannick Voßen <Y.Vossen@beckhoff.com>



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-30 16:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 14:07 [PATCH] i2c: piix4: Reset AMD FCH SMBus controller when HOST_BUSY is stuck Yannick Voßen via B4 Relay
2026-11-30 16:04 ` Mario Limonciello

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®