diff mbox series

[SRU,J:linux-bluefield,2/2] UBUNTU: SAUCE: mlxbf_gige: disable MAC after kernel panic

Message ID eebd918ff05f9fb61c11972ef02a234ce4cdfd86.1793296507.git.cbabroski@nvidia.com
State New
Headers show
Series mlxbf_gige: disable MAC after panic | expand

Commit Message

Chris Babroski Oct. 30, 2026, 6:36 p.m. UTC
BugLink: https://bugs.launchpad.net/bugs/2172611

After a kernel panic the MAC continues to receive packets into the RX
FIFO even though the driver can no longer process them. By default, the
MAC HW is designed to repeatedly send pause frames to its link partner
when the RX FIFO is full. The internal Ethernet switch on BlueField that
is connected to this port is also designed to stop traffic on all ports
when it receives a high number of continuous pause frames from one of
the ports.

What this means is that when the kernel panics on BlueField, it is
possible to reproduce a scenario under steady and high network load
where the network becomes inaccessible for other devices connected to
the 3-port switch, namely the OOB host and DPU-BMC.

Register a panic notifier at highest priority that disables MAC RX and
clears the RX FIFO to ensure that the MAC can no longer receive packets
or send pause frames.

Before v6.5, readq_poll_timeout_atomic() measures its timeout with
ktime_get(). That can spin forever in panic context if the timekeeping
seqcount was held for writing when the panic occurred, which would
prevent the clean port sequence from completing and hang the panic. Add
mlxbf_gige_readq_poll_timeout_atomic(), which counts the timeout down
locally on older kernels, and use it to poll for clean port completion.

Signed-off-by: Chris Babroski <cbabroski@nvidia.com>
---
 .../ethernet/mellanox/mlxbf_gige/mlxbf_gige.h |  2 +
 .../mellanox/mlxbf_gige/mlxbf_gige_main.c     | 68 +++++++++++++++++--
 2 files changed, 65 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige.h b/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige.h
index 12e391f86bfa..9d1cf9f40bd9 100644
--- a/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige.h
+++ b/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige.h
@@ -13,6 +13,7 @@ 
 #include <linux/io-64-nonatomic-lo-hi.h>
 #include <linux/irqreturn.h>
 #include <linux/netdevice.h>
+#include <linux/notifier.h>
 #include <linux/irq.h>
 #include <linux/phy.h>
 
@@ -135,6 +136,7 @@  struct mlxbf_gige {
 	struct timer_list media_timer;
 	struct work_struct phy_task;
 	u8 aneg_timeout;
+	struct notifier_block panic_nb;
 };
 
 /* BF2 autoneg takes 3-10 secs, set timeout to 50% over max */
diff --git a/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c b/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c
index 46963234c30e..02718ebf2b40 100644
--- a/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c
+++ b/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c
@@ -8,12 +8,13 @@ 
 #define DEBUG
 
 #include <linux/acpi.h>
+#include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/dma-mapping.h>
 #include <linux/etherdevice.h>
 #include <linux/interrupt.h>
-#include <linux/iopoll.h>
 #include <linux/module.h>
+#include <linux/panic_notifier.h>
 #include <linux/phy.h>
 #include <linux/phy_fixed.h>
 #include <linux/platform_device.h>
@@ -113,10 +114,29 @@  static void mlxbf_gige_cache_stats(struct mlxbf_gige *priv)
 					   MLXBF_GIGE_RX_DISC_COUNTER_ALL);
 }
 
+/* Poll until any bit in @mask is set. readq_poll_timeout_atomic()
+ * measures its timeout with ktime_get() on this kernel, which can spin
+ * forever if called during a panic, so count the timeout down locally.
+ */
+static int mlxbf_gige_readq_poll_timeout_atomic(void __iomem *addr, u64 mask,
+						unsigned long delay_us,
+						unsigned long timeout_us)
+{
+	long left_us = timeout_us;
+
+	while (!(readq(addr) & mask)) {
+		if (left_us <= 0)
+			return -ETIMEDOUT;
+		udelay(delay_us);
+		left_us -= delay_us;
+	}
+
+	return 0;
+}
+
 static int mlxbf_gige_clean_port(struct mlxbf_gige *priv)
 {
 	u64 control;
-	u64 temp;
 	int err;
 
 	/* Set the CLEAN_PORT_EN bit to trigger SW reset */
@@ -127,9 +147,9 @@  static int mlxbf_gige_clean_port(struct mlxbf_gige *priv)
 	/* Ensure completion of "clean port" write before polling status */
 	mb();
 
-	err = readq_poll_timeout_atomic(priv->base + MLXBF_GIGE_STATUS, temp,
-					(temp & MLXBF_GIGE_STATUS_READY),
-					100, 100000);
+	err = mlxbf_gige_readq_poll_timeout_atomic(priv->base + MLXBF_GIGE_STATUS,
+						   MLXBF_GIGE_STATUS_READY,
+						   100, 100000);
 
 	/* Clear the CLEAN_PORT_EN bit at end of this loop */
 	control = readq(priv->base + MLXBF_GIGE_CONTROL);
@@ -139,6 +159,27 @@  static int mlxbf_gige_clean_port(struct mlxbf_gige *priv)
 	return err;
 }
 
+static void mlxbf_gige_disable_port(struct mlxbf_gige *priv)
+{
+	u64 control;
+
+	/* Disable RX DMA */
+	control = readq(priv->base + MLXBF_GIGE_RX_DMA);
+	control &= ~MLXBF_GIGE_RX_DMA_EN;
+	writeq(control, priv->base + MLXBF_GIGE_RX_DMA);
+
+	/* Disable port */
+	control = readq(priv->base + MLXBF_GIGE_CONTROL);
+	control &= ~MLXBF_GIGE_CONTROL_PORT_EN;
+	writeq(control, priv->base + MLXBF_GIGE_CONTROL);
+
+	/* Disable interrupts */
+	writeq(0, priv->base + MLXBF_GIGE_INT_EN);
+
+	/* Ensure completion of disable writes before cleaning the port */
+	mb();
+}
+
 static void mlxbf_gige_phy_task(struct work_struct *work)
 {
 	struct mlxbf_gige *priv = container_of(work, struct mlxbf_gige, phy_task);
@@ -487,6 +528,17 @@  static struct mlxbf_gige_link_cfg mlxbf_gige_link_cfgs[] = {
 	}
 };
 
+static int mlxbf_gige_on_panic(struct notifier_block *nb,
+			       unsigned long action, void *data)
+{
+	struct mlxbf_gige *priv;
+
+	priv = container_of(nb, struct mlxbf_gige, panic_nb);
+	mlxbf_gige_disable_port(priv);
+	mlxbf_gige_clean_port(priv);
+	return NOTIFY_DONE;
+}
+
 static int mlxbf_gige_probe(struct platform_device *pdev)
 {
 	struct fixed_phy_status fphy_status = {};
@@ -557,6 +609,10 @@  static int mlxbf_gige_probe(struct platform_device *pdev)
 	/* Write initial MAC address to hardware */
 	mlxbf_gige_initial_mac(priv);
 
+	priv->panic_nb.priority = INT_MAX;
+	priv->panic_nb.notifier_call = mlxbf_gige_on_panic;
+	atomic_notifier_chain_register(&panic_notifier_list, &priv->panic_nb);
+
 	err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
 	if (err) {
 		dev_err(&pdev->dev, "DMA configuration failed: 0x%x\n", err);
@@ -645,6 +701,7 @@  static int mlxbf_gige_probe(struct platform_device *pdev)
 	return 0;
 
 out:
+	atomic_notifier_chain_unregister(&panic_notifier_list, &priv->panic_nb);
 	mlxbf_gige_mdio_remove(priv);
 	return err;
 }
@@ -656,6 +713,7 @@  static int mlxbf_gige_remove(struct platform_device *pdev)
 
 	unregister_netdev(priv->netdev);
 	phy_disconnect(phydev);
+	atomic_notifier_chain_unregister(&panic_notifier_list, &priv->panic_nb);
 
 	if (phy_is_pseudo_fixed_link(phydev))
 		fixed_phy_unregister(phydev);