[PATCH v3 5/6] PCI/FLIT: Signal Flit Error Counter events with ERR_COR
From: Yazen Ghannam
Date: Fri Dec 04 2026 - 13:16:40 EST
A Flit Error Counter event is signaled with the PCI Express Capability
interrupt, which only a port service can own. An Endpoint has no way to
report one.
Capability Version 2h can signal the event with an ERR_COR Message
instead.[1] Use it when supported, and keep the interrupt otherwise.
The event sets no AER status bit, so AER logs the ERR_COR but nothing
services it. Have AER check each correctable error source with the Flit
driver, both to find the source and to drain the log and restart the
counter.
A counter stays silent until its event is serviced. AER clears Root
Error Status when it enables a Root Port or RCEC, which can discard an
ERR_COR, so service every ERR_COR counter below it then.
The Extended Flit Error Counter has no ERR_COR enable of its own. Read
Flit Error Counter ERR_COR Enable as covering both counters.
[1] PCIe r7.1, sec 6.2.4.1.3, 6.2.12, 7.7.9.4, 7.7.9.5, 7.7.9.17 and
7.7.9.20
Signed-off-by: Yazen Ghannam <yazen.ghannam@xxxxxxx>
---
drivers/pci/pci.h | 6 ++
drivers/pci/pcie/aer.c | 22 +++++
drivers/pci/pcie/flit.c | 150 +++++++++++++++++++++++++++++++++-
include/uapi/linux/pci_regs.h | 8 ++
4 files changed, 184 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index c755b2f3aef7..c76c812b9524 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -960,12 +960,18 @@ void pci_flit_exit(struct pci_dev *pdev);
void pci_save_flit_state(struct pci_dev *pdev);
void pci_restore_flit_state(struct pci_dev *pdev);
bool pci_flit_uses_irq(struct pci_dev *pdev);
+bool pci_flit_err_cor_pending(struct pci_dev *pdev);
+void pci_flit_handle_err_cor(struct pci_dev *pdev);
+void pci_flit_rearm(struct pci_dev *pdev);
#else
static inline void pci_flit_init(struct pci_dev *pdev) { }
static inline void pci_flit_exit(struct pci_dev *pdev) { }
static inline void pci_save_flit_state(struct pci_dev *pdev) { }
static inline void pci_restore_flit_state(struct pci_dev *pdev) { }
static inline bool pci_flit_uses_irq(struct pci_dev *pdev) { return false; }
+static inline bool pci_flit_err_cor_pending(struct pci_dev *pdev) { return false; }
+static inline void pci_flit_handle_err_cor(struct pci_dev *pdev) { }
+static inline void pci_flit_rearm(struct pci_dev *pdev) { }
#endif
#ifdef CONFIG_PCIEPORTBUS
diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c
index 1973b6eba6b3..376ee7498108 100644
--- a/drivers/pci/pcie/aer.c
+++ b/drivers/pci/pcie/aer.c
@@ -1210,6 +1210,11 @@ static bool is_error_source(struct pci_dev *dev, struct aer_err_info *e_info)
if (!(reg16 & PCI_EXP_AER_FLAGS))
return false;
+ /* A Flit Error Counter event sets no AER status bit */
+ if (e_info->severity == AER_CORRECTABLE &&
+ pci_flit_err_cor_pending(dev))
+ return true;
+
if (!aer) {
pcie_capability_read_word(dev, PCI_EXP_DEVSTA, ®16);
return reg16 & severity2devsta[e_info->severity] &&
@@ -1594,6 +1599,8 @@ static inline void aer_process_err_devices(struct aer_err_info *e_info)
/* Report all before handling them, to not lose records by reset etc. */
for (i = 0; i < e_info->error_dev_num && e_info->dev[i]; i++) {
+ if (e_info->severity == AER_CORRECTABLE)
+ pci_flit_handle_err_cor(e_info->dev[i]);
if (aer_get_device_error_info(e_info, i))
aer_print_error(e_info, i);
}
@@ -1766,6 +1773,12 @@ static int clear_status_iter(struct pci_dev *dev, void *data)
return 0;
}
+static int flit_rearm_iter(struct pci_dev *dev, void *data)
+{
+ pci_flit_rearm(dev);
+ return 0;
+}
+
/**
* aer_enable_rootport - enable Root Port's interrupts when receiving messages
* @rpc: pointer to a Root Port data structure
@@ -1805,6 +1818,15 @@ static void aer_enable_rootport(struct aer_rpc *rpc)
pci_read_config_dword(pdev, aer + PCI_ERR_UNCOR_STATUS, ®32);
pci_write_config_dword(pdev, aer + PCI_ERR_UNCOR_STATUS, reg32);
+ /* Re-arm Flit Error Counters whose ERR_COR was never serviced */
+ if (IS_ENABLED(CONFIG_PCIE_FLIT)) {
+ pci_flit_rearm(pdev);
+ if (pci_pcie_type(pdev) == PCI_EXP_TYPE_RC_EC)
+ pcie_walk_rcec(pdev, flit_rearm_iter, NULL);
+ else if (pdev->subordinate)
+ pci_walk_bus(pdev->subordinate, flit_rearm_iter, NULL);
+ }
+
aer_enable_irq(pdev);
}
diff --git a/drivers/pci/pcie/flit.c b/drivers/pci/pcie/flit.c
index 97395b694238..83a6b50221ef 100644
--- a/drivers/pci/pcie/flit.c
+++ b/drivers/pci/pcie/flit.c
@@ -12,10 +12,12 @@
#define pr_fmt(fmt) "Flit: " fmt
#define dev_fmt pr_fmt
+#include <linux/aer.h>
#include <linux/bitfield.h>
#include <linux/dev_printk.h>
#include <linux/init.h>
#include <linux/interrupt.h>
+#include <linux/mutex.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
@@ -51,6 +53,7 @@ struct flit_cntr {
u32 intr_en; /* Interrupt Enable */
u32 trigger; /* Trigger Event on Error Count */
u32 intr_gen; /* Status: Interrupt Generated */
+ u32 err_cor_gen; /* Status: ERR_COR Generated */
};
static const struct flit_cntr flit_base_cntr = {
@@ -61,6 +64,7 @@ static const struct flit_cntr flit_base_cntr = {
.intr_en = PCI_FLIT_ERR_CNTR_CTRL_INTR_EN,
.trigger = PCI_FLIT_ERR_CNTR_CTRL_TRIGGER,
.intr_gen = PCI_FLIT_ERR_CNTR_STA_INTR_GEN,
+ .err_cor_gen = PCI_FLIT_ERR_CNTR_STA_ERR_COR,
};
static const struct flit_cntr flit_ext_cntr = {
@@ -72,14 +76,18 @@ static const struct flit_cntr flit_ext_cntr = {
.intr_en = PCI_FLIT_EXT_CNTR_CTRL1_INTR_EN,
.trigger = PCI_FLIT_EXT_CNTR_CTRL1_TRIGGER,
.intr_gen = PCI_FLIT_EXT_CNTR_STA_INTR_GEN,
+ .err_cor_gen = PCI_FLIT_EXT_CNTR_STA_ERR_COR,
};
struct flit_info {
spinlock_t lock; /* serializes Counter Control read-modify-write */
+ struct mutex service_lock; /* serializes flit_service() */
const struct flit_cntr *cntr; /* the counter the driver runs */
u32 cntr_cap; /* Flit Error Counter Capability, 0 in 1h */
u32 enable; /* what flit_cntr_enable() turns on */
+ u32 event; /* Status bit that flags an event to service */
u16 trigger; /* Trigger Event on Error Count to program */
+ bool err_cor; /* events are signaled with ERR_COR */
bool cntr_enabled; /* Counter Enable as the driver intends it */
};
@@ -143,6 +151,48 @@ static void flit_select_cntr(struct pci_dev *pdev)
info->cntr = &flit_ext_cntr;
}
+/*
+ * The Root Port or RCEC needs AER to log the ERR_COR, and system firmware must
+ * not claim it through SIG_SFW Enable or RC ECS Handling. The device itself
+ * needs no AER Capability.
+ */
+static bool flit_err_cor_usable(struct pci_dev *pdev)
+{
+ struct flit_info *info = pdev->flit_info;
+ struct pci_dev *root;
+ u32 root_cmd, sfw;
+ u16 ctrl;
+
+ if (!(info->cntr_cap & PCI_FLIT_ERR_CNTR_CAP_ERR_COR))
+ return false;
+
+ if (!pci_aer_available())
+ return false;
+
+ pci_read_config_word(pdev, pdev->flit_cap + PCI_FLIT_ERR_CNTR_CTRL,
+ &ctrl);
+ if (ctrl & PCI_FLIT_ERR_CNTR_CTRL_SIG_SFW_EN)
+ return false;
+
+ if (pci_pcie_type(pdev) == PCI_EXP_TYPE_RC_EC)
+ root = pdev;
+ else
+ root = pcie_find_root_port(pdev);
+
+ if (!root || !root->aer_cap)
+ return false;
+
+ if (pdev->devcap & PCI_EXP_DEVCAP_ECS)
+ sfw = PCI_ERR_ROOT_CMD_ECS_SIG_OS_SFW;
+ else
+ sfw = PCI_ERR_ROOT_CMD_ECS_LEGACY_SFW;
+
+ pci_read_config_dword(root, root->aer_cap + PCI_ERR_ROOT_COMMAND,
+ &root_cmd);
+
+ return !(root_cmd & sfw);
+}
+
static u32 flit_cntr_read(struct pci_dev *pdev, u16 reg)
{
int pos = pdev->flit_cap + reg;
@@ -170,6 +220,8 @@ static void flit_cntr_write(struct pci_dev *pdev, u16 reg, u32 val)
pci_write_config_word(pdev, pos, val);
}
+static void flit_cntr_enable(struct pci_dev *pdev);
+
void pci_flit_init(struct pci_dev *pdev)
{
struct flit_info *info;
@@ -193,11 +245,20 @@ void pci_flit_init(struct pci_dev *pdev)
pdev->flit_info = info;
info->cntr_cap = flit_read_cntr_cap(pdev);
+ info->err_cor = flit_err_cor_usable(pdev);
spin_lock_init(&info->lock);
+ mutex_init(&info->service_lock);
flit_select_cntr(pdev);
- info->enable = info->cntr->en | info->cntr->intr_en;
+
+ if (info->err_cor) {
+ info->enable = info->cntr->en;
+ info->event = info->cntr->err_cor_gen;
+ } else {
+ info->enable = info->cntr->en | info->cntr->intr_en;
+ info->event = info->cntr->intr_gen;
+ }
ctrl = flit_cntr_read(pdev, info->cntr->ctrl);
trigger = field_get(info->cntr->trigger, ctrl);
@@ -210,6 +271,12 @@ void pci_flit_init(struct pci_dev *pdev)
pci_dbg(pdev, "Flit Logging Extended Capability present, using the %s\n",
flit_ext(info) ? "Extended Flit Error Counter" :
"Flit Error Counter");
+
+ /* ERR_COR needs no port service, so start here, after pci_aer_init() */
+ if (info->err_cor) {
+ pci_dbg(pdev, "Flit Error Counter events signaled with ERR_COR\n");
+ flit_cntr_enable(pdev);
+ }
}
void pci_flit_exit(struct pci_dev *pdev)
@@ -332,6 +399,19 @@ static void __flit_save_state_update(struct pci_dev *pdev,
slots[slot] |= set;
}
+/* The extended counter has no ERR_COR enable, so this one covers both */
+static void __flit_err_cor_enable(struct pci_dev *pdev)
+{
+ u16 ctrl = PCI_FLIT_ERR_CNTR_CTRL_ERR_COR_EN;
+
+ lockdep_assert_held(&pdev->flit_info->lock);
+
+ pci_clear_and_set_config_word(pdev,
+ pdev->flit_cap + PCI_FLIT_ERR_CNTR_CTRL,
+ 0, ctrl);
+ __flit_save_state_update(pdev, FLIT_SAVE_CNTR_CTRL, 0, ctrl);
+}
+
static void flit_cntr_enable(struct pci_dev *pdev)
{
struct flit_info *info = pdev->flit_info;
@@ -344,6 +424,10 @@ static void flit_cntr_enable(struct pci_dev *pdev)
/* A 0->1 transition of Counter Enable clears stale event status */
__flit_cntr_ctrl_update(pdev, cntr->en, 0);
+
+ if (info->err_cor)
+ __flit_err_cor_enable(pdev);
+
__flit_cntr_ctrl_update(pdev, cntr->trigger | ctrl,
field_prep(cntr->trigger, info->trigger) |
info->enable);
@@ -448,9 +532,71 @@ static irqreturn_t flit_isr(int irq, void *context)
return IRQ_WAKE_THREAD;
}
+/*
+ * flit_isr() and flit_ist() in one, for ERR_COR. The AER thread and the
+ * rearm walk can both get here, and must not drain one log at once.
+ */
+static void flit_service(struct pci_dev *pdev)
+{
+ struct flit_info *info = pdev->flit_info;
+
+ mutex_lock(&info->service_lock);
+ flit_cntr_pause(pdev);
+ flit_cntr_write(pdev, info->cntr->sta, info->event);
+ flit_drain_log(pdev);
+ flit_cntr_resume(pdev);
+ mutex_unlock(&info->service_lock);
+}
+
bool pci_flit_uses_irq(struct pci_dev *pdev)
{
- return !!pdev->flit_info;
+ return pdev->flit_info && !pdev->flit_info->err_cor;
+}
+
+/**
+ * pci_flit_err_cor_pending - check for a counter event signaled with ERR_COR
+ * @pdev: PCI device that may have sent an ERR_COR
+ *
+ * Return: true if @pdev has an event awaiting pci_flit_handle_err_cor().
+ */
+bool pci_flit_err_cor_pending(struct pci_dev *pdev)
+{
+ struct flit_info *info = pdev->flit_info;
+ u32 sta;
+
+ if (!info || !info->err_cor)
+ return false;
+
+ sta = flit_cntr_read(pdev, info->cntr->sta);
+
+ return !PCI_POSSIBLE_ERROR(sta) && (sta & info->event);
+}
+
+/**
+ * pci_flit_handle_err_cor - service a counter event signaled with ERR_COR
+ * @pdev: PCI device AER identified as the source of an ERR_COR
+ *
+ * Called from the AER interrupt thread for every correctable error source.
+ */
+void pci_flit_handle_err_cor(struct pci_dev *pdev)
+{
+ if (pci_flit_err_cor_pending(pdev))
+ flit_service(pdev);
+}
+
+/**
+ * pci_flit_rearm - service a counter whose ERR_COR may have been discarded
+ * @pdev: PCI device reporting to a Root Port or RCEC AER is enabling
+ *
+ * An ERR_COR that AER cleared while enabling the Root Port or RCEC would
+ * leave the counter silent for good.
+ */
+void pci_flit_rearm(struct pci_dev *pdev)
+{
+ struct flit_info *info = pdev->flit_info;
+
+ if (info && info->err_cor)
+ flit_service(pdev);
}
static int flit_probe(struct pcie_device *dev)
diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h
index 803bfb6fbf49..7302d8edee41 100644
--- a/include/uapi/linux/pci_regs.h
+++ b/include/uapi/linux/pci_regs.h
@@ -505,6 +505,7 @@
#define PCI_EXP_DEVCAP_ATN_IND 0x00002000 /* Attention Indicator Present */
#define PCI_EXP_DEVCAP_PWR_IND 0x00004000 /* Power Indicator Present */
#define PCI_EXP_DEVCAP_RBER 0x00008000 /* Role-Based Error Reporting */
+#define PCI_EXP_DEVCAP_ECS 0x00010000 /* ERR_COR Subclass Capable */
#define PCI_EXP_DEVCAP_PWR_VAL 0x03fc0000 /* Slot Power Limit Value */
#define PCI_EXP_DEVCAP_PWR_SCL 0x0c000000 /* Slot Power Limit Scale */
#define PCI_EXP_DEVCAP_FLR 0x10000000 /* Function Level Reset */
@@ -824,6 +825,8 @@
#define PCI_ERR_ROOT_CMD_COR_EN 0x00000001 /* Correctable Err Reporting Enable */
#define PCI_ERR_ROOT_CMD_NONFATAL_EN 0x00000002 /* Non-Fatal Err Reporting Enable */
#define PCI_ERR_ROOT_CMD_FATAL_EN 0x00000004 /* Fatal Err Reporting Enable */
+#define PCI_ERR_ROOT_CMD_ECS_LEGACY_SFW 0x00000008 /* ECS Legacy Handling by SFW */
+#define PCI_ERR_ROOT_CMD_ECS_SIG_OS_SFW 0x00000020 /* ECS SIG_OS Handling by SFW */
#define PCI_ERR_ROOT_STATUS 0x30
#define PCI_ERR_ROOT_COR_RCV 0x00000001 /* ERR_COR Received */
#define PCI_ERR_ROOT_MULTI_COR_RCV 0x00000002 /* Multiple ERR_COR */
@@ -1201,9 +1204,13 @@
#define PCI_FLIT_ERR_CNTR_CTRL_EN 0x0001 /* Flit Error Counter Enable */
#define PCI_FLIT_ERR_CNTR_CTRL_INTR_EN 0x0002 /* Flit Error Counter Interrupt Enable */
#define PCI_FLIT_ERR_CNTR_CTRL_TRIGGER 0x0ff0 /* Trigger Event on Error Count */
+#define PCI_FLIT_ERR_CNTR_CTRL_ERR_COR_EN 0x1000 /* Flit Error Counter ERR_COR Enable */
+#define PCI_FLIT_ERR_CNTR_CTRL_SIG_SFW_EN 0x2000 /* Flit Error Counter SIG_SFW Enable */
#define PCI_FLIT_ERR_CNTR_STA 0x0e /* Flit Error Counter Status Register */
#define PCI_FLIT_ERR_CNTR_STA_INTR_GEN 0x0008 /* Interrupt Generated based on Trigger */
+#define PCI_FLIT_ERR_CNTR_STA_ERR_COR 0x0020 /* Flit Error Counter ERR_COR Status */
#define PCI_FLIT_ERR_CNTR_CAP 0x3c /* Flit Error Counter Capability Register */
+#define PCI_FLIT_ERR_CNTR_CAP_ERR_COR 0x00000001 /* ERR_COR Signaling Supported */
#define PCI_FLIT_ERR_CNTR_CAP_EXT 0x00000002 /* Extended Flit Error Counter Supported */
#define PCI_FLIT_EXT_CNTR_CTRL1 0x40 /* Ext Flit Error Counter Control 1 */
#define PCI_FLIT_EXT_CNTR_CTRL1_EN 0x00000001 /* Ext Flit Error Counter Enable */
@@ -1213,6 +1220,7 @@
#define PCI_FLIT_EXT_CNTR_CTRL2 0x44 /* Ext Flit Error Counter Control 2 */
#define PCI_FLIT_EXT_CNTR_STA 0x48 /* Ext Flit Error Counter Status */
#define PCI_FLIT_EXT_CNTR_STA_INTR_GEN 0x00000080 /* Intr Generated on Ext Trigger */
+#define PCI_FLIT_EXT_CNTR_STA_ERR_COR 0x00000100 /* ERR_COR Generated on Ext Trigger */
/* Native PCIe Enclosure Management */
#define PCI_NPEM_CAP 0x04 /* NPEM capability register */
--
2.55.0