diff options
Diffstat (limited to 'drivers/watchdog/sbc60xxwdt.c')
-rw-r--r-- | drivers/watchdog/sbc60xxwdt.c | 223 |
1 files changed, 110 insertions, 113 deletions
diff --git a/drivers/watchdog/sbc60xxwdt.c b/drivers/watchdog/sbc60xxwdt.c index ef76f01625e7..3266daaaecf8 100644 --- a/drivers/watchdog/sbc60xxwdt.c +++ b/drivers/watchdog/sbc60xxwdt.c | |||
@@ -16,19 +16,23 @@ | |||
16 | * | 16 | * |
17 | * 12/4 - 2000 [Initial revision] | 17 | * 12/4 - 2000 [Initial revision] |
18 | * 25/4 - 2000 Added /dev/watchdog support | 18 | * 25/4 - 2000 Added /dev/watchdog support |
19 | * 09/5 - 2001 [smj@oro.net] fixed fop_write to "return 1" on success | 19 | * 09/5 - 2001 [smj@oro.net] fixed fop_write to "return 1" |
20 | * on success | ||
20 | * 12/4 - 2002 [rob@osinvestor.com] eliminate fop_read | 21 | * 12/4 - 2002 [rob@osinvestor.com] eliminate fop_read |
21 | * fix possible wdt_is_open race | 22 | * fix possible wdt_is_open race |
22 | * add CONFIG_WATCHDOG_NOWAYOUT support | 23 | * add CONFIG_WATCHDOG_NOWAYOUT support |
23 | * remove lock_kernel/unlock_kernel pairs | 24 | * remove lock_kernel/unlock_kernel pairs |
24 | * added KERN_* to printk's | 25 | * added KERN_* to printk's |
25 | * got rid of extraneous comments | 26 | * got rid of extraneous comments |
26 | * changed watchdog_info to correctly reflect what the driver offers | 27 | * changed watchdog_info to correctly reflect what |
27 | * added WDIOC_GETSTATUS, WDIOC_GETBOOTSTATUS, WDIOC_SETTIMEOUT, | 28 | * the driver offers |
28 | * WDIOC_GETTIMEOUT, and WDIOC_SETOPTIONS ioctls | 29 | * added WDIOC_GETSTATUS, WDIOC_GETBOOTSTATUS, |
30 | * WDIOC_SETTIMEOUT, WDIOC_GETTIMEOUT, and | ||
31 | * WDIOC_SETOPTIONS ioctls | ||
29 | * 09/8 - 2003 [wim@iguana.be] cleanup of trailing spaces | 32 | * 09/8 - 2003 [wim@iguana.be] cleanup of trailing spaces |
30 | * use module_param | 33 | * use module_param |
31 | * made timeout (the emulated heartbeat) a module_param | 34 | * made timeout (the emulated heartbeat) a |
35 | * module_param | ||
32 | * made the keepalive ping an internal subroutine | 36 | * made the keepalive ping an internal subroutine |
33 | * made wdt_stop and wdt_start module params | 37 | * made wdt_stop and wdt_start module params |
34 | * added extra printk's for startup problems | 38 | * added extra printk's for startup problems |
@@ -56,9 +60,9 @@ | |||
56 | #include <linux/notifier.h> | 60 | #include <linux/notifier.h> |
57 | #include <linux/reboot.h> | 61 | #include <linux/reboot.h> |
58 | #include <linux/init.h> | 62 | #include <linux/init.h> |
63 | #include <linux/io.h> | ||
64 | #include <linux/uaccess.h> | ||
59 | 65 | ||
60 | #include <asm/io.h> | ||
61 | #include <asm/uaccess.h> | ||
62 | #include <asm/system.h> | 66 | #include <asm/system.h> |
63 | 67 | ||
64 | #define OUR_NAME "sbc60xxwdt" | 68 | #define OUR_NAME "sbc60xxwdt" |
@@ -94,13 +98,18 @@ MODULE_PARM_DESC(wdt_start, "SBC60xx WDT 'start' io port (default 0x443)"); | |||
94 | */ | 98 | */ |
95 | 99 | ||
96 | #define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */ | 100 | #define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */ |
97 | static int timeout = WATCHDOG_TIMEOUT; /* in seconds, will be multiplied by HZ to get seconds to wait for a ping */ | 101 | static int timeout = WATCHDOG_TIMEOUT; /* in seconds, multiplied by HZ to |
102 | get seconds to wait for a ping */ | ||
98 | module_param(timeout, int, 0); | 103 | module_param(timeout, int, 0); |
99 | MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (1<=timeout<=3600, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")"); | 104 | MODULE_PARM_DESC(timeout, |
105 | "Watchdog timeout in seconds. (1<=timeout<=3600, default=" | ||
106 | __MODULE_STRING(WATCHDOG_TIMEOUT) ")"); | ||
100 | 107 | ||
101 | static int nowayout = WATCHDOG_NOWAYOUT; | 108 | static int nowayout = WATCHDOG_NOWAYOUT; |
102 | module_param(nowayout, int, 0); | 109 | module_param(nowayout, int, 0); |
103 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); | 110 | MODULE_PARM_DESC(nowayout, |
111 | "Watchdog cannot be stopped once started (default=" | ||
112 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); | ||
104 | 113 | ||
105 | static void wdt_timer_ping(unsigned long); | 114 | static void wdt_timer_ping(unsigned long); |
106 | static DEFINE_TIMER(timer, wdt_timer_ping, 0, 0); | 115 | static DEFINE_TIMER(timer, wdt_timer_ping, 0, 0); |
@@ -117,15 +126,14 @@ static void wdt_timer_ping(unsigned long data) | |||
117 | /* If we got a heartbeat pulse within the WDT_US_INTERVAL | 126 | /* If we got a heartbeat pulse within the WDT_US_INTERVAL |
118 | * we agree to ping the WDT | 127 | * we agree to ping the WDT |
119 | */ | 128 | */ |
120 | if(time_before(jiffies, next_heartbeat)) | 129 | if (time_before(jiffies, next_heartbeat)) { |
121 | { | ||
122 | /* Ping the WDT by reading from wdt_start */ | 130 | /* Ping the WDT by reading from wdt_start */ |
123 | inb_p(wdt_start); | 131 | inb_p(wdt_start); |
124 | /* Re-set the timer interval */ | 132 | /* Re-set the timer interval */ |
125 | mod_timer(&timer, jiffies + WDT_INTERVAL); | 133 | mod_timer(&timer, jiffies + WDT_INTERVAL); |
126 | } else { | 134 | } else |
127 | printk(KERN_WARNING PFX "Heartbeat lost! Will not ping the watchdog\n"); | 135 | printk(KERN_WARNING PFX |
128 | } | 136 | "Heartbeat lost! Will not ping the watchdog\n"); |
129 | } | 137 | } |
130 | 138 | ||
131 | /* | 139 | /* |
@@ -159,40 +167,40 @@ static void wdt_keepalive(void) | |||
159 | * /dev/watchdog handling | 167 | * /dev/watchdog handling |
160 | */ | 168 | */ |
161 | 169 | ||
162 | static ssize_t fop_write(struct file * file, const char __user * buf, size_t count, loff_t * ppos) | 170 | static ssize_t fop_write(struct file *file, const char __user *buf, |
171 | size_t count, loff_t *ppos) | ||
163 | { | 172 | { |
164 | /* See if we got the magic character 'V' and reload the timer */ | 173 | /* See if we got the magic character 'V' and reload the timer */ |
165 | if(count) | 174 | if (count) { |
166 | { | 175 | if (!nowayout) { |
167 | if (!nowayout) | ||
168 | { | ||
169 | size_t ofs; | 176 | size_t ofs; |
170 | 177 | ||
171 | /* note: just in case someone wrote the magic character | 178 | /* note: just in case someone wrote the |
172 | * five months ago... */ | 179 | magic character five months ago... */ |
173 | wdt_expect_close = 0; | 180 | wdt_expect_close = 0; |
174 | 181 | ||
175 | /* scan to see whether or not we got the magic character */ | 182 | /* scan to see whether or not we got the |
176 | for(ofs = 0; ofs != count; ofs++) | 183 | magic character */ |
177 | { | 184 | for (ofs = 0; ofs != count; ofs++) { |
178 | char c; | 185 | char c; |
179 | if(get_user(c, buf+ofs)) | 186 | if (get_user(c, buf + ofs)) |
180 | return -EFAULT; | 187 | return -EFAULT; |
181 | if(c == 'V') | 188 | if (c == 'V') |
182 | wdt_expect_close = 42; | 189 | wdt_expect_close = 42; |
183 | } | 190 | } |
184 | } | 191 | } |
185 | 192 | ||
186 | /* Well, anyhow someone wrote to us, we should return that favour */ | 193 | /* Well, anyhow someone wrote to us, we should |
194 | return that favour */ | ||
187 | wdt_keepalive(); | 195 | wdt_keepalive(); |
188 | } | 196 | } |
189 | return count; | 197 | return count; |
190 | } | 198 | } |
191 | 199 | ||
192 | static int fop_open(struct inode * inode, struct file * file) | 200 | static int fop_open(struct inode *inode, struct file *file) |
193 | { | 201 | { |
194 | /* Just in case we're already talking to someone... */ | 202 | /* Just in case we're already talking to someone... */ |
195 | if(test_and_set_bit(0, &wdt_is_open)) | 203 | if (test_and_set_bit(0, &wdt_is_open)) |
196 | return -EBUSY; | 204 | return -EBUSY; |
197 | 205 | ||
198 | if (nowayout) | 206 | if (nowayout) |
@@ -203,78 +211,72 @@ static int fop_open(struct inode * inode, struct file * file) | |||
203 | return nonseekable_open(inode, file); | 211 | return nonseekable_open(inode, file); |
204 | } | 212 | } |
205 | 213 | ||
206 | static int fop_close(struct inode * inode, struct file * file) | 214 | static int fop_close(struct inode *inode, struct file *file) |
207 | { | 215 | { |
208 | if(wdt_expect_close == 42) | 216 | if (wdt_expect_close == 42) |
209 | wdt_turnoff(); | 217 | wdt_turnoff(); |
210 | else { | 218 | else { |
211 | del_timer(&timer); | 219 | del_timer(&timer); |
212 | printk(KERN_CRIT PFX "device file closed unexpectedly. Will not stop the WDT!\n"); | 220 | printk(KERN_CRIT PFX |
221 | "device file closed unexpectedly. Will not stop the WDT!\n"); | ||
213 | } | 222 | } |
214 | clear_bit(0, &wdt_is_open); | 223 | clear_bit(0, &wdt_is_open); |
215 | wdt_expect_close = 0; | 224 | wdt_expect_close = 0; |
216 | return 0; | 225 | return 0; |
217 | } | 226 | } |
218 | 227 | ||
219 | static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | 228 | static long fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
220 | unsigned long arg) | ||
221 | { | 229 | { |
222 | void __user *argp = (void __user *)arg; | 230 | void __user *argp = (void __user *)arg; |
223 | int __user *p = argp; | 231 | int __user *p = argp; |
224 | static struct watchdog_info ident= | 232 | static const struct watchdog_info ident = { |
225 | { | 233 | .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | |
226 | .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, | 234 | WDIOF_MAGICCLOSE, |
227 | .firmware_version = 1, | 235 | .firmware_version = 1, |
228 | .identity = "SBC60xx", | 236 | .identity = "SBC60xx", |
229 | }; | 237 | }; |
230 | 238 | ||
231 | switch(cmd) | 239 | switch (cmd) { |
240 | case WDIOC_GETSUPPORT: | ||
241 | return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0; | ||
242 | case WDIOC_GETSTATUS: | ||
243 | case WDIOC_GETBOOTSTATUS: | ||
244 | return put_user(0, p); | ||
245 | case WDIOC_SETOPTIONS: | ||
232 | { | 246 | { |
233 | default: | 247 | int new_options, retval = -EINVAL; |
234 | return -ENOTTY; | 248 | if (get_user(new_options, p)) |
235 | case WDIOC_GETSUPPORT: | 249 | return -EFAULT; |
236 | return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0; | 250 | if (new_options & WDIOS_DISABLECARD) { |
237 | case WDIOC_GETSTATUS: | 251 | wdt_turnoff(); |
238 | case WDIOC_GETBOOTSTATUS: | 252 | retval = 0; |
239 | return put_user(0, p); | ||
240 | case WDIOC_KEEPALIVE: | ||
241 | wdt_keepalive(); | ||
242 | return 0; | ||
243 | case WDIOC_SETOPTIONS: | ||
244 | { | ||
245 | int new_options, retval = -EINVAL; | ||
246 | |||
247 | if(get_user(new_options, p)) | ||
248 | return -EFAULT; | ||
249 | |||
250 | if(new_options & WDIOS_DISABLECARD) { | ||
251 | wdt_turnoff(); | ||
252 | retval = 0; | ||
253 | } | ||
254 | |||
255 | if(new_options & WDIOS_ENABLECARD) { | ||
256 | wdt_startup(); | ||
257 | retval = 0; | ||
258 | } | ||
259 | |||
260 | return retval; | ||
261 | } | 253 | } |
262 | case WDIOC_SETTIMEOUT: | 254 | if (new_options & WDIOS_ENABLECARD) { |
263 | { | 255 | wdt_startup(); |
264 | int new_timeout; | 256 | retval = 0; |
265 | |||
266 | if(get_user(new_timeout, p)) | ||
267 | return -EFAULT; | ||
268 | |||
269 | if(new_timeout < 1 || new_timeout > 3600) /* arbitrary upper limit */ | ||
270 | return -EINVAL; | ||
271 | |||
272 | timeout = new_timeout; | ||
273 | wdt_keepalive(); | ||
274 | /* Fall through */ | ||
275 | } | 257 | } |
276 | case WDIOC_GETTIMEOUT: | 258 | return retval; |
277 | return put_user(timeout, p); | 259 | } |
260 | case WDIOC_KEEPALIVE: | ||
261 | wdt_keepalive(); | ||
262 | return 0; | ||
263 | case WDIOC_SETTIMEOUT: | ||
264 | { | ||
265 | int new_timeout; | ||
266 | if (get_user(new_timeout, p)) | ||
267 | return -EFAULT; | ||
268 | /* arbitrary upper limit */ | ||
269 | if (new_timeout < 1 || new_timeout > 3600) | ||
270 | return -EINVAL; | ||
271 | |||
272 | timeout = new_timeout; | ||
273 | wdt_keepalive(); | ||
274 | /* Fall through */ | ||
275 | } | ||
276 | case WDIOC_GETTIMEOUT: | ||
277 | return put_user(timeout, p); | ||
278 | default: | ||
279 | return -ENOTTY; | ||
278 | } | 280 | } |
279 | } | 281 | } |
280 | 282 | ||
@@ -284,7 +286,7 @@ static const struct file_operations wdt_fops = { | |||
284 | .write = fop_write, | 286 | .write = fop_write, |
285 | .open = fop_open, | 287 | .open = fop_open, |
286 | .release = fop_close, | 288 | .release = fop_close, |
287 | .ioctl = fop_ioctl, | 289 | .unlocked_ioctl = fop_ioctl, |
288 | }; | 290 | }; |
289 | 291 | ||
290 | static struct miscdevice wdt_miscdev = { | 292 | static struct miscdevice wdt_miscdev = { |
@@ -300,7 +302,7 @@ static struct miscdevice wdt_miscdev = { | |||
300 | static int wdt_notify_sys(struct notifier_block *this, unsigned long code, | 302 | static int wdt_notify_sys(struct notifier_block *this, unsigned long code, |
301 | void *unused) | 303 | void *unused) |
302 | { | 304 | { |
303 | if(code==SYS_DOWN || code==SYS_HALT) | 305 | if (code == SYS_DOWN || code == SYS_HALT) |
304 | wdt_turnoff(); | 306 | wdt_turnoff(); |
305 | return NOTIFY_DONE; | 307 | return NOTIFY_DONE; |
306 | } | 308 | } |
@@ -310,8 +312,7 @@ static int wdt_notify_sys(struct notifier_block *this, unsigned long code, | |||
310 | * turn the timebomb registers off. | 312 | * turn the timebomb registers off. |
311 | */ | 313 | */ |
312 | 314 | ||
313 | static struct notifier_block wdt_notifier= | 315 | static struct notifier_block wdt_notifier = { |
314 | { | ||
315 | .notifier_call = wdt_notify_sys, | 316 | .notifier_call = wdt_notify_sys, |
316 | }; | 317 | }; |
317 | 318 | ||
@@ -324,23 +325,22 @@ static void __exit sbc60xxwdt_unload(void) | |||
324 | 325 | ||
325 | unregister_reboot_notifier(&wdt_notifier); | 326 | unregister_reboot_notifier(&wdt_notifier); |
326 | if ((wdt_stop != 0x45) && (wdt_stop != wdt_start)) | 327 | if ((wdt_stop != 0x45) && (wdt_stop != wdt_start)) |
327 | release_region(wdt_stop,1); | 328 | release_region(wdt_stop, 1); |
328 | release_region(wdt_start,1); | 329 | release_region(wdt_start, 1); |
329 | } | 330 | } |
330 | 331 | ||
331 | static int __init sbc60xxwdt_init(void) | 332 | static int __init sbc60xxwdt_init(void) |
332 | { | 333 | { |
333 | int rc = -EBUSY; | 334 | int rc = -EBUSY; |
334 | 335 | ||
335 | if(timeout < 1 || timeout > 3600) /* arbitrary upper limit */ | 336 | if (timeout < 1 || timeout > 3600) { /* arbitrary upper limit */ |
336 | { | ||
337 | timeout = WATCHDOG_TIMEOUT; | 337 | timeout = WATCHDOG_TIMEOUT; |
338 | printk(KERN_INFO PFX "timeout value must be 1<=x<=3600, using %d\n", | 338 | printk(KERN_INFO PFX |
339 | timeout); | 339 | "timeout value must be 1 <= x <= 3600, using %d\n", |
340 | } | 340 | timeout); |
341 | } | ||
341 | 342 | ||
342 | if (!request_region(wdt_start, 1, "SBC 60XX WDT")) | 343 | if (!request_region(wdt_start, 1, "SBC 60XX WDT")) { |
343 | { | ||
344 | printk(KERN_ERR PFX "I/O address 0x%04x already in use\n", | 344 | printk(KERN_ERR PFX "I/O address 0x%04x already in use\n", |
345 | wdt_start); | 345 | wdt_start); |
346 | rc = -EIO; | 346 | rc = -EIO; |
@@ -348,33 +348,30 @@ static int __init sbc60xxwdt_init(void) | |||
348 | } | 348 | } |
349 | 349 | ||
350 | /* We cannot reserve 0x45 - the kernel already has! */ | 350 | /* We cannot reserve 0x45 - the kernel already has! */ |
351 | if ((wdt_stop != 0x45) && (wdt_stop != wdt_start)) | 351 | if (wdt_stop != 0x45 && wdt_stop != wdt_start) { |
352 | { | 352 | if (!request_region(wdt_stop, 1, "SBC 60XX WDT")) { |
353 | if (!request_region(wdt_stop, 1, "SBC 60XX WDT")) | 353 | printk(KERN_ERR PFX |
354 | { | 354 | "I/O address 0x%04x already in use\n", |
355 | printk(KERN_ERR PFX "I/O address 0x%04x already in use\n", | 355 | wdt_stop); |
356 | wdt_stop); | ||
357 | rc = -EIO; | 356 | rc = -EIO; |
358 | goto err_out_region1; | 357 | goto err_out_region1; |
359 | } | 358 | } |
360 | } | 359 | } |
361 | 360 | ||
362 | rc = register_reboot_notifier(&wdt_notifier); | 361 | rc = register_reboot_notifier(&wdt_notifier); |
363 | if (rc) | 362 | if (rc) { |
364 | { | 363 | printk(KERN_ERR PFX |
365 | printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", | 364 | "cannot register reboot notifier (err=%d)\n", rc); |
366 | rc); | ||
367 | goto err_out_region2; | 365 | goto err_out_region2; |
368 | } | 366 | } |
369 | 367 | ||
370 | rc = misc_register(&wdt_miscdev); | 368 | rc = misc_register(&wdt_miscdev); |
371 | if (rc) | 369 | if (rc) { |
372 | { | 370 | printk(KERN_ERR PFX |
373 | printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", | 371 | "cannot register miscdev on minor=%d (err=%d)\n", |
374 | wdt_miscdev.minor, rc); | 372 | wdt_miscdev.minor, rc); |
375 | goto err_out_reboot; | 373 | goto err_out_reboot; |
376 | } | 374 | } |
377 | |||
378 | printk(KERN_INFO PFX "WDT driver for 60XX single board computer initialised. timeout=%d sec (nowayout=%d)\n", | 375 | printk(KERN_INFO PFX "WDT driver for 60XX single board computer initialised. timeout=%d sec (nowayout=%d)\n", |
379 | timeout, nowayout); | 376 | timeout, nowayout); |
380 | 377 | ||
@@ -383,10 +380,10 @@ static int __init sbc60xxwdt_init(void) | |||
383 | err_out_reboot: | 380 | err_out_reboot: |
384 | unregister_reboot_notifier(&wdt_notifier); | 381 | unregister_reboot_notifier(&wdt_notifier); |
385 | err_out_region2: | 382 | err_out_region2: |
386 | if ((wdt_stop != 0x45) && (wdt_stop != wdt_start)) | 383 | if (wdt_stop != 0x45 && wdt_stop != wdt_start) |
387 | release_region(wdt_stop,1); | 384 | release_region(wdt_stop, 1); |
388 | err_out_region1: | 385 | err_out_region1: |
389 | release_region(wdt_start,1); | 386 | release_region(wdt_start, 1); |
390 | err_out: | 387 | err_out: |
391 | return rc; | 388 | return rc; |
392 | } | 389 | } |