[PATCH v3 3/6] PCI/FLIT: Add support for Flit Logging Extended Capability

From: Yazen Ghannam

Date: Fri Dec 04 2026 - 13:16:56 EST


PCIe r7.1 requires the Flit Logging Extended Capability on ports and
RCRBs that support Flit Mode.[1] It logs flits received with errors and
counts them against a programmable trigger.

Add a port service driver for it, with _OSC negotiation of control like
the other port services.

[1] PCIe r7.1, sec 7.7.9

Link: https://pcisig.com/specification/extend-osc-negotiate-control-pcie-flit-logging-extended-capability
Originally-by: Avadhut Naik <avadhut.naik@xxxxxxx>
Signed-off-by: Yazen Ghannam <yazen.ghannam@xxxxxxx>
---
drivers/acpi/pci_root.c | 15 +-
drivers/pci/controller/vmd.c | 1 +
drivers/pci/pci.c | 2 +
drivers/pci/pci.h | 14 ++
drivers/pci/pcie/Kconfig | 9 +
drivers/pci/pcie/Makefile | 1 +
drivers/pci/pcie/flit.c | 407 ++++++++++++++++++++++++++++++++++
drivers/pci/pcie/portdrv.c | 4 +
drivers/pci/pcie/portdrv.h | 13 +-
drivers/pci/probe.c | 3 +
include/linux/acpi.h | 1 +
include/linux/pci.h | 6 +
include/uapi/linux/pci_regs.h | 19 +-
13 files changed, 489 insertions(+), 6 deletions(-)
create mode 100644 drivers/pci/pcie/flit.c

diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index b08261b6372f..49532d209684 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -137,6 +137,7 @@ static struct pci_osc_bit_struct pci_osc_control_bit[] = {
{ OSC_PCI_EXPRESS_CAPABILITY_CONTROL, "PCIeCapability" },
{ OSC_PCI_EXPRESS_LTR_CONTROL, "LTR" },
{ OSC_PCI_EXPRESS_DPC_CONTROL, "DPC" },
+ { OSC_PCI_EXPRESS_FLIT_CONTROL, "FlitLogging" },
};

static struct pci_osc_bit_struct cxl_osc_support_bit[] = {
@@ -522,6 +523,11 @@ static u32 calculate_control(void)
(control & OSC_PCI_EXPRESS_AER_CONTROL))
control |= OSC_PCI_EXPRESS_DPC_CONTROL;

+ /* An OS requesting Flit Logging control must also request AER control */
+ if (IS_ENABLED(CONFIG_PCIE_FLIT) &&
+ (control & OSC_PCI_EXPRESS_AER_CONTROL))
+ control |= OSC_PCI_EXPRESS_FLIT_CONTROL;
+
return control;
}

@@ -1012,7 +1018,8 @@ static void acpi_pci_root_release_info(struct pci_host_bridge *bridge)
#define OSC_PCIE_PORT_SERVICE_CONTROLS (OSC_PCI_EXPRESS_NATIVE_HP_CONTROL | \
OSC_PCI_EXPRESS_PME_CONTROL | \
OSC_PCI_EXPRESS_AER_CONTROL | \
- OSC_PCI_EXPRESS_DPC_CONTROL)
+ OSC_PCI_EXPRESS_DPC_CONTROL | \
+ OSC_PCI_EXPRESS_FLIT_CONTROL)

struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root,
struct acpi_pci_root_ops *ops,
@@ -1095,17 +1102,19 @@ struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root,
OSC_OWNER(ctrl, OSC_PCI_EXPRESS_PME_CONTROL, host_bridge->native_pme);
OSC_OWNER(ctrl, OSC_PCI_EXPRESS_LTR_CONTROL, host_bridge->native_ltr);
OSC_OWNER(ctrl, OSC_PCI_EXPRESS_DPC_CONTROL, host_bridge->native_dpc);
+ OSC_OWNER(ctrl, OSC_PCI_EXPRESS_FLIT_CONTROL, host_bridge->native_flit);

OSC_OWNER(ext_ctrl, OSC_CXL_ERROR_REPORTING_CONTROL,
host_bridge->native_cxl_error);

- dev_info(&root->device->dev, "OS native features: SHPCHotplug%c PCIeHotplug%c PME%c AER%c DPC%c LTR%c\n",
+ dev_info(&root->device->dev, "OS native features: SHPCHotplug%c PCIeHotplug%c PME%c AER%c DPC%c LTR%c FlitLogging%c\n",
FLAG(host_bridge->native_shpc_hotplug),
FLAG(host_bridge->native_pcie_hotplug),
FLAG(host_bridge->native_pme),
FLAG(host_bridge->native_aer),
FLAG(host_bridge->native_dpc),
- FLAG(host_bridge->native_ltr));
+ FLAG(host_bridge->native_ltr),
+ FLAG(host_bridge->native_flit));

acpi_dev_power_up_children_with_adr(device);

diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c
index 9d97a832785e..36d67b9c8f62 100644
--- a/drivers/pci/controller/vmd.c
+++ b/drivers/pci/controller/vmd.c
@@ -907,6 +907,7 @@ static void vmd_copy_host_bridge_flags(struct pci_host_bridge *root_bridge,
vmd_bridge->native_pme = root_bridge->native_pme;
vmd_bridge->native_ltr = root_bridge->native_ltr;
vmd_bridge->native_dpc = root_bridge->native_dpc;
+ vmd_bridge->native_flit = root_bridge->native_flit;
}

/*
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7c6f2aba8144..5effe559a876 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1823,6 +1823,7 @@ int pci_save_state(struct pci_dev *dev)

pci_save_dpc_state(dev);
pci_save_aer_state(dev);
+ pci_save_flit_state(dev);
pci_save_ptm_state(dev);
pci_save_tph_state(dev);
return pci_save_vc_state(dev);
@@ -1895,6 +1896,7 @@ void pci_restore_state(struct pci_dev *dev)

pci_aer_clear_status(dev);
pci_restore_aer_state(dev);
+ pci_restore_flit_state(dev);

pci_restore_config_space(dev);

diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 2f21246380dd..c755b2f3aef7 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -954,6 +954,20 @@ static inline void pci_dpc_init(struct pci_dev *pdev) { }
static inline bool pci_dpc_recovered(struct pci_dev *pdev) { return false; }
#endif

+#ifdef CONFIG_PCIE_FLIT
+void pci_flit_init(struct pci_dev *pdev);
+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);
+#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; }
+#endif
+
#ifdef CONFIG_PCIEPORTBUS
void pci_rcec_init(struct pci_dev *dev);
void pci_rcec_exit(struct pci_dev *dev);
diff --git a/drivers/pci/pcie/Kconfig b/drivers/pci/pcie/Kconfig
index 4d097c53f140..b30147d064eb 100644
--- a/drivers/pci/pcie/Kconfig
+++ b/drivers/pci/pcie/Kconfig
@@ -140,3 +140,12 @@ config PCIE_PTM
config PCIE_EDR
def_bool y
depends on PCIE_DPC && ACPI
+
+config PCIE_FLIT
+ bool "PCI Express Flit Logging support"
+ depends on PCIEAER
+ help
+ This enables support for the PCI Express Flit Logging Extended
+ Capability, which logs errors encountered by a port operating
+ in PCIe Flit Mode. If your system doesn't have this capability
+ or you do not want to use this feature, it is safe to answer N.
diff --git a/drivers/pci/pcie/Makefile b/drivers/pci/pcie/Makefile
index b0b43a18c304..14a5222920b9 100644
--- a/drivers/pci/pcie/Makefile
+++ b/drivers/pci/pcie/Makefile
@@ -14,3 +14,4 @@ obj-$(CONFIG_PCIE_PME) += pme.o
obj-$(CONFIG_PCIE_DPC) += dpc.o
obj-$(CONFIG_PCIE_PTM) += ptm.o
obj-$(CONFIG_PCIE_EDR) += edr.o
+obj-$(CONFIG_PCIE_FLIT) += flit.o
diff --git a/drivers/pci/pcie/flit.c b/drivers/pci/pcie/flit.c
new file mode 100644
index 000000000000..00409dd7bb95
--- /dev/null
+++ b/drivers/pci/pcie/flit.c
@@ -0,0 +1,407 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Service driver for PCIe Flit Logging Extended Capability
+ *
+ * Copyright (c) 2026, Advanced Micro Devices, Inc.
+ * All Rights Reserved.
+ *
+ * Authors: Avadhut Naik <Avadhut.Naik@xxxxxxx>
+ * Yazen Ghannam <Yazen.Ghannam@xxxxxxx>
+ */
+
+#define pr_fmt(fmt) "Flit: " fmt
+#define dev_fmt pr_fmt
+
+#include <linux/bitfield.h>
+#include <linux/dev_printk.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/pci.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+
+#include "portdrv.h"
+#include "../pci.h"
+
+/* Highest trigger that fires: an event needs the count to exceed it */
+#define FLIT_DEFAULT_TRIGGER 0xfe
+
+/* More Entries can be set again mid-drain, so bound the loop */
+#define FLIT_MAX_LOG_ENTRIES 0xff
+
+/* An entry with none of these set and Flit Error Log 2 zero is Reserved */
+#define FLIT_ERR_LOG1_ERROR (PCI_FLIT_ERR_LOG1_UNRECOG | \
+ PCI_FLIT_ERR_LOG1_FEC_UNCOR | \
+ PCI_FLIT_ERR_LOG1_SYND_PARITY0 | \
+ PCI_FLIT_ERR_LOG1_SYND_CHECK0)
+
+enum flit_save_slot {
+ FLIT_SAVE_CNTR_CTRL,
+ FLIT_SAVE_SLOTS
+};
+
+struct flit_cntr {
+ u16 ctrl; /* Control register offset */
+ u16 sta; /* Status register offset */
+ enum flit_save_slot slot; /* save buffer slot of Control */
+ u32 en; /* Counter Enable */
+ u32 intr_en; /* Interrupt Enable */
+ u32 trigger; /* Trigger Event on Error Count */
+ u32 intr_gen; /* Status: Interrupt Generated */
+};
+
+static const struct flit_cntr flit_base_cntr = {
+ .ctrl = PCI_FLIT_ERR_CNTR_CTRL,
+ .sta = PCI_FLIT_ERR_CNTR_STA,
+ .slot = FLIT_SAVE_CNTR_CTRL,
+ .en = PCI_FLIT_ERR_CNTR_CTRL_EN,
+ .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,
+};
+
+struct flit_info {
+ spinlock_t lock; /* serializes Counter Control read-modify-write */
+ const struct flit_cntr *cntr; /* the counter the driver runs */
+ u32 enable; /* what flit_cntr_enable() turns on */
+ u16 trigger; /* Trigger Event on Error Count to program */
+ bool cntr_enabled; /* Counter Enable as the driver intends it */
+};
+
+/* The port types pcie_portdrv_probe() claims */
+static bool flit_is_port(struct pci_dev *pdev)
+{
+ if (!pci_is_pcie(pdev))
+ return false;
+
+ switch (pci_pcie_type(pdev)) {
+ case PCI_EXP_TYPE_ROOT_PORT:
+ case PCI_EXP_TYPE_UPSTREAM:
+ case PCI_EXP_TYPE_DOWNSTREAM:
+ case PCI_EXP_TYPE_RC_EC:
+ return true;
+ default:
+ return false;
+ }
+}
+
+/* Flit Logging control is only meaningful alongside AER control */
+static bool flit_is_native(struct pci_dev *pdev)
+{
+ struct pci_host_bridge *host = pci_find_host_bridge(pdev->bus);
+
+ return host->native_flit && host->native_aer;
+}
+
+static u32 flit_cntr_read(struct pci_dev *pdev, u16 reg)
+{
+ int pos = pdev->flit_cap + reg;
+ u16 val16;
+
+ pci_read_config_word(pdev, pos, &val16);
+
+ /* Keep an error response recognizable to PCI_POSSIBLE_ERROR() */
+ return PCI_POSSIBLE_ERROR(val16) ? ~0U : val16;
+}
+
+static void flit_cntr_write(struct pci_dev *pdev, u16 reg, u32 val)
+{
+ pci_write_config_word(pdev, pdev->flit_cap + reg, val);
+}
+
+void pci_flit_init(struct pci_dev *pdev)
+{
+ struct flit_info *info;
+ u16 trigger;
+ u32 ctrl;
+
+ if (!flit_is_port(pdev) || !flit_is_native(pdev))
+ return;
+
+ pdev->flit_cap = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_FLIT);
+ if (!pdev->flit_cap)
+ return;
+
+ info = kzalloc_obj(*info);
+ if (!info) {
+ pdev->flit_cap = 0;
+ return;
+ }
+
+ pdev->flit_info = info;
+
+ spin_lock_init(&info->lock);
+
+ info->cntr = &flit_base_cntr;
+ info->enable = info->cntr->en | info->cntr->intr_en;
+
+ ctrl = flit_cntr_read(pdev, info->cntr->ctrl);
+ trigger = field_get(info->cntr->trigger, ctrl);
+ info->trigger = trigger ? trigger : FLIT_DEFAULT_TRIGGER;
+
+ pci_add_ext_cap_save_buffer(pdev, PCI_EXT_CAP_ID_FLIT,
+ FLIT_SAVE_SLOTS * sizeof(u32));
+}
+
+void pci_flit_exit(struct pci_dev *pdev)
+{
+ kfree(pdev->flit_info);
+ pdev->flit_info = NULL;
+ pdev->flit_cap = 0;
+}
+
+static u32 *flit_save_slots(struct pci_dev *pdev)
+{
+ struct pci_cap_saved_state *save_state;
+
+ save_state = pci_find_saved_ext_cap(pdev, PCI_EXT_CAP_ID_FLIT);
+
+ return save_state ? save_state->cap.data : NULL;
+}
+
+void pci_save_flit_state(struct pci_dev *pdev)
+{
+ struct flit_info *info = pdev->flit_info;
+ const struct flit_cntr *cntr;
+ u16 flit = pdev->flit_cap;
+ unsigned long flags;
+ u32 *slots;
+ u16 ctrl;
+
+ if (!flit)
+ return;
+
+ slots = flit_save_slots(pdev);
+ if (!slots)
+ return;
+
+ cntr = info->cntr;
+
+ spin_lock_irqsave(&info->lock, flags);
+ pci_read_config_word(pdev, flit + PCI_FLIT_ERR_CNTR_CTRL, &ctrl);
+ slots[FLIT_SAVE_CNTR_CTRL] = ctrl;
+
+ /* Counter Enable is clear in the register while an event is serviced */
+ if (info->cntr_enabled)
+ slots[cntr->slot] |= cntr->en;
+ else
+ slots[cntr->slot] &= ~cntr->en;
+ spin_unlock_irqrestore(&info->lock, flags);
+}
+
+void pci_restore_flit_state(struct pci_dev *pdev)
+{
+ struct flit_info *info = pdev->flit_info;
+ u16 flit = pdev->flit_cap;
+ unsigned long flags;
+ u32 *slots;
+
+ if (!flit)
+ return;
+
+ slots = flit_save_slots(pdev);
+ if (!slots)
+ return;
+
+ /* Event servicing can run during a runtime resume or slot reset */
+ spin_lock_irqsave(&info->lock, flags);
+ pci_write_config_word(pdev, flit + PCI_FLIT_ERR_CNTR_CTRL,
+ slots[FLIT_SAVE_CNTR_CTRL]);
+ spin_unlock_irqrestore(&info->lock, flags);
+}
+
+/* A lost update can leave the trigger at zero, which never fires */
+static void __flit_cntr_ctrl_update(struct pci_dev *pdev, u32 clear, u32 set)
+{
+ const struct flit_cntr *cntr = pdev->flit_info->cntr;
+ int pos = pdev->flit_cap + cntr->ctrl;
+
+ lockdep_assert_held(&pdev->flit_info->lock);
+
+ pci_clear_and_set_config_word(pdev, pos, clear, set);
+}
+
+/* pcie_do_recovery() restores the save buffer without saving it first */
+static void __flit_save_state_update(struct pci_dev *pdev,
+ enum flit_save_slot slot,
+ u32 clear, u32 set)
+{
+ u32 *slots;
+
+ lockdep_assert_held(&pdev->flit_info->lock);
+
+ slots = flit_save_slots(pdev);
+ if (!slots)
+ return;
+
+ slots[slot] &= ~clear;
+ slots[slot] |= set;
+}
+
+static void flit_cntr_enable(struct pci_dev *pdev)
+{
+ struct flit_info *info = pdev->flit_info;
+ const struct flit_cntr *cntr = info->cntr;
+ u32 ctrl = cntr->en | cntr->intr_en;
+ unsigned long flags;
+
+ spin_lock_irqsave(&info->lock, flags);
+ info->cntr_enabled = true;
+
+ /* A 0->1 transition of Counter Enable clears stale event status */
+ __flit_cntr_ctrl_update(pdev, cntr->en, 0);
+ __flit_cntr_ctrl_update(pdev, cntr->trigger | ctrl,
+ field_prep(cntr->trigger, info->trigger) |
+ info->enable);
+ __flit_save_state_update(pdev, cntr->slot, ctrl, info->enable);
+ spin_unlock_irqrestore(&info->lock, flags);
+}
+
+static void flit_cntr_disable(struct pci_dev *pdev)
+{
+ struct flit_info *info = pdev->flit_info;
+ unsigned long flags;
+
+ spin_lock_irqsave(&info->lock, flags);
+ info->cntr_enabled = false;
+ __flit_cntr_ctrl_update(pdev, info->enable, 0);
+ __flit_save_state_update(pdev, info->cntr->slot, info->enable, 0);
+ spin_unlock_irqrestore(&info->lock, flags);
+}
+
+/* Stop counting until the log is drained */
+static void flit_cntr_pause(struct pci_dev *pdev)
+{
+ struct flit_info *info = pdev->flit_info;
+ unsigned long flags;
+
+ spin_lock_irqsave(&info->lock, flags);
+ __flit_cntr_ctrl_update(pdev, info->cntr->en, 0);
+ spin_unlock_irqrestore(&info->lock, flags);
+}
+
+/* Re-arm event generation, unless flit_cntr_disable() ran meanwhile */
+static void flit_cntr_resume(struct pci_dev *pdev)
+{
+ struct flit_info *info = pdev->flit_info;
+ unsigned long flags;
+
+ spin_lock_irqsave(&info->lock, flags);
+ if (info->cntr_enabled)
+ __flit_cntr_ctrl_update(pdev, 0, info->cntr->en);
+ spin_unlock_irqrestore(&info->lock, flags);
+}
+
+static void flit_report(struct pci_dev *pdev, u32 err_log1, u32 err_log2)
+{
+ if (!(err_log1 & FLIT_ERR_LOG1_ERROR) && !err_log2)
+ return;
+
+ pci_warn(pdev, "ErrLog1: 0x%08x ErrLog2: 0x%08x\n", err_log1, err_log2);
+}
+
+static void flit_drain_log(struct pci_dev *pdev)
+{
+ u16 flit = pdev->flit_cap;
+ u32 err_log1, err_log2;
+ unsigned int i;
+
+ for (i = 0; i < FLIT_MAX_LOG_ENTRIES; i++) {
+ pci_read_config_dword(pdev, flit + PCI_FLIT_ERR_LOG1, &err_log1);
+
+ if (PCI_POSSIBLE_ERROR(err_log1) || !(err_log1 & PCI_FLIT_ERR_LOG1_VALID))
+ break;
+
+ pci_read_config_dword(pdev, flit + PCI_FLIT_ERR_LOG2, &err_log2);
+
+ flit_report(pdev, err_log1, err_log2);
+
+ /* Clearing Valid loads the next entry */
+ pci_write_config_dword(pdev, flit + PCI_FLIT_ERR_LOG1, err_log1);
+
+ if (!(err_log1 & PCI_FLIT_ERR_LOG1_MORE))
+ break;
+ }
+}
+
+static irqreturn_t flit_ist(int irq, void *context)
+{
+ struct pcie_device *dev = (struct pcie_device *)context;
+ struct pci_dev *pdev = dev->port;
+
+ flit_drain_log(pdev);
+ flit_cntr_resume(pdev);
+
+ return IRQ_HANDLED;
+}
+
+static irqreturn_t flit_isr(int irq, void *context)
+{
+ struct pcie_device *dev = (struct pcie_device *)context;
+ struct pci_dev *pdev = dev->port;
+ const struct flit_cntr *cntr;
+ u32 sta;
+
+ cntr = pdev->flit_info->cntr;
+
+ sta = flit_cntr_read(pdev, cntr->sta);
+ if (PCI_POSSIBLE_ERROR(sta) || !(sta & cntr->intr_gen))
+ return IRQ_NONE;
+
+ /* On INTx the line stays asserted until the status is cleared */
+ flit_cntr_pause(pdev);
+ flit_cntr_write(pdev, cntr->sta, cntr->intr_gen);
+ return IRQ_WAKE_THREAD;
+}
+
+bool pci_flit_uses_irq(struct pci_dev *pdev)
+{
+ return !!pdev->flit_info;
+}
+
+static int flit_probe(struct pcie_device *dev)
+{
+ struct pci_dev *pdev = dev->port;
+ int status;
+
+ status = request_threaded_irq(dev->irq, flit_isr, flit_ist,
+ IRQF_SHARED, "pcie-flit", dev);
+ if (status) {
+ pci_warn(pdev, "request Flit IRQ %d failed: %d\n", dev->irq, status);
+ return status;
+ }
+
+ flit_cntr_enable(pdev);
+
+ return 0;
+}
+
+/* No suspend callbacks: pci_save_state() would save the counter disabled */
+static int flit_cntr_restore(struct pcie_device *dev)
+{
+ flit_cntr_enable(dev->port);
+ return 0;
+}
+
+/* Disable first, or an event can assert a shared INTx line with no handler */
+static void flit_cntr_remove(struct pcie_device *dev)
+{
+ flit_cntr_disable(dev->port);
+ free_irq(dev->irq, dev);
+}
+
+static struct pcie_port_service_driver flitdriver = {
+ .name = "flit",
+ .port_type = PCIE_ANY_PORT,
+ .service = PCIE_PORT_SERVICE_FLIT,
+ .probe = flit_probe,
+ .resume = flit_cntr_restore,
+ .runtime_resume = flit_cntr_restore,
+ .slot_reset = flit_cntr_restore,
+ .remove = flit_cntr_remove,
+};
+
+int __init pcie_flit_init(void)
+{
+ return pcie_port_service_register(&flitdriver);
+}
diff --git a/drivers/pci/pcie/portdrv.c b/drivers/pci/pcie/portdrv.c
index 17a2d4a12349..dd59b0147edd 100644
--- a/drivers/pci/pcie/portdrv.c
+++ b/drivers/pci/pcie/portdrv.c
@@ -273,6 +273,9 @@ static int get_port_device_capability(struct pci_dev *dev)
services |= PCIE_PORT_SERVICE_BWCTRL;
}

+ if (pci_flit_uses_irq(dev))
+ services |= PCIE_PORT_SERVICE_FLIT;
+
return services;
}

@@ -829,6 +832,7 @@ static void __init pcie_init_services(void)
pcie_dpc_init();
pcie_bwctrl_init();
pcie_hp_init();
+ pcie_flit_init();
}

static int __init pcie_portdrv_init(void)
diff --git a/drivers/pci/pcie/portdrv.h b/drivers/pci/pcie/portdrv.h
index 31fda7a09f0f..a342338e2bf7 100644
--- a/drivers/pci/pcie/portdrv.h
+++ b/drivers/pci/pcie/portdrv.h
@@ -22,13 +22,16 @@
#define PCIE_PORT_SERVICE_DPC (1 << PCIE_PORT_SERVICE_DPC_SHIFT)
#define PCIE_PORT_SERVICE_BWCTRL_SHIFT 4 /* Bandwidth Controller (notifications) */
#define PCIE_PORT_SERVICE_BWCTRL (1 << PCIE_PORT_SERVICE_BWCTRL_SHIFT)
+#define PCIE_PORT_SERVICE_FLIT_SHIFT 5 /* Flit Logging */
+#define PCIE_PORT_SERVICE_FLIT (1 << PCIE_PORT_SERVICE_FLIT_SHIFT)

/* Services sharing the PCI Express Capability Interrupt Message Number */
#define PCIE_PORT_SERVICES_EXPCAP (PCIE_PORT_SERVICE_PME | \
PCIE_PORT_SERVICE_HP | \
- PCIE_PORT_SERVICE_BWCTRL)
+ PCIE_PORT_SERVICE_BWCTRL | \
+ PCIE_PORT_SERVICE_FLIT)

-#define PCIE_PORT_DEVICE_MAXSERVICES 5
+#define PCIE_PORT_DEVICE_MAXSERVICES 6

#ifdef CONFIG_PCIEAER
int pcie_aer_init(void);
@@ -54,6 +57,12 @@ int pcie_dpc_init(void);
static inline int pcie_dpc_init(void) { return 0; }
#endif

+#ifdef CONFIG_PCIE_FLIT
+int pcie_flit_init(void);
+#else
+static inline int pcie_flit_init(void) { return 0; }
+#endif
+
int pcie_bwctrl_init(void);

/* Port Type */
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 9a178e0e5f7f..1fe043d4489e 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -676,6 +676,7 @@ static void pci_init_host_bridge(struct pci_host_bridge *bridge)
bridge->native_pme = port_services;
bridge->native_ltr = 1;
bridge->native_dpc = port_services;
+ bridge->native_flit = port_services;
bridge->domain_nr = PCI_DOMAIN_NR_NOT_SET;
bridge->native_cxl_error = 1;
bridge->dev.type = &pci_host_bridge_type;
@@ -2472,6 +2473,7 @@ static void pci_configure_device(struct pci_dev *dev)

static void pci_release_capabilities(struct pci_dev *dev)
{
+ pci_flit_exit(dev);
pci_aer_exit(dev);
pci_rcec_exit(dev);
pci_iov_release(dev);
@@ -2674,6 +2676,7 @@ static void pci_init_capabilities(struct pci_dev *dev)
pci_acs_init(dev); /* Access Control Services */
pci_ptm_init(dev); /* Precision Time Measurement */
pci_aer_init(dev); /* Advanced Error Reporting */
+ pci_flit_init(dev); /* Flit Logging */
pci_dpc_init(dev); /* Downstream Port Containment */
pci_rcec_init(dev); /* Root Complex Event Collector */
pci_doe_init(dev); /* Data Object Exchange */
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 9d3f039ebd94..fa9d0bfbcb82 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -667,6 +667,7 @@ extern u32 osc_sb_native_usb4_control;
#define OSC_PCI_EXPRESS_CAPABILITY_CONTROL 0x00000010
#define OSC_PCI_EXPRESS_LTR_CONTROL 0x00000020
#define OSC_PCI_EXPRESS_DPC_CONTROL 0x00000080
+#define OSC_PCI_EXPRESS_FLIT_CONTROL 0x00000800

/* CXL _OSC: Capabilities DWORD 4: Support Field */
#define OSC_CXL_1_1_PORT_REG_ACCESS_SUPPORT 0x00000001
diff --git a/include/linux/pci.h b/include/linux/pci.h
index aa3765a20a96..46cbc76edeaa 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -599,6 +599,11 @@ struct pci_dev {
u8 tph_mode; /* TPH mode */
u8 tph_req_type; /* TPH requester type */
#endif
+
+#ifdef CONFIG_PCIE_FLIT
+ u16 flit_cap; /* Flit Logging Capability offset */
+ struct flit_info *flit_info; /* Flit Logging state */
+#endif
};

static inline struct pci_dev *pci_physfn(struct pci_dev *dev)
@@ -667,6 +672,7 @@ struct pci_host_bridge {
unsigned int native_pme:1; /* OS may use PCIe PME */
unsigned int native_ltr:1; /* OS may use PCIe LTR */
unsigned int native_dpc:1; /* OS may use PCIe DPC */
+ unsigned int native_flit:1; /* OS may use PCIe Flit logging */
unsigned int native_cxl_error:1; /* OS may use CXL RAS/Events */
unsigned int preserve_config:1; /* Preserve FW resource setup */
unsigned int size_windows:1; /* Enable root bus sizing */
diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h
index facaa324bd86..73482024359b 100644
--- a/include/uapi/linux/pci_regs.h
+++ b/include/uapi/linux/pci_regs.h
@@ -763,7 +763,8 @@
#define PCI_EXT_CAP_ID_DEV3 0x2F /* Device 3 Capability/Control/Status */
#define PCI_EXT_CAP_ID_IDE 0x30 /* Integrity and Data Encryption */
#define PCI_EXT_CAP_ID_PL_64GT 0x31 /* Physical Layer 64.0 GT/s */
-#define PCI_EXT_CAP_ID_MAX PCI_EXT_CAP_ID_PL_64GT
+#define PCI_EXT_CAP_ID_FLIT 0x32 /* Flit Logging */
+#define PCI_EXT_CAP_ID_MAX PCI_EXT_CAP_ID_FLIT

#define PCI_EXT_CAP_DSN_SIZEOF 12
#define PCI_EXT_CAP_MCAST_ENDPOINT_SIZEOF 40
@@ -1187,6 +1188,22 @@
/* Physical Layer 64.0 GT/s */
#define PCI_PL_64GT_LE_CTRL 0x20 /* Lane Equalization Control Register */

+/* Flit Logging Extended Capability */
+#define PCI_FLIT_ERR_LOG1 0x04 /* Flit Error Log 1 Register */
+#define PCI_FLIT_ERR_LOG1_VALID 0x00000001 /* Flit Error Log Valid */
+#define PCI_FLIT_ERR_LOG1_MORE 0x00002000 /* More Entries Valid */
+#define PCI_FLIT_ERR_LOG1_UNRECOG 0x00004000 /* Unrecognized Flit */
+#define PCI_FLIT_ERR_LOG1_FEC_UNCOR 0x00008000 /* FEC Uncorrectable Error in Flit */
+#define PCI_FLIT_ERR_LOG1_SYND_PARITY0 0x00ff0000 /* Syndrome Parity for ECC Group 0 */
+#define PCI_FLIT_ERR_LOG1_SYND_CHECK0 0xff000000 /* Syndrome Check for ECC Group 0 */
+#define PCI_FLIT_ERR_LOG2 0x08 /* Flit Error Log 2 Register */
+#define PCI_FLIT_ERR_CNTR_CTRL 0x0c /* Flit Error Counter Control Register */
+#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_STA 0x0e /* Flit Error Counter Status Register */
+#define PCI_FLIT_ERR_CNTR_STA_INTR_GEN 0x0008 /* Interrupt Generated based on Trigger */
+
/* Native PCIe Enclosure Management */
#define PCI_NPEM_CAP 0x04 /* NPEM capability register */
#define PCI_NPEM_CAP_CAPABLE 0x00000001 /* NPEM Capable */
--
2.55.0