[WATCHDOG 02/57] clean up and check advantech watchdog
Clean up the advantech watchdog code and inspect for BKL problems Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
This commit is contained in:
parent
94da1e2eff
commit
b6b4d9b8d0
|
@ -72,35 +72,35 @@ MODULE_PARM_DESC(wdt_start, "Advantech WDT 'start' io port (default 0x443)");
|
||||||
|
|
||||||
static int timeout = WATCHDOG_TIMEOUT; /* in seconds */
|
static int timeout = WATCHDOG_TIMEOUT; /* in seconds */
|
||||||
module_param(timeout, int, 0);
|
module_param(timeout, int, 0);
|
||||||
MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. 1<= timeout <=63, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ".");
|
MODULE_PARM_DESC(timeout,
|
||||||
|
"Watchdog timeout in seconds. 1<= timeout <=63, 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) ")");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Watchdog Operations
|
* Watchdog Operations
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void advwdt_ping(void)
|
||||||
advwdt_ping(void)
|
|
||||||
{
|
{
|
||||||
/* Write a watchdog value */
|
/* Write a watchdog value */
|
||||||
outb_p(timeout, wdt_start);
|
outb_p(timeout, wdt_start);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void advwdt_disable(void)
|
||||||
advwdt_disable(void)
|
|
||||||
{
|
{
|
||||||
inb_p(wdt_stop);
|
inb_p(wdt_stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int advwdt_set_heartbeat(int t)
|
||||||
advwdt_set_heartbeat(int t)
|
|
||||||
{
|
{
|
||||||
if ((t < 1) || (t > 63))
|
if (t < 1 || t > 63)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
timeout = t;
|
timeout = t;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -109,8 +109,8 @@ advwdt_set_heartbeat(int t)
|
||||||
* /dev/watchdog handling
|
* /dev/watchdog handling
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t advwdt_write(struct file *file, const char __user *buf,
|
||||||
advwdt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
|
size_t count, loff_t *ppos)
|
||||||
{
|
{
|
||||||
if (count) {
|
if (count) {
|
||||||
if (!nowayout) {
|
if (!nowayout) {
|
||||||
|
@ -131,9 +131,7 @@ advwdt_write(struct file *file, const char __user *buf, size_t count, loff_t *pp
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static long advwdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
|
||||||
advwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
|
|
||||||
unsigned long arg)
|
|
||||||
{
|
{
|
||||||
int new_timeout;
|
int new_timeout;
|
||||||
void __user *argp = (void __user *)arg;
|
void __user *argp = (void __user *)arg;
|
||||||
|
@ -146,57 +144,50 @@ advwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case WDIOC_GETSUPPORT:
|
case WDIOC_GETSUPPORT:
|
||||||
if (copy_to_user(argp, &ident, sizeof(ident)))
|
if (copy_to_user(argp, &ident, sizeof(ident)))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
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:
|
||||||
advwdt_ping();
|
advwdt_ping();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WDIOC_SETTIMEOUT:
|
case WDIOC_SETTIMEOUT:
|
||||||
if (get_user(new_timeout, p))
|
if (get_user(new_timeout, p))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
if (advwdt_set_heartbeat(new_timeout))
|
if (advwdt_set_heartbeat(new_timeout))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
advwdt_ping();
|
advwdt_ping();
|
||||||
/* Fall */
|
/* Fall */
|
||||||
|
|
||||||
case WDIOC_GETTIMEOUT:
|
case WDIOC_GETTIMEOUT:
|
||||||
return put_user(timeout, p);
|
return put_user(timeout, p);
|
||||||
|
|
||||||
case WDIOC_SETOPTIONS:
|
case WDIOC_SETOPTIONS:
|
||||||
{
|
{
|
||||||
int options, retval = -EINVAL;
|
int options, retval = -EINVAL;
|
||||||
|
|
||||||
if (get_user(options, p))
|
if (get_user(options, p))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
if (options & WDIOS_DISABLECARD) {
|
||||||
if (options & WDIOS_DISABLECARD) {
|
advwdt_disable();
|
||||||
advwdt_disable();
|
retval = 0;
|
||||||
retval = 0;
|
}
|
||||||
}
|
if (options & WDIOS_ENABLECARD) {
|
||||||
|
advwdt_ping();
|
||||||
if (options & WDIOS_ENABLECARD) {
|
retval = 0;
|
||||||
advwdt_ping();
|
}
|
||||||
retval = 0;
|
return retval;
|
||||||
}
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -ENOTTY;
|
return -ENOTTY;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int advwdt_open(struct inode *inode, struct file *file)
|
||||||
advwdt_open(struct inode *inode, struct file *file)
|
|
||||||
{
|
{
|
||||||
if (test_and_set_bit(0, &advwdt_is_open))
|
if (test_and_set_bit(0, &advwdt_is_open))
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
|
@ -214,7 +205,8 @@ advwdt_close(struct inode *inode, struct file *file)
|
||||||
if (adv_expect_close == 42) {
|
if (adv_expect_close == 42) {
|
||||||
advwdt_disable();
|
advwdt_disable();
|
||||||
} else {
|
} else {
|
||||||
printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
|
printk(KERN_CRIT PFX
|
||||||
|
"Unexpected close, not stopping watchdog!\n");
|
||||||
advwdt_ping();
|
advwdt_ping();
|
||||||
}
|
}
|
||||||
clear_bit(0, &advwdt_is_open);
|
clear_bit(0, &advwdt_is_open);
|
||||||
|
@ -230,7 +222,7 @@ static const struct file_operations advwdt_fops = {
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.llseek = no_llseek,
|
.llseek = no_llseek,
|
||||||
.write = advwdt_write,
|
.write = advwdt_write,
|
||||||
.ioctl = advwdt_ioctl,
|
.unlocked_ioctl = advwdt_ioctl,
|
||||||
.open = advwdt_open,
|
.open = advwdt_open,
|
||||||
.release = advwdt_close,
|
.release = advwdt_close,
|
||||||
};
|
};
|
||||||
|
@ -245,23 +237,24 @@ static struct miscdevice advwdt_miscdev = {
|
||||||
* Init & exit routines
|
* Init & exit routines
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int __devinit
|
static int __devinit advwdt_probe(struct platform_device *dev)
|
||||||
advwdt_probe(struct platform_device *dev)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (wdt_stop != wdt_start) {
|
if (wdt_stop != wdt_start) {
|
||||||
if (!request_region(wdt_stop, 1, WATCHDOG_NAME)) {
|
if (!request_region(wdt_stop, 1, WATCHDOG_NAME)) {
|
||||||
printk (KERN_ERR PFX "I/O address 0x%04x already in use\n",
|
printk(KERN_ERR PFX
|
||||||
wdt_stop);
|
"I/O address 0x%04x already in use\n",
|
||||||
|
wdt_stop);
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!request_region(wdt_start, 1, WATCHDOG_NAME)) {
|
if (!request_region(wdt_start, 1, WATCHDOG_NAME)) {
|
||||||
printk (KERN_ERR PFX "I/O address 0x%04x already in use\n",
|
printk(KERN_ERR PFX
|
||||||
wdt_start);
|
"I/O address 0x%04x already in use\n",
|
||||||
|
wdt_start);
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto unreg_stop;
|
goto unreg_stop;
|
||||||
}
|
}
|
||||||
|
@ -269,20 +262,19 @@ advwdt_probe(struct platform_device *dev)
|
||||||
/* Check that the heartbeat value is within it's range ; if not reset to the default */
|
/* Check that the heartbeat value is within it's range ; if not reset to the default */
|
||||||
if (advwdt_set_heartbeat(timeout)) {
|
if (advwdt_set_heartbeat(timeout)) {
|
||||||
advwdt_set_heartbeat(WATCHDOG_TIMEOUT);
|
advwdt_set_heartbeat(WATCHDOG_TIMEOUT);
|
||||||
printk (KERN_INFO PFX "timeout value must be 1<=x<=63, using %d\n",
|
printk(KERN_INFO PFX
|
||||||
timeout);
|
"timeout value must be 1<=x<=63, using %d\n", timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = misc_register(&advwdt_miscdev);
|
ret = misc_register(&advwdt_miscdev);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
|
printk(KERN_ERR PFX
|
||||||
WATCHDOG_MINOR, ret);
|
"cannot register miscdev on minor=%d (err=%d)\n",
|
||||||
|
WATCHDOG_MINOR, ret);
|
||||||
goto unreg_regions;
|
goto unreg_regions;
|
||||||
}
|
}
|
||||||
|
printk(KERN_INFO PFX "initialized. timeout=%d sec (nowayout=%d)\n",
|
||||||
printk (KERN_INFO PFX "initialized. timeout=%d sec (nowayout=%d)\n",
|
|
||||||
timeout, nowayout);
|
timeout, nowayout);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
return ret;
|
return ret;
|
||||||
unreg_regions:
|
unreg_regions:
|
||||||
|
@ -293,8 +285,7 @@ unreg_stop:
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __devexit
|
static int __devexit advwdt_remove(struct platform_device *dev)
|
||||||
advwdt_remove(struct platform_device *dev)
|
|
||||||
{
|
{
|
||||||
misc_deregister(&advwdt_miscdev);
|
misc_deregister(&advwdt_miscdev);
|
||||||
release_region(wdt_start,1);
|
release_region(wdt_start,1);
|
||||||
|
@ -304,8 +295,7 @@ advwdt_remove(struct platform_device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void advwdt_shutdown(struct platform_device *dev)
|
||||||
advwdt_shutdown(struct platform_device *dev)
|
|
||||||
{
|
{
|
||||||
/* Turn the WDT off if we have a soft shutdown */
|
/* Turn the WDT off if we have a soft shutdown */
|
||||||
advwdt_disable();
|
advwdt_disable();
|
||||||
|
@ -321,8 +311,7 @@ static struct platform_driver advwdt_driver = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static int __init
|
static int __init advwdt_init(void)
|
||||||
advwdt_init(void)
|
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
@ -332,7 +321,8 @@ advwdt_init(void)
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
advwdt_platform_device = platform_device_register_simple(DRV_NAME, -1, NULL, 0);
|
advwdt_platform_device = platform_device_register_simple(DRV_NAME,
|
||||||
|
-1, NULL, 0);
|
||||||
if (IS_ERR(advwdt_platform_device)) {
|
if (IS_ERR(advwdt_platform_device)) {
|
||||||
err = PTR_ERR(advwdt_platform_device);
|
err = PTR_ERR(advwdt_platform_device);
|
||||||
goto unreg_platform_driver;
|
goto unreg_platform_driver;
|
||||||
|
@ -345,8 +335,7 @@ unreg_platform_driver:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit
|
static void __exit advwdt_exit(void)
|
||||||
advwdt_exit(void)
|
|
||||||
{
|
{
|
||||||
platform_device_unregister(advwdt_platform_device);
|
platform_device_unregister(advwdt_platform_device);
|
||||||
platform_driver_unregister(&advwdt_driver);
|
platform_driver_unregister(&advwdt_driver);
|
||||||
|
|
Loading…
Reference in New Issue