Commit ff948060 authored by Alan Cox's avatar Alan Cox Committed by Wim Van Sebroeck

[WATCHDOG 43/57] sc520_wdt: Clean up and switch to unlocked_ioctl

Review and switch to unlocked_ioctl
Signed-off-by: default avatarAlan Cox <alan@redhat.com>
Signed-off-by: default avatarWim Van Sebroeck <wim@iguana.be>
parent d14bccaa
...@@ -64,9 +64,9 @@ ...@@ -64,9 +64,9 @@
#include <linux/reboot.h> #include <linux/reboot.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/jiffies.h> #include <linux/jiffies.h>
#include <linux/io.h>
#include <linux/uaccess.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <asm/system.h> #include <asm/system.h>
#define OUR_NAME "sc520_wdt" #define OUR_NAME "sc520_wdt"
...@@ -91,13 +91,18 @@ ...@@ -91,13 +91,18 @@
*/ */
#define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */ #define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */
static int timeout = WATCHDOG_TIMEOUT; /* in seconds, will be multiplied by HZ to get seconds to wait for a ping */ /* in seconds, will be multiplied by HZ to get seconds to wait for a ping */
static int timeout = WATCHDOG_TIMEOUT;
module_param(timeout, int, 0); module_param(timeout, int, 0);
MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (1<=timeout<=3600, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")"); MODULE_PARM_DESC(timeout,
"Watchdog timeout in seconds. (1 <= timeout <= 3600, default="
__MODULE_STRING(WATCHDOG_TIMEOUT) ")");
static int nowayout = WATCHDOG_NOWAYOUT; static int nowayout = WATCHDOG_NOWAYOUT;
module_param(nowayout, int, 0); module_param(nowayout, int, 0);
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); MODULE_PARM_DESC(nowayout,
"Watchdog cannot be stopped once started (default="
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
/* /*
* AMD Elan SC520 - Watchdog Timer Registers * AMD Elan SC520 - Watchdog Timer Registers
...@@ -136,8 +141,7 @@ static void wdt_timer_ping(unsigned long data) ...@@ -136,8 +141,7 @@ static void wdt_timer_ping(unsigned long data)
/* If we got a heartbeat pulse within the WDT_US_INTERVAL /* If we got a heartbeat pulse within the WDT_US_INTERVAL
* we agree to ping the WDT * we agree to ping the WDT
*/ */
if(time_before(jiffies, next_heartbeat)) if (time_before(jiffies, next_heartbeat)) {
{
/* Ping the WDT */ /* Ping the WDT */
spin_lock(&wdt_spinlock); spin_lock(&wdt_spinlock);
writew(0xAAAA, wdtmrctl); writew(0xAAAA, wdtmrctl);
...@@ -146,9 +150,9 @@ static void wdt_timer_ping(unsigned long data) ...@@ -146,9 +150,9 @@ static void wdt_timer_ping(unsigned long data)
/* Re-set the timer interval */ /* Re-set the timer interval */
mod_timer(&timer, jiffies + WDT_INTERVAL); mod_timer(&timer, jiffies + WDT_INTERVAL);
} else { } else
printk(KERN_WARNING PFX "Heartbeat lost! Will not ping the watchdog\n"); printk(KERN_WARNING PFX
} "Heartbeat lost! Will not ping the watchdog\n");
} }
/* /*
...@@ -162,7 +166,7 @@ static void wdt_config(int writeval) ...@@ -162,7 +166,7 @@ static void wdt_config(int writeval)
/* buy some time (ping) */ /* buy some time (ping) */
spin_lock_irqsave(&wdt_spinlock, flags); spin_lock_irqsave(&wdt_spinlock, flags);
dummy=readw(wdtmrctl); /* ensure write synchronization */ dummy = readw(wdtmrctl); /* ensure write synchronization */
writew(0xAAAA, wdtmrctl); writew(0xAAAA, wdtmrctl);
writew(0x5555, wdtmrctl); writew(0x5555, wdtmrctl);
/* unlock WDT = make WDT configuration register writable one time */ /* unlock WDT = make WDT configuration register writable one time */
...@@ -219,10 +223,11 @@ static int wdt_set_heartbeat(int t) ...@@ -219,10 +223,11 @@ static int wdt_set_heartbeat(int t)
* /dev/watchdog handling * /dev/watchdog handling
*/ */
static ssize_t fop_write(struct file * file, const char __user * buf, size_t count, loff_t * ppos) static ssize_t fop_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{ {
/* See if we got the magic character 'V' and reload the timer */ /* See if we got the magic character 'V' and reload the timer */
if(count) { if (count) {
if (!nowayout) { if (!nowayout) {
size_t ofs; size_t ofs;
...@@ -231,25 +236,26 @@ static ssize_t fop_write(struct file * file, const char __user * buf, size_t cou ...@@ -231,25 +236,26 @@ static ssize_t fop_write(struct file * file, const char __user * buf, size_t cou
wdt_expect_close = 0; wdt_expect_close = 0;
/* now scan */ /* now scan */
for(ofs = 0; ofs != count; ofs++) { for (ofs = 0; ofs != count; ofs++) {
char c; char c;
if (get_user(c, buf + ofs)) if (get_user(c, buf + ofs))
return -EFAULT; return -EFAULT;
if(c == 'V') if (c == 'V')
wdt_expect_close = 42; wdt_expect_close = 42;
} }
} }
/* Well, anyhow someone wrote to us, we should return that favour */ /* Well, anyhow someone wrote to us, we should
return that favour */
wdt_keepalive(); wdt_keepalive();
} }
return count; return count;
} }
static int fop_open(struct inode * inode, struct file * file) static int fop_open(struct inode *inode, struct file *file)
{ {
/* Just in case we're already talking to someone... */ /* Just in case we're already talking to someone... */
if(test_and_set_bit(0, &wdt_is_open)) if (test_and_set_bit(0, &wdt_is_open))
return -EBUSY; return -EBUSY;
if (nowayout) if (nowayout)
__module_get(THIS_MODULE); __module_get(THIS_MODULE);
...@@ -259,12 +265,13 @@ static int fop_open(struct inode * inode, struct file * file) ...@@ -259,12 +265,13 @@ static int fop_open(struct inode * inode, struct file * file)
return nonseekable_open(inode, file); return nonseekable_open(inode, file);
} }
static int fop_close(struct inode * inode, struct file * file) static int fop_close(struct inode *inode, struct file *file)
{ {
if(wdt_expect_close == 42) { if (wdt_expect_close == 42)
wdt_turnoff(); wdt_turnoff();
} else { else {
printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n"); printk(KERN_CRIT PFX
"Unexpected close, not stopping watchdog!\n");
wdt_keepalive(); wdt_keepalive();
} }
clear_bit(0, &wdt_is_open); clear_bit(0, &wdt_is_open);
...@@ -272,63 +279,63 @@ static int fop_close(struct inode * inode, struct file * file) ...@@ -272,63 +279,63 @@ static int fop_close(struct inode * inode, struct file * file)
return 0; return 0;
} }
static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd, static int fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
unsigned long arg)
{ {
void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg;
int __user *p = argp; int __user *p = argp;
static struct watchdog_info ident = { static const struct watchdog_info ident = {
.options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT
| WDIOF_MAGICCLOSE,
.firmware_version = 1, .firmware_version = 1,
.identity = "SC520", .identity = "SC520",
}; };
switch(cmd) switch (cmd)
{ {
default: default:
return -ENOTTY; return -ENOTTY;
case WDIOC_GETSUPPORT: case WDIOC_GETSUPPORT:
return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0; return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
case WDIOC_GETSTATUS: case WDIOC_GETSTATUS:
case WDIOC_GETBOOTSTATUS: case WDIOC_GETBOOTSTATUS:
return put_user(0, p); return put_user(0, p);
case WDIOC_KEEPALIVE: case WDIOC_KEEPALIVE:
wdt_keepalive(); wdt_keepalive();
return 0; return 0;
case WDIOC_SETOPTIONS: case WDIOC_SETOPTIONS:
{ {
int new_options, retval = -EINVAL; int new_options, retval = -EINVAL;
if(get_user(new_options, p))
return -EFAULT;
if(new_options & WDIOS_DISABLECARD) {
wdt_turnoff();
retval = 0;
}
if(new_options & WDIOS_ENABLECARD) { if (get_user(new_options, p))
wdt_startup(); return -EFAULT;
retval = 0;
} if (new_options & WDIOS_DISABLECARD) {
wdt_turnoff();
retval = 0;
}
return retval; if (new_options & WDIOS_ENABLECARD) {
wdt_startup();
retval = 0;
} }
case WDIOC_SETTIMEOUT:
{
int new_timeout;
if(get_user(new_timeout, p)) return retval;
return -EFAULT; }
case WDIOC_SETTIMEOUT:
{
int new_timeout;
if(wdt_set_heartbeat(new_timeout)) if (get_user(new_timeout, p))
return -EINVAL; return -EFAULT;
wdt_keepalive(); if (wdt_set_heartbeat(new_timeout))
/* Fall through */ return -EINVAL;
}
case WDIOC_GETTIMEOUT: wdt_keepalive();
return put_user(timeout, p); /* Fall through */
}
case WDIOC_GETTIMEOUT:
return put_user(timeout, p);
} }
} }
...@@ -354,7 +361,7 @@ static struct miscdevice wdt_miscdev = { ...@@ -354,7 +361,7 @@ static struct miscdevice wdt_miscdev = {
static int wdt_notify_sys(struct notifier_block *this, unsigned long code, static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
void *unused) void *unused)
{ {
if(code==SYS_DOWN || code==SYS_HALT) if (code == SYS_DOWN || code == SYS_HALT)
wdt_turnoff(); wdt_turnoff();
return NOTIFY_DONE; return NOTIFY_DONE;
} }
...@@ -383,11 +390,13 @@ static int __init sc520_wdt_init(void) ...@@ -383,11 +390,13 @@ static int __init sc520_wdt_init(void)
{ {
int rc = -EBUSY; int rc = -EBUSY;
/* Check that the timeout value is within it's range ; if not reset to the default */ /* Check that the timeout value is within it's range ;
if not reset to the default */
if (wdt_set_heartbeat(timeout)) { if (wdt_set_heartbeat(timeout)) {
wdt_set_heartbeat(WATCHDOG_TIMEOUT); wdt_set_heartbeat(WATCHDOG_TIMEOUT);
printk(KERN_INFO PFX "timeout value must be 1<=timeout<=3600, using %d\n", printk(KERN_INFO PFX
WATCHDOG_TIMEOUT); "timeout value must be 1 <= timeout <= 3600, using %d\n",
WATCHDOG_TIMEOUT);
} }
wdtmrctl = ioremap((unsigned long)(MMCR_BASE + OFFS_WDTMRCTL), 2); wdtmrctl = ioremap((unsigned long)(MMCR_BASE + OFFS_WDTMRCTL), 2);
...@@ -399,20 +408,22 @@ static int __init sc520_wdt_init(void) ...@@ -399,20 +408,22 @@ static int __init sc520_wdt_init(void)
rc = register_reboot_notifier(&wdt_notifier); rc = register_reboot_notifier(&wdt_notifier);
if (rc) { if (rc) {
printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", printk(KERN_ERR PFX
rc); "cannot register reboot notifier (err=%d)\n", rc);
goto err_out_ioremap; goto err_out_ioremap;
} }
rc = misc_register(&wdt_miscdev); rc = misc_register(&wdt_miscdev);
if (rc) { if (rc) {
printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", printk(KERN_ERR PFX
WATCHDOG_MINOR, rc); "cannot register miscdev on minor=%d (err=%d)\n",
WATCHDOG_MINOR, rc);
goto err_out_notifier; goto err_out_notifier;
} }
printk(KERN_INFO PFX "WDT driver for SC520 initialised. timeout=%d sec (nowayout=%d)\n", printk(KERN_INFO PFX
timeout,nowayout); "WDT driver for SC520 initialised. timeout=%d sec (nowayout=%d)\n",
timeout, nowayout);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment