]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/watchdog/softdog.c
netfilter: remove nf_ct_is_untracked
[mirror_ubuntu-artful-kernel.git] / drivers / watchdog / softdog.c
CommitLineData
1da177e4 1/*
a5132caf 2 * SoftDog: A Software Watchdog Device
1da177e4 3 *
143a2e54
WVS
4 * (c) Copyright 1996 Alan Cox <alan@lxorguk.ukuu.org.uk>,
5 * All Rights Reserved.
1da177e4
LT
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 * Neither Alan Cox nor CymruNet Ltd. admit liability nor provide
13 * warranty for any of this software. This material is provided
14 * "AS-IS" and at no charge.
15 *
16 * (c) Copyright 1995 Alan Cox <alan@lxorguk.ukuu.org.uk>
17 *
18 * Software only watchdog driver. Unlike its big brother the WDT501P
19 * driver this won't always recover a failed machine.
1da177e4
LT
20 */
21
27c766aa
JP
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
8d5755b3 24#include <linux/hrtimer.h>
e65c5825 25#include <linux/init.h>
e65c5825 26#include <linux/kernel.h>
1da177e4
LT
27#include <linux/module.h>
28#include <linux/moduleparam.h>
e65c5825 29#include <linux/reboot.h>
e65c5825 30#include <linux/types.h>
1da177e4 31#include <linux/watchdog.h>
1da177e4 32
1da177e4 33#define TIMER_MARGIN 60 /* Default is 60 seconds */
a5132caf
AC
34static unsigned int soft_margin = TIMER_MARGIN; /* in seconds */
35module_param(soft_margin, uint, 0);
f92d3749
AC
36MODULE_PARM_DESC(soft_margin,
37 "Watchdog soft_margin in seconds. (0 < soft_margin < 65536, default="
38 __MODULE_STRING(TIMER_MARGIN) ")");
1da177e4 39
86a1e189
WVS
40static bool nowayout = WATCHDOG_NOWAYOUT;
41module_param(nowayout, bool, 0);
f92d3749
AC
42MODULE_PARM_DESC(nowayout,
43 "Watchdog cannot be stopped once started (default="
44 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
1da177e4 45
5f5e1909 46static int soft_noboot;
1da177e4 47module_param(soft_noboot, int, 0);
a77dba7e 48MODULE_PARM_DESC(soft_noboot,
a5132caf 49 "Softdog action, set to 1 to ignore reboots, 0 to reboot (default=0)");
1da177e4 50
7fff4beb
AJ
51static int soft_panic;
52module_param(soft_panic, int, 0);
53MODULE_PARM_DESC(soft_panic,
54 "Softdog action, set to 1 to panic, 0 to reboot (default=0)");
55
8d5755b3
NC
56static struct hrtimer softdog_ticktock;
57static struct hrtimer softdog_preticktock;
58
59static enum hrtimer_restart softdog_fire(struct hrtimer *timer)
1da177e4 60{
5889f06b 61 module_put(THIS_MODULE);
4a23e2bf 62 if (soft_noboot) {
27c766aa 63 pr_crit("Triggered - Reboot ignored\n");
4a23e2bf 64 } else if (soft_panic) {
27c766aa
JP
65 pr_crit("Initiating panic\n");
66 panic("Software Watchdog Timer expired");
7fff4beb 67 } else {
27c766aa 68 pr_crit("Initiating system reboot\n");
479d0f41 69 emergency_restart();
27c766aa 70 pr_crit("Reboot didn't ?????\n");
1da177e4 71 }
1da177e4 72
8d5755b3
NC
73 return HRTIMER_NORESTART;
74}
44ba0f04 75
2accf320
WS
76static struct watchdog_device softdog_dev;
77
8d5755b3 78static enum hrtimer_restart softdog_pretimeout(struct hrtimer *timer)
2accf320
WS
79{
80 watchdog_notify_pretimeout(&softdog_dev);
2accf320 81
8d5755b3
NC
82 return HRTIMER_NORESTART;
83}
2accf320 84
a5132caf 85static int softdog_ping(struct watchdog_device *w)
1da177e4 86{
8d5755b3 87 if (!hrtimer_active(&softdog_ticktock))
5889f06b 88 __module_get(THIS_MODULE);
8d5755b3
NC
89 hrtimer_start(&softdog_ticktock, ktime_set(w->timeout, 0),
90 HRTIMER_MODE_REL);
2accf320 91
4cbc6902
WS
92 if (IS_ENABLED(CONFIG_SOFT_WATCHDOG_PRETIMEOUT)) {
93 if (w->pretimeout)
8d5755b3
NC
94 hrtimer_start(&softdog_preticktock,
95 ktime_set(w->timeout - w->pretimeout, 0),
96 HRTIMER_MODE_REL);
4cbc6902 97 else
8d5755b3 98 hrtimer_cancel(&softdog_preticktock);
4cbc6902 99 }
2accf320 100
1da177e4
LT
101 return 0;
102}
103
a5132caf 104static int softdog_stop(struct watchdog_device *w)
1da177e4 105{
8d5755b3 106 if (hrtimer_cancel(&softdog_ticktock))
5889f06b
LR
107 module_put(THIS_MODULE);
108
4cbc6902 109 if (IS_ENABLED(CONFIG_SOFT_WATCHDOG_PRETIMEOUT))
8d5755b3 110 hrtimer_cancel(&softdog_preticktock);
2accf320 111
1da177e4
LT
112 return 0;
113}
114
a5132caf
AC
115static struct watchdog_info softdog_info = {
116 .identity = "Software Watchdog",
4cbc6902 117 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
1da177e4
LT
118};
119
85f15cfc 120static const struct watchdog_ops softdog_ops = {
a5132caf
AC
121 .owner = THIS_MODULE,
122 .start = softdog_ping,
123 .stop = softdog_stop,
a5132caf
AC
124};
125
126static struct watchdog_device softdog_dev = {
127 .info = &softdog_info,
128 .ops = &softdog_ops,
129 .min_timeout = 1,
e8cf96ab
WS
130 .max_timeout = 65535,
131 .timeout = TIMER_MARGIN,
1da177e4
LT
132};
133
0efc70b8 134static int __init softdog_init(void)
1da177e4
LT
135{
136 int ret;
137
e8cf96ab 138 watchdog_init_timeout(&softdog_dev, soft_margin, NULL);
a5132caf 139 watchdog_set_nowayout(&softdog_dev, nowayout);
84ebcc17 140 watchdog_stop_on_reboot(&softdog_dev);
1da177e4 141
8d5755b3
NC
142 hrtimer_init(&softdog_ticktock, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
143 softdog_ticktock.function = softdog_fire;
144
145 if (IS_ENABLED(CONFIG_SOFT_WATCHDOG_PRETIMEOUT)) {
4cbc6902 146 softdog_info.options |= WDIOF_PRETIMEOUT;
8d5755b3
NC
147 hrtimer_init(&softdog_preticktock, CLOCK_MONOTONIC,
148 HRTIMER_MODE_REL);
149 softdog_preticktock.function = softdog_pretimeout;
150 }
4cbc6902 151
a5132caf 152 ret = watchdog_register_device(&softdog_dev);
84ebcc17 153 if (ret)
1da177e4 154 return ret;
1da177e4 155
e8cf96ab
WS
156 pr_info("initialized. soft_noboot=%d soft_margin=%d sec soft_panic=%d (nowayout=%d)\n",
157 soft_noboot, softdog_dev.timeout, soft_panic, nowayout);
1da177e4
LT
158
159 return 0;
160}
0efc70b8 161module_init(softdog_init);
1da177e4 162
0efc70b8 163static void __exit softdog_exit(void)
1da177e4 164{
a5132caf 165 watchdog_unregister_device(&softdog_dev);
1da177e4 166}
0efc70b8 167module_exit(softdog_exit);
1da177e4
LT
168
169MODULE_AUTHOR("Alan Cox");
170MODULE_DESCRIPTION("Software Watchdog Device Driver");
171MODULE_LICENSE("GPL");