Page MenuHomeFreeBSD

D61968.1795976177.diff
No OneTemporary

Authored By
Unknown
Size
14 KB
Referenced Files
None
Subscribers
None

D61968.1795976177.diff

diff --git a/sys/powerpc/powernv/opal.h b/sys/powerpc/powernv/opal.h
--- a/sys/powerpc/powernv/opal.h
+++ b/sys/powerpc/powernv/opal.h
@@ -71,6 +71,7 @@
#define OPAL_START_CPU 41
#define OPAL_PCI_MAP_PE_DMA_WINDOW 44
#define OPAL_PCI_MAP_PE_DMA_WINDOW_REAL 45
+#define OPAL_PCI_NEXT_ERROR 60
#define OPAL_RETURN_CPU 69
#define OPAL_REINIT_CPUS 70
#define OPAL_CHECK_TOKEN 80
@@ -133,6 +134,21 @@
#define OPAL_PCI_TCE_KILL_PE 1
#define OPAL_PCI_TCE_KILL_ALL 2
+/* For OPAL_PCI_NEXT_ERROR */
+#define OPAL_EEH_NO_ERROR 0
+#define OPAL_EEH_IOC_ERROR 1
+#define OPAL_EEH_PHB_ERROR 2
+#define OPAL_EEH_PE_ERROR 3
+#define OPAL_EEH_PE_MMIO_ERROR 4
+#define OPAL_EEH_PE_DMA_ERROR 5
+
+#define OPAL_EEH_SEV_NO_ERROR 0
+#define OPAL_EEH_SEV_IOC_DEAD 1
+#define OPAL_EEH_SEV_PHB_DEAD 2
+#define OPAL_EEH_SEV_PHB_FENCED 3
+#define OPAL_EEH_SEV_PE_ER 4
+#define OPAL_EEH_SEV_INF 5
+
#define OPAL_SUCCESS 0
#define OPAL_PARAMETER -1
#define OPAL_BUSY -2
@@ -205,6 +221,12 @@
#define OPAL_IODA_INVALID_PE 0xffffffff
+#define OPAL_P7IOC_NUM_PEST_REGS 128
+#define OPAL_PHB3_NUM_PEST_REGS 256
+#define OPAL_PHB4_NUM_PEST_REGS 512
+
+#define OPAL_PNV_PCI_DIAG_BUF_SIZE (4096*8)
+
struct opal_msg {
uint32_t msg_type;
uint32_t reserved;
diff --git a/sys/powerpc/powernv/opal_dev.c b/sys/powerpc/powernv/opal_dev.c
--- a/sys/powerpc/powernv/opal_dev.c
+++ b/sys/powerpc/powernv/opal_dev.c
@@ -1,5 +1,6 @@
/*-
* Copyright (c) 2015 Nathan Whitehorn
+ * Copyright (c) 2025-2026 Raptor Engineering, LLC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -47,6 +48,7 @@
#include "clock_if.h"
#include "opal.h"
+#include "opal_pci.h"
static int opaldev_probe(device_t);
static int opaldev_attach(device_t);
@@ -95,6 +97,7 @@
static void opal_heartbeat(void);
static void opal_handle_messages(void);
+static void opal_handle_phb_error(void);
static struct proc *opal_hb_proc;
static struct kproc_desc opal_heartbeat_kp = {
@@ -131,6 +134,8 @@
opal_call(OPAL_POLL_EVENTS, vtophys(&events));
if (be64toh(events) & OPAL_EVENT_MSG_PENDING)
opal_handle_messages();
+ if (be64toh(events) & OPAL_EVENT_PCI_ERROR)
+ opal_handle_phb_error();
tsleep(opal_hb_proc, 0, "opal",
MSEC_2_TICKS(opal_heartbeat_ms));
}
@@ -421,6 +426,38 @@
}
}
+static void
+opal_handle_phb_error(void)
+{
+ device_t *pcibs;
+ device_t phb;
+ device_t root_phb;
+ int i, error, num_pcibs;
+
+ error = devclass_get_devices(devclass_find("pcib"), &pcibs,
+ &num_pcibs);
+ if (error != 0)
+ return;
+
+ for (i = 0; i < num_pcibs; i++) {
+ /* Find root PHB for bus */
+ root_phb = NULL;
+ phb = device_get_parent(pcibs[i]);
+ while (phb != NULL) {
+ if (strcmp(device_get_name(phb), "pcib") == 0)
+ root_phb = phb;
+
+ phb = device_get_parent(phb);
+ }
+ if (root_phb == NULL)
+ continue;
+
+ /* Dump PHB error log and clear associated message buffer */
+ opalpci_dump_error(root_phb);
+ }
+ free(pcibs, M_TEMP);
+}
+
static void
opal_intr(void *xintr)
{
diff --git a/sys/powerpc/powernv/opal_pci.h b/sys/powerpc/powernv/opal_pci.h
--- a/sys/powerpc/powernv/opal_pci.h
+++ b/sys/powerpc/powernv/opal_pci.h
@@ -42,6 +42,84 @@
#define POWERNV_FW_PAGE_SHIFT 16
#define POWERNV_INVALID_DEVFN 0xffffffff
+/* Indicates a PE is frozen (MMIO flag set in PESTA & DMA flag set in PESTB) */
+#define POWERNV_IODA_STOPPED_STATE 0x8000000000000000
+
+struct opalpci_phb_error_common {
+ uint32_t version;
+ uint32_t io_type;
+ uint32_t length;
+};
+
+struct opalpci_phb4_error_state {
+ struct opalpci_phb_error_common common;
+
+ uint32_t bridge_control;
+
+ /* PHB4 configuration registers */
+ uint32_t device_status;
+ uint32_t slot_status;
+ uint32_t link_status;
+ uint32_t dev_command_status;
+ uint32_t dev_sec_status;
+
+ /* AER registers */
+ uint32_t root_error_status;
+ uint32_t uncorr_error_status;
+ uint32_t corr_error_status;
+ uint32_t tlp_header1;
+ uint32_t tlp_header2;
+ uint32_t tlp_header3;
+ uint32_t tlp_header4;
+ uint32_t source_id;
+
+ /* PHB4 ETU error registers */
+ uint64_t n_fir;
+ uint64_t n_fir_mask;
+ uint64_t n_fir_wof;
+ uint64_t phb_plssr;
+ uint64_t phb_csr;
+ uint64_t lemFir;
+ uint64_t lemErrorMask;
+ uint64_t lemWOF;
+ uint64_t phb_error_status;
+ uint64_t phb_first_error_status;
+ uint64_t phb_error_log0;
+ uint64_t phb_error_log1;
+ uint64_t phb_txe_error_status;
+ uint64_t phb_txe_First_error_status;
+ uint64_t phb_txe_error_log0;
+ uint64_t phb_txe_error_log1;
+ uint64_t phb_rxe_arb__error_status;
+ uint64_t phb_rxe_arb_First_error_status;
+ uint64_t phb_rxe_arb_error_log0;
+ uint64_t phb_rxe_arb_error_log1;
+ uint64_t phb_rxe_merge_error_status;
+ uint64_t phb_rxe_merge_first_error_status;
+ uint64_t phb_rxe_merge_error_log0;
+ uint64_t phb_rxe_merge_error_log1;
+ uint64_t phb_rxe_tce_error_status;
+ uint64_t phb_rxe_tce_first_error_status;
+ uint64_t phb_rxe_tce_error_log0;
+ uint64_t phb_rxe_tce_error_log1;
+
+ /* PHB4 REGB error registers */
+ uint64_t phb_pbl_error_status;
+ uint64_t phb_pblFirst_error_status;
+ uint64_t phb_pblerror_log0;
+ uint64_t phb_pblerror_log1;
+ uint64_t phb_pcie_dlp_error_log1;
+ uint64_t phb_pcie_dlp_error_log2;
+ uint64_t phb_pcie_dlp_error_status;
+ uint64_t phb_reg_b_error_status;
+ uint64_t phb_reg_b_first_error_status;
+ uint64_t phb_reg_b_error_log0;
+ uint64_t phb_reg_b_error_log1;
+
+ uint64_t pest_a[OPAL_PHB4_NUM_PEST_REGS];
+ uint64_t pest_b[OPAL_PHB4_NUM_PEST_REGS];
+};
+
/*
* The content of the TVT itself is read by hardware (cached into the PHB);
* all other fields are used by the kernel. Note that the TVT contents
@@ -146,6 +224,8 @@
uint64_t m64_window_size;
uint64_t m64_segment_size;
+ uint8_t *phb_errlog; /* PHB error log buffer */
+
/* linked list storing PCI device to PE mappings */
LIST_HEAD(phb_drc_list, phb_drc_list_entry) pe_drc_list;
LIST_HEAD(phb_pe_map_list, phb_pe_map_entry) pe_map_list;
@@ -178,4 +258,6 @@
int opalpci_ioda2_clear_iommu_window(device_t phb, uint64_t pe,
int window_number, struct powernv_ioda_tvt * tvt);
+void opalpci_dump_error(device_t phb);
+
#endif /* _POWERNV_OPAL_PCI_H_ */
\ No newline at end of file
diff --git a/sys/powerpc/powernv/opal_pci.c b/sys/powerpc/powernv/opal_pci.c
--- a/sys/powerpc/powernv/opal_pci.c
+++ b/sys/powerpc/powernv/opal_pci.c
@@ -870,6 +870,10 @@
return (ENXIO);
}
+ /* Allocate space for PHB error log */
+ sc->phb_errlog = malloc(OPAL_PNV_PCI_DIAG_BUF_SIZE,
+ M_OPALPCI_PHB, M_WAITOK | M_ZERO);
+
/*
* Root bus number is fixed at 0 on PHB3/PHB4 systems
* (and possibly others)
@@ -984,7 +988,6 @@
opal_call(OPAL_PCI_EEH_FREEZE_CLEAR, sc->phb_id, sc->reserved_pe_id,
OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);
-
/* Inform the PCI core about the 64-bit memory window on the PHB */
if (sc->m64_window_present) {
struct ofw_pci_range *rp;
@@ -1066,7 +1069,6 @@
* Poking config state for non-existant devices can make
* the host bridge hang up. Clear any errors.
*/
-
if (error != OPAL_SUCCESS ||
(word == ((1UL << (8 * width)) - 1))) {
if (error != OPAL_HARDWARE) {
@@ -1074,10 +1076,11 @@
sc->reserved_pe_id, vtophys(&eeh_state),
vtophys(&err_type), NULL);
err_type = be16toh(err_type); /* XXX unused */
- if (eeh_state != OPAL_EEH_STOPPED_NOT_FROZEN)
+ if (eeh_state != OPAL_EEH_STOPPED_NOT_FROZEN) {
opal_call(OPAL_PCI_EEH_FREEZE_CLEAR,
sc->phb_id, sc->reserved_pe_id,
OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);
+ }
}
if (error != OPAL_SUCCESS)
word = 0xffffffff;
@@ -1259,6 +1262,216 @@
return 0;
}
+/*
+ * Print the contents of the PE State Tables (PEST) in standard format
+ * The output intentionally matches Linux, typos and unusual syntax included,
+ * to allow existing decoder tools to work without modification.
+ */
+static void
+opalpci_dump_pest(device_t phb, uint64_t pest_a[], uint64_t pest_b[],
+ int pest_size)
+{
+ uint64_t prevA, prevB;
+ bool duplicate;
+ int i;
+
+ prevA = ULONG_MAX;
+ prevB = ULONG_MAX;
+ duplicate = false;
+
+ for (i = 0; i < pest_size; i++) {
+ uint64_t peA = be64toh(pest_a[i]);
+ uint64_t peB = be64toh(pest_b[i]);
+
+ if (peA != prevA || peB != prevB) {
+ if (duplicate) {
+ device_printf(phb, "PE[..%03x] A/B: as above\n",
+ i-1);
+ duplicate = false;
+ }
+ prevA = peA;
+ prevB = peB;
+ if (peA & POWERNV_IODA_STOPPED_STATE ||
+ peB & POWERNV_IODA_STOPPED_STATE)
+ device_printf(phb,
+ "PE[%03x] A/B: %016lx %016lx\n",
+ i, peA, peB);
+ } else if (!duplicate &&
+ (peA & POWERNV_IODA_STOPPED_STATE ||
+ peB & POWERNV_IODA_STOPPED_STATE)) {
+ duplicate = true;
+ }
+ }
+}
+
+/*
+ * Print the PHB4 diagnostic tables in standard format
+ * The output intentionally matches Linux, typos and unusual syntax included,
+ * to allow existing decoder tools to work without modification.
+ */
+static void
+opalpci_dump_phb4_diag_data(device_t phb,
+ struct opalpci_phb_error_common *common)
+{
+ struct opalpci_phb4_error_state *data;
+ struct opalpci_softc *phb_sc;
+
+ phb_sc = device_get_softc(phb);
+
+ data = (struct opalpci_phb4_error_state*)common;
+ device_printf(phb, "PHB4 PHB#%ld Diag-data (Version: %d)\n",
+ phb_sc->phb_id,
+ be32toh(common->version));
+ if (data->bridge_control)
+ device_printf(phb, "brdgCtl: %08x\n",
+ be32toh(data->bridge_control));
+ if (data->device_status || data->slot_status || data->link_status
+ || data->dev_command_status || data->dev_sec_status)
+ device_printf(phb, "RootSts: %08x %08x %08x %08x %08x\n",
+ be32toh(data->device_status),
+ be32toh(data->slot_status),
+ be32toh(data->link_status),
+ be32toh(data->dev_command_status),
+ be32toh(data->dev_sec_status));
+ if (data->root_error_status || data->uncorr_error_status ||
+ data->corr_error_status)
+ device_printf(phb, "RootErrSts: %08x %08x %08x\n",
+ be32toh(data->root_error_status),
+ be32toh(data->uncorr_error_status),
+ be32toh(data->corr_error_status));
+ if (data->tlp_header1 || data->tlp_header2 || data->tlp_header3
+ || data->tlp_header4)
+ device_printf(phb, "RootErrLog: %08x %08x %08x %08x\n",
+ be32toh(data->tlp_header1),
+ be32toh(data->tlp_header2),
+ be32toh(data->tlp_header3),
+ be32toh(data->tlp_header4));
+ if (data->source_id)
+ device_printf(phb, "sourceId: %08x\n",
+ be32toh(data->source_id));
+ if (data->n_fir)
+ device_printf(phb, "nFir: %016lx %016lx %016lx\n",
+ be64toh(data->n_fir),
+ be64toh(data->n_fir_mask),
+ be64toh(data->n_fir_wof));
+ if (data->phb_plssr || data->phb_csr)
+ device_printf(phb, "PhbSts: %016lx %016lx\n",
+ be64toh(data->phb_plssr),
+ be64toh(data->phb_csr));
+ if (data->lemFir)
+ device_printf(phb, "Lem: %016lx %016lx %016lx\n",
+ be64toh(data->lemFir),
+ be64toh(data->lemErrorMask),
+ be64toh(data->lemWOF));
+ if (data->phb_error_status)
+ device_printf(phb, "PhbErr: %016lx %016lx %016lx %016lx\n",
+ be64toh(data->phb_error_status),
+ be64toh(data->phb_first_error_status),
+ be64toh(data->phb_error_log0),
+ be64toh(data->phb_error_log1));
+ if (data->phb_txe_error_status)
+ device_printf(phb, "PhbTxeErr: %016lx %016lx %016lx %016lx\n",
+ be64toh(data->phb_txe_error_status),
+ be64toh(data->phb_txe_First_error_status),
+ be64toh(data->phb_txe_error_log0),
+ be64toh(data->phb_txe_error_log1));
+ if (data->phb_rxe_arb__error_status)
+ device_printf(phb, "RxeArbErr: %016lx %016lx %016lx %016lx\n",
+ be64toh(data->phb_rxe_arb__error_status),
+ be64toh(data->phb_rxe_arb_First_error_status),
+ be64toh(data->phb_rxe_arb_error_log0),
+ be64toh(data->phb_rxe_arb_error_log1));
+ if (data->phb_rxe_merge_error_status)
+ device_printf(phb, "RxeMrgErr: %016lx %016lx %016lx %016lx\n",
+ be64toh(data->phb_rxe_merge_error_status),
+ be64toh(data->phb_rxe_merge_first_error_status),
+ be64toh(data->phb_rxe_merge_error_log0),
+ be64toh(data->phb_rxe_merge_error_log1));
+ if (data->phb_rxe_tce_error_status)
+ device_printf(phb, "RxeTceErr: %016lx %016lx %016lx %016lx\n",
+ be64toh(data->phb_rxe_tce_error_status),
+ be64toh(data->phb_rxe_tce_first_error_status),
+ be64toh(data->phb_rxe_tce_error_log0),
+ be64toh(data->phb_rxe_tce_error_log1));
+
+ if (data->phb_pbl_error_status)
+ device_printf(phb, "PblErr: %016lx %016lx %016lx %016lx\n",
+ be64toh(data->phb_pbl_error_status),
+ be64toh(data->phb_pblFirst_error_status),
+ be64toh(data->phb_pblerror_log0),
+ be64toh(data->phb_pblerror_log1));
+ if (data->phb_pcie_dlp_error_status)
+ device_printf(phb, "PcieDlp: %016lx %016lx %016lx\n",
+ be64toh(data->phb_pcie_dlp_error_log1),
+ be64toh(data->phb_pcie_dlp_error_log2),
+ be64toh(data->phb_pcie_dlp_error_status));
+ if (data->phb_reg_b_error_status)
+ device_printf(phb, "RegbErr: %016lx %016lx %016lx %016lx\n",
+ be64toh(data->phb_reg_b_error_status),
+ be64toh(data->phb_reg_b_first_error_status),
+ be64toh(data->phb_reg_b_error_log0),
+ be64toh(data->phb_reg_b_error_log1));
+
+ opalpci_dump_pest(phb, data->pest_a, data->pest_b,
+ OPAL_PHB4_NUM_PEST_REGS);
+}
+
+void
+opalpci_dump_error(device_t phb)
+{
+ struct opalpci_softc *phb_sc;
+ int err;
+ uint64_t first_frozen_pe;
+ uint16_t pci_error_type;
+ uint16_t error_severity;
+ struct opalpci_phb_error_common *common;
+
+ phb_sc = device_get_softc(phb);
+
+ err = opal_call(OPAL_PCI_NEXT_ERROR, phb_sc->phb_id,
+ vtophys(&first_frozen_pe), vtophys(&pci_error_type),
+ vtophys(&error_severity));
+
+ if (err == OPAL_SUCCESS) {
+ /* Check if PHB actually has an error log pending */
+ if ((be16toh(pci_error_type) == OPAL_EEH_NO_ERROR)
+ || (be16toh(error_severity) == OPAL_EEH_SEV_NO_ERROR))
+ return;
+
+ if (first_frozen_pe == be64toh(0xffffffffffffffff))
+ device_printf(phb,
+ "Found PCI error set on unknown PE, retreiving "
+ "PHB error log from OPAL\n");
+ else
+ device_printf(phb,
+ "Found PCI error set on PE#%02lx, retreiving "
+ "PHB error log from OPAL\n",
+ be64toh(first_frozen_pe));
+
+ err = opal_call(OPAL_PCI_GET_PHB_DIAG_DATA2,
+ phb_sc->phb_id, vtophys(phb_sc->phb_errlog),
+ OPAL_PNV_PCI_DIAG_BUF_SIZE);
+ }
+
+ if (err == OPAL_SUCCESS) {
+ device_printf(phb,
+ "Retrieved PHB error log from OPAL, dumping...\n");
+ common = (struct opalpci_phb_error_common *)phb_sc->phb_errlog;
+ if (ofw_bus_is_compatible(phb, "ibm,ioda3-phb")) {
+ opalpci_dump_phb4_diag_data(phb, common);
+ }
+ else {
+ device_printf(phb,
+ "Don't know how to dump error log, aborting\n");
+ }
+ } else {
+ device_printf(phb, "Error log fetch failed: %d\n", err);
+ }
+
+ /* Ask user to send report! */
+ printf("%s: PHB error detected. Please file a bug report.\n", __func__);
+}
+
static int
opalpci_associate_pe_to_bus(device_t phb, device_t child, uint64_t pe,
rman_res_t start, rman_res_t end)

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 29, 6:16 PM (12 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42094077
Default Alt Text
D61968.1795976177.diff (14 KB)

Event Timeline