aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Chadd <adrian@FreeBSD.org>2020-07-15 19:34:19 +0000
committerAdrian Chadd <adrian@FreeBSD.org>2020-07-15 19:34:19 +0000
commit0155d8f69dbebb4a5fe38bd965e677fab657d24f (patch)
treef717f95072048dc09c870e7677105a47b64a26e4
parentea64ebd08c80e4c0a7b8ed207caba45e9374908e (diff)
downloadsrc-0155d8f69dbebb4a5fe38bd965e677fab657d24f.tar.gz
src-0155d8f69dbebb4a5fe38bd965e677fab657d24f.zip
[ar71xx] fix watchdog to work on subsequent SoCs
The AR9341 AHB runs at 225MHz, much faster than the 33MHz of the AR71xx AHB. So not only is the math going to do weird things, it will also wrap rather than being clamped. So: * clamp! don't wrap! * tidy up some debugging * add an option to throw an NMI rather than reset! Tested: * AR9341 SoC (TP-Link TL-WDR4300), patting/not patting the watchdog!
Notes
Notes: svn path=/head/; revision=363236
-rw-r--r--sys/mips/atheros/ar71xx_wdog.c50
1 files changed, 38 insertions, 12 deletions
diff --git a/sys/mips/atheros/ar71xx_wdog.c b/sys/mips/atheros/ar71xx_wdog.c
index 3944cbbd9a59..e752c3f85c6a 100644
--- a/sys/mips/atheros/ar71xx_wdog.c
+++ b/sys/mips/atheros/ar71xx_wdog.c
@@ -50,6 +50,7 @@ struct ar71xx_wdog_softc {
device_t dev;
int armed;
int reboot_from_watchdog;
+ int watchdog_nmi;
int debug;
};
@@ -58,32 +59,54 @@ ar71xx_wdog_watchdog_fn(void *private, u_int cmd, int *error)
{
struct ar71xx_wdog_softc *sc = private;
uint64_t timer_val;
+ int action;
+
+ action = RST_WDOG_ACTION_RESET;
+ if (sc->watchdog_nmi != 0)
+ action = RST_WDOG_ACTION_NMI;
cmd &= WD_INTERVAL;
if (sc->debug)
- device_printf(sc->dev, "ar71xx_wdog_watchdog_fn: cmd: %x\n", cmd);
+ device_printf(sc->dev, "%s: : cmd: %x\n", __func__, cmd);
if (cmd > 0) {
timer_val = (uint64_t)(1ULL << cmd) * ar71xx_ahb_freq() /
1000000000;
+
+ /*
+ * Clamp the timer value in case we overflow.
+ */
+ if (timer_val > 0xffffffff)
+ timer_val = 0xffffffff;
if (sc->debug)
- device_printf(sc->dev, "ar71xx_wdog_watchdog_fn: programming timer: %jx\n", (uintmax_t) timer_val);
+ device_printf(sc->dev, "%s: programming timer: %jx\n",
+ __func__, (uintmax_t) timer_val);
/*
- * Load timer with large enough value to prevent spurious
- * reset
+ * Make sure the watchdog is set to NOACTION and give it
+ * time to take.
*/
- ATH_WRITE_REG(AR71XX_RST_WDOG_TIMER,
- ar71xx_ahb_freq() * 10);
- ATH_WRITE_REG(AR71XX_RST_WDOG_CONTROL,
- RST_WDOG_ACTION_RESET);
- ATH_WRITE_REG(AR71XX_RST_WDOG_TIMER,
- (timer_val & 0xffffffff));
+ ATH_WRITE_REG(AR71XX_RST_WDOG_CONTROL, RST_WDOG_ACTION_NOACTION);
+ wmb();
+ DELAY(100);
+
+ /*
+ * Update the timer value. It's already clamped at this
+ * point so we don't have to wrap/clamp it here.
+ */
+ ATH_WRITE_REG(AR71XX_RST_WDOG_TIMER, timer_val);
+ wmb();
+ DELAY(100);
+
+ /*
+ * And now, arm.
+ */
+ ATH_WRITE_REG(AR71XX_RST_WDOG_CONTROL, action);
sc->armed = 1;
*error = 0;
} else {
if (sc->debug)
- device_printf(sc->dev, "ar71xx_wdog_watchdog_fn: disarming\n");
+ device_printf(sc->dev, "%s: disarming\n", __func__);
if (sc->armed) {
- ATH_WRITE_REG(AR71XX_RST_WDOG_CONTROL,
+ ATH_WRITE_REG(AR71XX_RST_WDOG_CONTROL,
RST_WDOG_ACTION_NOACTION);
sc->armed = 0;
}
@@ -110,6 +133,9 @@ ar71xx_wdog_sysctl(device_t dev)
"debug", CTLFLAG_RW, &sc->debug, 0,
"enable watchdog debugging");
SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
+ "nmi", CTLFLAG_RW, &sc->watchdog_nmi, 0,
+ "watchdog triggers NMI instead of reset");
+ SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
"armed", CTLFLAG_RD, &sc->armed, 0,
"whether the watchdog is armed");
SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,