git: 02bf7486363c - stable/15 - e1000: Recover from PCH packet buffer ECC errors

From: Kevin Bowling <kbowling_at_FreeBSD.org>
Date: Sun, 30 Aug 2026 01:09:48 UTC
The branch stable/15 has been updated by kbowling:

URL: https://cgit.FreeBSD.org/src/commit/?id=02bf7486363c33a1a8b30c9e878df831a0613c4b

commit 02bf7486363c33a1a8b30c9e878df831a0613c4b
Author:     Kevin Bowling <kbowling@FreeBSD.org>
AuthorDate: 2026-08-12 18:29:28 +0000
Commit:     Kevin Bowling <kbowling@FreeBSD.org>
CommitDate: 2026-08-30 01:09:11 +0000

    e1000: Recover from PCH packet buffer ECC errors
    
    PCH LAN controllers beginning with I217 report uncorrectable
    packet buffer ECC errors through ICR.ECCER.  Descriptor memory errors
    stop the MAC and require a reset before traffic can resume.
    
    Enable the interrupt on the PCH generations whose shared code setup
    enables packet buffer ECC.  Capture the read-clear PBECCSTS value in
    the interrupt filter, mask ECCER while recovery is pending, and request
    an iflib reset from the admin task.  Reenable the cause only after
    hardware initialization succeeds.
    
    Hardware validation used an I219-LM and the documented ICS.ECCER bit to
    generate the fatal interrupt.  This synthesizes the interrupt cause but
    does not corrupt packet buffer memory or alter its ECC byte counters.
    Three injections in one boot each requested one reset and recovered
    traffic without a panic or watchdog.  IMS.ECCER and PBECCSTS.ECC_ENABLE
    remained set after every reset.
    
    MFC after:      2 weeks
    Sponsored by:   BBOX.io
    
    (cherry picked from commit 39762c840a15e1b32b2e1acaca18d98c030f7c17)
---
 sys/dev/e1000/if_em.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++---
 sys/dev/e1000/if_em.h |   3 ++
 2 files changed, 102 insertions(+), 5 deletions(-)

diff --git a/sys/dev/e1000/if_em.c b/sys/dev/e1000/if_em.c
index bf3369a20bad..74ed1d985808 100644
--- a/sys/dev/e1000/if_em.c
+++ b/sys/dev/e1000/if_em.c
@@ -442,6 +442,9 @@ static int	em_if_rx_queue_intr_enable(if_ctx_t, uint16_t);
 static int	em_if_tx_queue_intr_enable(if_ctx_t, uint16_t);
 static int	igb_if_rx_queue_intr_enable(if_ctx_t, uint16_t);
 static int	igb_if_tx_queue_intr_enable(if_ctx_t, uint16_t);
+static void	em_handle_fatal_error_intr(struct e1000_softc *, u32);
+static bool	em_handle_fatal_error_admin(struct e1000_softc *);
+static void	em_finish_fatal_error_reset(struct e1000_softc *);
 static void	em_if_multi_set(if_ctx_t);
 static void	em_if_update_admin_status(if_ctx_t);
 static void	em_if_debug(if_ctx_t);
@@ -485,6 +488,13 @@ static void	em_disable_aspm(struct e1000_softc *);
 
 int		em_intr(void *);
 
+enum em_fatal_error_state {
+	EM_FATAL_ERROR_NONE,
+	EM_FATAL_ERROR_CAPTURING,
+	EM_FATAL_ERROR_DETECTED,
+	EM_FATAL_ERROR_RESET_REQUESTED,
+};
+
 /* MSI-X handlers */
 static int	em_if_msix_intr_assign(if_ctx_t, int);
 static int	em_msix_link(void *);
@@ -1854,6 +1864,80 @@ em_newitr(struct e1000_softc *sc, struct em_rx_queue *que,
 	}
 }
 
+static bool
+em_has_pch_ecc(const struct e1000_hw *hw)
+{
+
+	return (hw->mac.type >= e1000_pch_lpt &&
+	    hw->mac.type < e1000_82575);
+}
+
+static u32
+em_fatal_error_intr_mask(struct e1000_softc *sc)
+{
+
+	if (em_has_pch_ecc(&sc->hw) &&
+	    atomic_load_acq_32(&sc->fatal_error_state) ==
+	    EM_FATAL_ERROR_NONE)
+		return (E1000_IMS_ECCER);
+	return (0);
+}
+
+/*
+ * Descriptor-memory ECC errors stop the PCH MAC.  Capture the read-clear
+ * status before handing recovery to the iflib admin task.
+ */
+static void
+em_handle_fatal_error_intr(struct e1000_softc *sc, u32 icr)
+{
+	struct e1000_hw *hw;
+
+	if (!em_has_pch_ecc(&sc->hw) || (icr & E1000_ICR_ECCER) == 0)
+		return;
+
+	hw = &sc->hw;
+	E1000_WRITE_REG(hw, E1000_IMC, E1000_IMS_ECCER);
+	if (!atomic_cmpset_32(&sc->fatal_error_state,
+	    EM_FATAL_ERROR_NONE, EM_FATAL_ERROR_CAPTURING))
+		return;
+
+	sc->fatal_error_pbeccsts = E1000_READ_REG(hw, E1000_PBECCSTS);
+	atomic_store_rel_32(&sc->fatal_error_state,
+	    EM_FATAL_ERROR_DETECTED);
+	iflib_admin_intr_deferred(sc->ctx);
+}
+
+static bool
+em_handle_fatal_error_admin(struct e1000_softc *sc)
+{
+
+	if (!atomic_cmpset_acq_32(&sc->fatal_error_state,
+	    EM_FATAL_ERROR_DETECTED, EM_FATAL_ERROR_RESET_REQUESTED))
+		return (atomic_load_acq_32(&sc->fatal_error_state) !=
+		    EM_FATAL_ERROR_NONE);
+
+	device_printf(sc->dev,
+	    "uncorrectable packet-buffer ECC error: PBECCSTS %#x; "
+	    "requesting reset\n", sc->fatal_error_pbeccsts);
+	sc->fatal_error_reset_count++;
+	iflib_request_reset(sc->ctx);
+	/* Re-enter the admin task so it observes the reset request. */
+	iflib_admin_intr_deferred(sc->ctx);
+	return (true);
+}
+
+static void
+em_finish_fatal_error_reset(struct e1000_softc *sc)
+{
+
+	if (atomic_load_acq_32(&sc->fatal_error_state) ==
+	    EM_FATAL_ERROR_NONE)
+		return;
+
+	sc->fatal_error_pbeccsts = 0;
+	atomic_store_rel_32(&sc->fatal_error_state, EM_FATAL_ERROR_NONE);
+}
+
 /*********************************************************************
  *
  *  Fast Legacy/MSI Combined Interrupt Service routine
@@ -1902,6 +1986,8 @@ em_intr(void *arg)
 	if (reg_icr & E1000_ICR_RXO)
 		sc->rx_overruns++;
 
+	em_handle_fatal_error_intr(sc, reg_icr);
+
 	if (hw->mac.type >= e1000_82540)
 		em_newitr(sc, que, rxr);
 
@@ -1987,10 +2073,12 @@ em_msix_link(void *arg)
 
 	if (reg_icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))
 		em_handle_link(sc->ctx);
+	em_handle_fatal_error_intr(sc, reg_icr);
 
 	/* Re-arm unconditionally */
 	if (sc->hw.mac.type >= igb_mac_min) {
-		E1000_WRITE_REG(&sc->hw, E1000_IMS, E1000_IMS_LSC);
+		E1000_WRITE_REG(&sc->hw, E1000_IMS,
+		    E1000_IMS_LSC | em_fatal_error_intr_mask(sc));
 		E1000_WRITE_REG(&sc->hw, E1000_EIMS, sc->link_mask);
 	} else if (sc->hw.mac.type == e1000_82574) {
 		E1000_WRITE_REG(&sc->hw, E1000_IMS,
@@ -2003,7 +2091,8 @@ em_msix_link(void *arg)
 		if (reg_icr)
 			E1000_WRITE_REG(&sc->hw, E1000_ICS, sc->ims);
 	} else
-		E1000_WRITE_REG(&sc->hw, E1000_IMS, E1000_IMS_LSC);
+		E1000_WRITE_REG(&sc->hw, E1000_IMS,
+		    E1000_IMS_LSC | em_fatal_error_intr_mask(sc));
 
 	return (FILTER_HANDLED);
 }
@@ -2260,6 +2349,8 @@ em_if_update_admin_status(if_ctx_t ctx)
 	u32 link_check, thstat, ctrl;
 	bool reset_requested = false;
 
+	if (em_handle_fatal_error_admin(sc))
+		return;
 	link_check = thstat = ctrl = 0;
 	/* Get the cached link value or read phy for real */
 	switch (hw->phy.media_type) {
@@ -3358,6 +3449,7 @@ em_reset(if_ctx_t ctx)
 		device_printf(dev, "Hardware Initialization Failed\n");
 		return;
 	}
+	em_finish_fatal_error_reset(sc);
 	if (hw->mac.type >= igb_mac_min)
 		igb_init_dmac(sc, pba);
 
@@ -4442,7 +4534,7 @@ em_if_intr_enable(if_ctx_t ctx)
 {
 	struct e1000_softc *sc = iflib_get_softc(ctx);
 	struct e1000_hw *hw = &sc->hw;
-	u32 ims_mask = IMS_ENABLE_MASK;
+	u32 ims_mask = IMS_ENABLE_MASK | em_fatal_error_intr_mask(sc);
 
 	if (sc->intr_type == IFLIB_INTR_MSIX) {
 		E1000_WRITE_REG(hw, EM_EIAC, sc->ims);
@@ -4477,9 +4569,11 @@ igb_if_intr_enable(if_ctx_t ctx)
 		E1000_WRITE_REG(hw, E1000_EIAC, mask);
 		E1000_WRITE_REG(hw, E1000_EIAM, mask);
 		E1000_WRITE_REG(hw, E1000_EIMS, mask);
-		E1000_WRITE_REG(hw, E1000_IMS, E1000_IMS_LSC);
+		E1000_WRITE_REG(hw, E1000_IMS,
+		    E1000_IMS_LSC | em_fatal_error_intr_mask(sc));
 	} else
-		E1000_WRITE_REG(hw, E1000_IMS, IMS_ENABLE_MASK);
+		E1000_WRITE_REG(hw, E1000_IMS,
+		    IMS_ENABLE_MASK | em_fatal_error_intr_mask(sc));
 	E1000_WRITE_FLUSH(hw);
 }
 
diff --git a/sys/dev/e1000/if_em.h b/sys/dev/e1000/if_em.h
index 6237639bd5a5..47acdd9ed8d5 100644
--- a/sys/dev/e1000/if_em.h
+++ b/sys/dev/e1000/if_em.h
@@ -618,6 +618,9 @@ struct e1000_softc {
 	u32			pba;
 	int			link_mask;
 	int			tso_automasked;
+	u32			fatal_error_state;
+	u32			fatal_error_pbeccsts;
+	u64			fatal_error_reset_count;
 
 	u64			que_mask;