Commit 9f2d1f0da766f84fdb96c9bd79ed0f97036635cb

Authored by Alan Cox
Committed by Linus Torvalds
1 parent 41dc8b72e3

wdt: Cleanup and sort out locking and inb_p

Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 2 changed files with 265 additions and 211 deletions Side-by-side Diff

drivers/watchdog/wdt.c
... ... @@ -24,9 +24,10 @@
24 24 * Matt Crocker).
25 25 * Alan Cox : Added wdt= boot option
26 26 * Alan Cox : Cleaned up copy/user stuff
27   - * Tim Hockin : Added insmod parameters, comment cleanup
28   - * Parameterized timeout
29   - * Tigran Aivazian : Restructured wdt_init() to handle failures
  27 + * Tim Hockin : Added insmod parameters, comment
  28 + * cleanup, parameterized timeout
  29 + * Tigran Aivazian : Restructured wdt_init() to handle
  30 + * failures
30 31 * Joel Becker : Added WDIOC_GET/SETTIMEOUT
31 32 * Matt Domsch : Added nowayout module option
32 33 */
33 34  
... ... @@ -42,9 +43,9 @@
42 43 #include <linux/notifier.h>
43 44 #include <linux/reboot.h>
44 45 #include <linux/init.h>
  46 +#include <linux/io.h>
  47 +#include <linux/uaccess.h>
45 48  
46   -#include <asm/io.h>
47   -#include <asm/uaccess.h>
48 49 #include <asm/system.h>
49 50 #include "wd501p.h"
50 51  
51 52  
52 53  
... ... @@ -60,15 +61,19 @@
60 61 static int heartbeat = WD_TIMO;
61 62 static int wd_heartbeat;
62 63 module_param(heartbeat, int, 0);
63   -MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (0<heartbeat<65536, default=" __MODULE_STRING(WD_TIMO) ")");
  64 +MODULE_PARM_DESC(heartbeat,
  65 + "Watchdog heartbeat in seconds. (0 < heartbeat < 65536, default="
  66 + __MODULE_STRING(WD_TIMO) ")");
64 67  
65 68 static int nowayout = WATCHDOG_NOWAYOUT;
66 69 module_param(nowayout, int, 0);
67   -MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  70 +MODULE_PARM_DESC(nowayout,
  71 + "Watchdog cannot be stopped once started (default="
  72 + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
68 73  
69 74 /* You must set these - there is no sane way to probe for this board. */
70   -static int io=0x240;
71   -static int irq=11;
  75 +static int io = 0x240;
  76 +static int irq = 11;
72 77  
73 78 static DEFINE_SPINLOCK(wdt_lock);
74 79  
... ... @@ -82,7 +87,8 @@
82 87 static int tachometer;
83 88  
84 89 module_param(tachometer, int, 0);
85   -MODULE_PARM_DESC(tachometer, "WDT501-P Fan Tachometer support (0=disable, default=0)");
  90 +MODULE_PARM_DESC(tachometer,
  91 + "WDT501-P Fan Tachometer support (0=disable, default=0)");
86 92 #endif /* CONFIG_WDT_501 */
87 93  
88 94 /*
... ... @@ -91,9 +97,9 @@
91 97  
92 98 static void wdt_ctr_mode(int ctr, int mode)
93 99 {
94   - ctr<<=6;
95   - ctr|=0x30;
96   - ctr|=(mode<<1);
  100 + ctr <<= 6;
  101 + ctr |= 0x30;
  102 + ctr |= (mode << 1);
97 103 outb_p(ctr, WDT_CR);
98 104 }
99 105  
100 106  
... ... @@ -114,12 +120,15 @@
114 120 unsigned long flags;
115 121 spin_lock_irqsave(&wdt_lock, flags);
116 122 inb_p(WDT_DC); /* Disable watchdog */
117   - wdt_ctr_mode(0,3); /* Program CTR0 for Mode 3: Square Wave Generator */
118   - wdt_ctr_mode(1,2); /* Program CTR1 for Mode 2: Rate Generator */
119   - wdt_ctr_mode(2,0); /* Program CTR2 for Mode 0: Pulse on Terminal Count */
  123 + wdt_ctr_mode(0, 3); /* Program CTR0 for Mode 3:
  124 + Square Wave Generator */
  125 + wdt_ctr_mode(1, 2); /* Program CTR1 for Mode 2:
  126 + Rate Generator */
  127 + wdt_ctr_mode(2, 0); /* Program CTR2 for Mode 0:
  128 + Pulse on Terminal Count */
120 129 wdt_ctr_load(0, 8948); /* Count at 100Hz */
121   - wdt_ctr_load(1,wd_heartbeat); /* Heartbeat */
122   - wdt_ctr_load(2,65535); /* Length of reset pulse */
  130 + wdt_ctr_load(1, wd_heartbeat); /* Heartbeat */
  131 + wdt_ctr_load(2, 65535); /* Length of reset pulse */
123 132 outb_p(0, WDT_DC); /* Enable watchdog */
124 133 spin_unlock_irqrestore(&wdt_lock, flags);
125 134 return 0;
126 135  
... ... @@ -131,13 +140,13 @@
131 140 * Stop the watchdog driver.
132 141 */
133 142  
134   -static int wdt_stop (void)
  143 +static int wdt_stop(void)
135 144 {
136 145 unsigned long flags;
137 146 spin_lock_irqsave(&wdt_lock, flags);
138 147 /* Turn the card off */
139 148 inb_p(WDT_DC); /* Disable watchdog */
140   - wdt_ctr_load(2,0); /* 0 length reset pulses now */
  149 + wdt_ctr_load(2, 0); /* 0 length reset pulses now */
141 150 spin_unlock_irqrestore(&wdt_lock, flags);
142 151 return 0;
143 152 }
... ... @@ -145,8 +154,8 @@
145 154 /**
146 155 * wdt_ping:
147 156 *
148   - * Reload counter one with the watchdog heartbeat. We don't bother reloading
149   - * the cascade counter.
  157 + * Reload counter one with the watchdog heartbeat. We don't bother
  158 + * reloading the cascade counter.
150 159 */
151 160  
152 161 static int wdt_ping(void)
... ... @@ -155,8 +164,9 @@
155 164 spin_lock_irqsave(&wdt_lock, flags);
156 165 /* Write a watchdog value */
157 166 inb_p(WDT_DC); /* Disable watchdog */
158   - wdt_ctr_mode(1,2); /* Re-Program CTR1 for Mode 2: Rate Generator */
159   - wdt_ctr_load(1,wd_heartbeat); /* Heartbeat */
  167 + wdt_ctr_mode(1, 2); /* Re-Program CTR1 for Mode 2:
  168 + Rate Generator */
  169 + wdt_ctr_load(1, wd_heartbeat); /* Heartbeat */
160 170 outb_p(0, WDT_DC); /* Enable watchdog */
161 171 spin_unlock_irqrestore(&wdt_lock, flags);
162 172 return 0;
163 173  
164 174  
... ... @@ -166,13 +176,14 @@
166 176 * wdt_set_heartbeat:
167 177 * @t: the new heartbeat value that needs to be set.
168 178 *
169   - * Set a new heartbeat value for the watchdog device. If the heartbeat value is
170   - * incorrect we keep the old value and return -EINVAL. If successfull we
171   - * return 0.
  179 + * Set a new heartbeat value for the watchdog device. If the heartbeat
  180 + * value is incorrect we keep the old value and return -EINVAL. If
  181 + * successful we return 0.
172 182 */
  183 +
173 184 static int wdt_set_heartbeat(int t)
174 185 {
175   - if ((t < 1) || (t > 65535))
  186 + if (t < 1 || t > 65535)
176 187 return -EINVAL;
177 188  
178 189 heartbeat = t;
... ... @@ -200,7 +211,7 @@
200 211 new_status = inb_p(WDT_SR);
201 212 spin_unlock_irqrestore(&wdt_lock, flags);
202 213  
203   - *status=0;
  214 + *status = 0;
204 215 if (new_status & WDC_SR_ISOI0)
205 216 *status |= WDIOF_EXTERN1;
206 217 if (new_status & WDC_SR_ISII1)
... ... @@ -266,7 +277,7 @@
266 277  
267 278 #ifdef CONFIG_WDT_501
268 279 if (!(status & WDC_SR_TGOOD))
269   - printk(KERN_CRIT "Overheat alarm.(%d)\n",inb_p(WDT_RT));
  280 + printk(KERN_CRIT "Overheat alarm.(%d)\n", inb_p(WDT_RT));
270 281 if (!(status & WDC_SR_PSUOVER))
271 282 printk(KERN_CRIT "PSU over voltage.\n");
272 283 if (!(status & WDC_SR_PSUUNDR))
273 284  
... ... @@ -304,9 +315,10 @@
304 315 * write of data will do, as we we don't define content meaning.
305 316 */
306 317  
307   -static ssize_t wdt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
  318 +static ssize_t wdt_write(struct file *file, const char __user *buf,
  319 + size_t count, loff_t *ppos)
308 320 {
309   - if(count) {
  321 + if (count) {
310 322 if (!nowayout) {
311 323 size_t i;
312 324  
... ... @@ -328,7 +340,6 @@
328 340  
329 341 /**
330 342 * wdt_ioctl:
331   - * @inode: inode of the device
332 343 * @file: file handle to the device
333 344 * @cmd: watchdog command
334 345 * @arg: argument pointer
... ... @@ -338,8 +349,7 @@
338 349 * querying capabilities and current status.
339 350 */
340 351  
341   -static int wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
342   - unsigned long arg)
  352 +static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
343 353 {
344 354 void __user *argp = (void __user *)arg;
345 355 int __user *p = argp;
... ... @@ -362,32 +372,28 @@
362 372 ident.options |= WDIOF_FANFAULT;
363 373 #endif /* CONFIG_WDT_501 */
364 374  
365   - switch(cmd)
366   - {
367   - default:
368   - return -ENOTTY;
369   - case WDIOC_GETSUPPORT:
370   - return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0;
371   -
372   - case WDIOC_GETSTATUS:
373   - wdt_get_status(&status);
374   - return put_user(status, p);
375   - case WDIOC_GETBOOTSTATUS:
376   - return put_user(0, p);
377   - case WDIOC_KEEPALIVE:
378   - wdt_ping();
379   - return 0;
380   - case WDIOC_SETTIMEOUT:
381   - if (get_user(new_heartbeat, p))
382   - return -EFAULT;
383   -
384   - if (wdt_set_heartbeat(new_heartbeat))
385   - return -EINVAL;
386   -
387   - wdt_ping();
388   - /* Fall */
389   - case WDIOC_GETTIMEOUT:
390   - return put_user(heartbeat, p);
  375 + switch (cmd) {
  376 + default:
  377 + return -ENOTTY;
  378 + case WDIOC_GETSUPPORT:
  379 + return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
  380 + case WDIOC_GETSTATUS:
  381 + wdt_get_status(&status);
  382 + return put_user(status, p);
  383 + case WDIOC_GETBOOTSTATUS:
  384 + return put_user(0, p);
  385 + case WDIOC_KEEPALIVE:
  386 + wdt_ping();
  387 + return 0;
  388 + case WDIOC_SETTIMEOUT:
  389 + if (get_user(new_heartbeat, p))
  390 + return -EFAULT;
  391 + if (wdt_set_heartbeat(new_heartbeat))
  392 + return -EINVAL;
  393 + wdt_ping();
  394 + /* Fall */
  395 + case WDIOC_GETTIMEOUT:
  396 + return put_user(heartbeat, p);
391 397 }
392 398 }
393 399  
... ... @@ -405,7 +411,7 @@
405 411  
406 412 static int wdt_open(struct inode *inode, struct file *file)
407 413 {
408   - if(test_and_set_bit(0, &wdt_is_open))
  414 + if (test_and_set_bit(0, &wdt_is_open))
409 415 return -EBUSY;
410 416 /*
411 417 * Activate
... ... @@ -432,7 +438,8 @@
432 438 wdt_stop();
433 439 clear_bit(0, &wdt_is_open);
434 440 } else {
435   - printk(KERN_CRIT "wdt: WDT device closed unexpectedly. WDT will not stop!\n");
  441 + printk(KERN_CRIT
  442 + "wdt: WDT device closed unexpectedly. WDT will not stop!\n");
436 443 wdt_ping();
437 444 }
438 445 expect_close = 0;
439 446  
... ... @@ -451,14 +458,15 @@
451 458 * farenheit. It was designed by an imperial measurement luddite.
452 459 */
453 460  
454   -static ssize_t wdt_temp_read(struct file *file, char __user *buf, size_t count, loff_t *ptr)
  461 +static ssize_t wdt_temp_read(struct file *file, char __user *buf,
  462 + size_t count, loff_t *ptr)
455 463 {
456 464 int temperature;
457 465  
458 466 if (wdt_get_temperature(&temperature))
459 467 return -EFAULT;
460 468  
461   - if (copy_to_user (buf, &temperature, 1))
  469 + if (copy_to_user(buf, &temperature, 1))
462 470 return -EFAULT;
463 471  
464 472 return 1;
465 473  
... ... @@ -506,10 +514,8 @@
506 514 static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
507 515 void *unused)
508 516 {
509   - if(code==SYS_DOWN || code==SYS_HALT) {
510   - /* Turn the card off */
  517 + if (code == SYS_DOWN || code == SYS_HALT)
511 518 wdt_stop();
512   - }
513 519 return NOTIFY_DONE;
514 520 }
515 521  
... ... @@ -522,7 +528,7 @@
522 528 .owner = THIS_MODULE,
523 529 .llseek = no_llseek,
524 530 .write = wdt_write,
525   - .ioctl = wdt_ioctl,
  531 + .unlocked_ioctl = wdt_ioctl,
526 532 .open = wdt_open,
527 533 .release = wdt_release,
528 534 };
... ... @@ -576,7 +582,7 @@
576 582 #endif /* CONFIG_WDT_501 */
577 583 unregister_reboot_notifier(&wdt_notifier);
578 584 free_irq(irq, NULL);
579   - release_region(io,8);
  585 + release_region(io, 8);
580 586 }
581 587  
582 588 /**
583 589  
584 590  
585 591  
586 592  
587 593  
588 594  
... ... @@ -591,44 +597,49 @@
591 597 {
592 598 int ret;
593 599  
594   - /* Check that the heartbeat value is within it's range ; if not reset to the default */
  600 + /* Check that the heartbeat value is within it's range;
  601 + if not reset to the default */
595 602 if (wdt_set_heartbeat(heartbeat)) {
596 603 wdt_set_heartbeat(WD_TIMO);
597   - printk(KERN_INFO "wdt: heartbeat value must be 0<heartbeat<65536, using %d\n",
  604 + printk(KERN_INFO "wdt: heartbeat value must be 0 < heartbeat < 65536, using %d\n",
598 605 WD_TIMO);
599 606 }
600 607  
601 608 if (!request_region(io, 8, "wdt501p")) {
602   - printk(KERN_ERR "wdt: I/O address 0x%04x already in use\n", io);
  609 + printk(KERN_ERR
  610 + "wdt: I/O address 0x%04x already in use\n", io);
603 611 ret = -EBUSY;
604 612 goto out;
605 613 }
606 614  
607 615 ret = request_irq(irq, wdt_interrupt, IRQF_DISABLED, "wdt501p", NULL);
608   - if(ret) {
  616 + if (ret) {
609 617 printk(KERN_ERR "wdt: IRQ %d is not free.\n", irq);
610 618 goto outreg;
611 619 }
612 620  
613 621 ret = register_reboot_notifier(&wdt_notifier);
614   - if(ret) {
615   - printk(KERN_ERR "wdt: cannot register reboot notifier (err=%d)\n", ret);
  622 + if (ret) {
  623 + printk(KERN_ERR
  624 + "wdt: cannot register reboot notifier (err=%d)\n", ret);
616 625 goto outirq;
617 626 }
618 627  
619 628 #ifdef CONFIG_WDT_501
620 629 ret = misc_register(&temp_miscdev);
621 630 if (ret) {
622   - printk(KERN_ERR "wdt: cannot register miscdev on minor=%d (err=%d)\n",
623   - TEMP_MINOR, ret);
  631 + printk(KERN_ERR
  632 + "wdt: cannot register miscdev on minor=%d (err=%d)\n",
  633 + TEMP_MINOR, ret);
624 634 goto outrbt;
625 635 }
626 636 #endif /* CONFIG_WDT_501 */
627 637  
628 638 ret = misc_register(&wdt_miscdev);
629 639 if (ret) {
630   - printk(KERN_ERR "wdt: cannot register miscdev on minor=%d (err=%d)\n",
631   - WATCHDOG_MINOR, ret);
  640 + printk(KERN_ERR
  641 + "wdt: cannot register miscdev on minor=%d (err=%d)\n",
  642 + WATCHDOG_MINOR, ret);
632 643 goto outmisc;
633 644 }
634 645  
... ... @@ -636,7 +647,8 @@
636 647 printk(KERN_INFO "WDT500/501-P driver 0.10 at 0x%04x (Interrupt %d). heartbeat=%d sec (nowayout=%d)\n",
637 648 io, irq, heartbeat, nowayout);
638 649 #ifdef CONFIG_WDT_501
639   - printk(KERN_INFO "wdt: Fan Tachometer is %s\n", (tachometer ? "Enabled" : "Disabled"));
  650 + printk(KERN_INFO "wdt: Fan Tachometer is %s\n",
  651 + (tachometer ? "Enabled" : "Disabled"));
640 652 #endif /* CONFIG_WDT_501 */
641 653  
642 654 out:
... ... @@ -651,7 +663,7 @@
651 663 outirq:
652 664 free_irq(irq, NULL);
653 665 outreg:
654   - release_region(io,8);
  666 + release_region(io, 8);
655 667 goto out;
656 668 }
657 669  
drivers/watchdog/wdt_pci.c
... ... @@ -29,9 +29,11 @@
29 29 * JP Nollmann : Added support for PCI wdt501p
30 30 * Alan Cox : Split ISA and PCI cards into two drivers
31 31 * Jeff Garzik : PCI cleanups
32   - * Tigran Aivazian : Restructured wdtpci_init_one() to handle failures
  32 + * Tigran Aivazian : Restructured wdtpci_init_one() to handle
  33 + * failures
33 34 * Joel Becker : Added WDIOC_GET/SETTIMEOUT
34   - * Zwane Mwaikambo : Magic char closing, locking changes, cleanups
  35 + * Zwane Mwaikambo : Magic char closing, locking changes,
  36 + * cleanups
35 37 * Matt Domsch : nowayout module option
36 38 */
37 39  
38 40  
... ... @@ -47,9 +49,9 @@
47 49 #include <linux/init.h>
48 50 #include <linux/fs.h>
49 51 #include <linux/pci.h>
  52 +#include <linux/io.h>
  53 +#include <linux/uaccess.h>
50 54  
51   -#include <asm/io.h>
52   -#include <asm/uaccess.h>
53 55 #include <asm/system.h>
54 56  
55 57 #define WDT_IS_PCI
... ... @@ -73,7 +75,7 @@
73 75 /* We can only use 1 card due to the /dev/watchdog restriction */
74 76 static int dev_count;
75 77  
76   -static struct semaphore open_sem;
  78 +static unsigned long open_lock;
77 79 static DEFINE_SPINLOCK(wdtpci_lock);
78 80 static char expect_close;
79 81  
80 82  
81 83  
... ... @@ -86,18 +88,23 @@
86 88 static int heartbeat = WD_TIMO;
87 89 static int wd_heartbeat;
88 90 module_param(heartbeat, int, 0);
89   -MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (0<heartbeat<65536, default=" __MODULE_STRING(WD_TIMO) ")");
  91 +MODULE_PARM_DESC(heartbeat,
  92 + "Watchdog heartbeat in seconds. (0<heartbeat<65536, default="
  93 + __MODULE_STRING(WD_TIMO) ")");
90 94  
91 95 static int nowayout = WATCHDOG_NOWAYOUT;
92 96 module_param(nowayout, int, 0);
93   -MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  97 +MODULE_PARM_DESC(nowayout,
  98 + "Watchdog cannot be stopped once started (default="
  99 + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
94 100  
95 101 #ifdef CONFIG_WDT_501_PCI
96 102 /* Support for the Fan Tachometer on the PCI-WDT501 */
97 103 static int tachometer;
98 104  
99 105 module_param(tachometer, int, 0);
100   -MODULE_PARM_DESC(tachometer, "PCI-WDT501 Fan Tachometer support (0=disable, default=0)");
  106 +MODULE_PARM_DESC(tachometer,
  107 + "PCI-WDT501 Fan Tachometer support (0=disable, default=0)");
101 108 #endif /* CONFIG_WDT_501_PCI */
102 109  
103 110 /*
104 111  
... ... @@ -106,16 +113,19 @@
106 113  
107 114 static void wdtpci_ctr_mode(int ctr, int mode)
108 115 {
109   - ctr<<=6;
110   - ctr|=0x30;
111   - ctr|=(mode<<1);
112   - outb_p(ctr, WDT_CR);
  116 + ctr <<= 6;
  117 + ctr |= 0x30;
  118 + ctr |= (mode << 1);
  119 + outb(ctr, WDT_CR);
  120 + udelay(8);
113 121 }
114 122  
115 123 static void wdtpci_ctr_load(int ctr, int val)
116 124 {
117   - outb_p(val&0xFF, WDT_COUNT0+ctr);
118   - outb_p(val>>8, WDT_COUNT0+ctr);
  125 + outb(val & 0xFF, WDT_COUNT0 + ctr);
  126 + udelay(8);
  127 + outb(val >> 8, WDT_COUNT0 + ctr);
  128 + udelay(8);
119 129 }
120 130  
121 131 /**
122 132  
... ... @@ -134,23 +144,35 @@
134 144 * "pet" the watchdog, as Access says.
135 145 * This resets the clock outputs.
136 146 */
137   - inb_p(WDT_DC); /* Disable watchdog */
138   - wdtpci_ctr_mode(2,0); /* Program CTR2 for Mode 0: Pulse on Terminal Count */
139   - outb_p(0, WDT_DC); /* Enable watchdog */
140   -
141   - inb_p(WDT_DC); /* Disable watchdog */
142   - outb_p(0, WDT_CLOCK); /* 2.0833MHz clock */
143   - inb_p(WDT_BUZZER); /* disable */
144   - inb_p(WDT_OPTONOTRST); /* disable */
145   - inb_p(WDT_OPTORST); /* disable */
146   - inb_p(WDT_PROGOUT); /* disable */
147   - wdtpci_ctr_mode(0,3); /* Program CTR0 for Mode 3: Square Wave Generator */
148   - wdtpci_ctr_mode(1,2); /* Program CTR1 for Mode 2: Rate Generator */
149   - wdtpci_ctr_mode(2,1); /* Program CTR2 for Mode 1: Retriggerable One-Shot */
150   - wdtpci_ctr_load(0,20833); /* count at 100Hz */
151   - wdtpci_ctr_load(1,wd_heartbeat);/* Heartbeat */
  147 + inb(WDT_DC); /* Disable watchdog */
  148 + udelay(8);
  149 + wdtpci_ctr_mode(2, 0); /* Program CTR2 for Mode 0:
  150 + Pulse on Terminal Count */
  151 + outb(0, WDT_DC); /* Enable watchdog */
  152 + udelay(8);
  153 + inb(WDT_DC); /* Disable watchdog */
  154 + udelay(8);
  155 + outb(0, WDT_CLOCK); /* 2.0833MHz clock */
  156 + udelay(8);
  157 + inb(WDT_BUZZER); /* disable */
  158 + udelay(8);
  159 + inb(WDT_OPTONOTRST); /* disable */
  160 + udelay(8);
  161 + inb(WDT_OPTORST); /* disable */
  162 + udelay(8);
  163 + inb(WDT_PROGOUT); /* disable */
  164 + udelay(8);
  165 + wdtpci_ctr_mode(0, 3); /* Program CTR0 for Mode 3:
  166 + Square Wave Generator */
  167 + wdtpci_ctr_mode(1, 2); /* Program CTR1 for Mode 2:
  168 + Rate Generator */
  169 + wdtpci_ctr_mode(2, 1); /* Program CTR2 for Mode 1:
  170 + Retriggerable One-Shot */
  171 + wdtpci_ctr_load(0, 20833); /* count at 100Hz */
  172 + wdtpci_ctr_load(1, wd_heartbeat);/* Heartbeat */
152 173 /* DO NOT LOAD CTR2 on PCI card! -- JPN */
153   - outb_p(0, WDT_DC); /* Enable watchdog */
  174 + outb(0, WDT_DC); /* Enable watchdog */
  175 + udelay(8);
154 176  
155 177 spin_unlock_irqrestore(&wdtpci_lock, flags);
156 178 return 0;
157 179  
... ... @@ -162,14 +184,15 @@
162 184 * Stop the watchdog driver.
163 185 */
164 186  
165   -static int wdtpci_stop (void)
  187 +static int wdtpci_stop(void)
166 188 {
167 189 unsigned long flags;
168 190  
169 191 /* Turn the card off */
170 192 spin_lock_irqsave(&wdtpci_lock, flags);
171   - inb_p(WDT_DC); /* Disable watchdog */
172   - wdtpci_ctr_load(2,0); /* 0 length reset pulses now */
  193 + inb(WDT_DC); /* Disable watchdog */
  194 + udelay(8);
  195 + wdtpci_ctr_load(2, 0); /* 0 length reset pulses now */
173 196 spin_unlock_irqrestore(&wdtpci_lock, flags);
174 197 return 0;
175 198 }
176 199  
177 200  
... ... @@ -177,20 +200,23 @@
177 200 /**
178 201 * wdtpci_ping:
179 202 *
180   - * Reload counter one with the watchdog heartbeat. We don't bother reloading
181   - * the cascade counter.
  203 + * Reload counter one with the watchdog heartbeat. We don't bother
  204 + * reloading the cascade counter.
182 205 */
183 206  
184 207 static int wdtpci_ping(void)
185 208 {
186 209 unsigned long flags;
187 210  
188   - /* Write a watchdog value */
189 211 spin_lock_irqsave(&wdtpci_lock, flags);
190   - inb_p(WDT_DC); /* Disable watchdog */
191   - wdtpci_ctr_mode(1,2); /* Re-Program CTR1 for Mode 2: Rate Generator */
192   - wdtpci_ctr_load(1,wd_heartbeat);/* Heartbeat */
193   - outb_p(0, WDT_DC); /* Enable watchdog */
  212 + /* Write a watchdog value */
  213 + inb(WDT_DC); /* Disable watchdog */
  214 + udelay(8);
  215 + wdtpci_ctr_mode(1, 2); /* Re-Program CTR1 for Mode 2:
  216 + Rate Generator */
  217 + wdtpci_ctr_load(1, wd_heartbeat);/* Heartbeat */
  218 + outb(0, WDT_DC); /* Enable watchdog */
  219 + udelay(8);
194 220 spin_unlock_irqrestore(&wdtpci_lock, flags);
195 221 return 0;
196 222 }
197 223  
... ... @@ -199,14 +225,14 @@
199 225 * wdtpci_set_heartbeat:
200 226 * @t: the new heartbeat value that needs to be set.
201 227 *
202   - * Set a new heartbeat value for the watchdog device. If the heartbeat value is
203   - * incorrect we keep the old value and return -EINVAL. If successfull we
204   - * return 0.
  228 + * Set a new heartbeat value for the watchdog device. If the heartbeat
  229 + * value is incorrect we keep the old value and return -EINVAL.
  230 + * If successful we return 0.
205 231 */
206 232 static int wdtpci_set_heartbeat(int t)
207 233 {
208 234 /* Arbitrary, can't find the card's limits */
209   - if ((t < 1) || (t > 65535))
  235 + if (t < 1 || t > 65535)
210 236 return -EINVAL;
211 237  
212 238 heartbeat = t;
213 239  
... ... @@ -227,9 +253,14 @@
227 253  
228 254 static int wdtpci_get_status(int *status)
229 255 {
230   - unsigned char new_status=inb_p(WDT_SR);
  256 + unsigned char new_status;
  257 + unsigned long flags;
231 258  
232   - *status=0;
  259 + spin_lock_irqsave(&wdtpci_lock, flags);
  260 + new_status = inb(WDT_SR);
  261 + spin_unlock_irqrestore(&wdtpci_lock, flags);
  262 +
  263 + *status = 0;
233 264 if (new_status & WDC_SR_ISOI0)
234 265 *status |= WDIOF_EXTERN1;
235 266 if (new_status & WDC_SR_ISII1)
... ... @@ -259,8 +290,12 @@
259 290  
260 291 static int wdtpci_get_temperature(int *temperature)
261 292 {
262   - unsigned short c=inb_p(WDT_RT);
263   -
  293 + unsigned short c;
  294 + unsigned long flags;
  295 + spin_lock_irqsave(&wdtpci_lock, flags);
  296 + c = inb(WDT_RT);
  297 + udelay(8);
  298 + spin_unlock_irqrestore(&wdtpci_lock, flags);
264 299 *temperature = (c * 11 / 15) + 7;
265 300 return 0;
266 301 }
267 302  
268 303  
269 304  
270 305  
... ... @@ -282,17 +317,25 @@
282 317 * Read the status register see what is up and
283 318 * then printk it.
284 319 */
285   - unsigned char status=inb_p(WDT_SR);
  320 + unsigned char status;
286 321  
  322 + spin_lock(&wdtpci_lock);
  323 +
  324 + status = inb(WDT_SR);
  325 + udelay(8);
  326 +
287 327 printk(KERN_CRIT PFX "status %d\n", status);
288 328  
289 329 #ifdef CONFIG_WDT_501_PCI
290   - if (!(status & WDC_SR_TGOOD))
291   - printk(KERN_CRIT PFX "Overheat alarm.(%d)\n",inb_p(WDT_RT));
  330 + if (!(status & WDC_SR_TGOOD)) {
  331 + u8 alarm = inb(WDT_RT);
  332 + printk(KERN_CRIT PFX "Overheat alarm.(%d)\n", alarm);
  333 + udelay(8);
  334 + }
292 335 if (!(status & WDC_SR_PSUOVER))
293   - printk(KERN_CRIT PFX "PSU over voltage.\n");
  336 + printk(KERN_CRIT PFX "PSU over voltage.\n");
294 337 if (!(status & WDC_SR_PSUUNDR))
295   - printk(KERN_CRIT PFX "PSU under voltage.\n");
  338 + printk(KERN_CRIT PFX "PSU under voltage.\n");
296 339 if (tachometer) {
297 340 if (!(status & WDC_SR_FANGOOD))
298 341 printk(KERN_CRIT PFX "Possible fan fault.\n");
... ... @@ -310,6 +353,7 @@
310 353 printk(KERN_CRIT PFX "Reset in 5ms.\n");
311 354 #endif
312 355 }
  356 + spin_unlock(&wdtpci_lock);
313 357 return IRQ_HANDLED;
314 358 }
315 359  
... ... @@ -325,7 +369,8 @@
325 369 * write of data will do, as we we don't define content meaning.
326 370 */
327 371  
328   -static ssize_t wdtpci_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
  372 +static ssize_t wdtpci_write(struct file *file, const char __user *buf,
  373 + size_t count, loff_t *ppos)
329 374 {
330 375 if (count) {
331 376 if (!nowayout) {
... ... @@ -335,7 +380,7 @@
335 380  
336 381 for (i = 0; i != count; i++) {
337 382 char c;
338   - if(get_user(c, buf+i))
  383 + if (get_user(c, buf+i))
339 384 return -EFAULT;
340 385 if (c == 'V')
341 386 expect_close = 42;
342 387  
... ... @@ -343,13 +388,11 @@
343 388 }
344 389 wdtpci_ping();
345 390 }
346   -
347 391 return count;
348 392 }
349 393  
350 394 /**
351 395 * wdtpci_ioctl:
352   - * @inode: inode of the device
353 396 * @file: file handle to the device
354 397 * @cmd: watchdog command
355 398 * @arg: argument pointer
... ... @@ -359,8 +402,8 @@
359 402 * querying capabilities and current status.
360 403 */
361 404  
362   -static int wdtpci_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
363   - unsigned long arg)
  405 +static long wdtpci_ioctl(struct file *file, unsigned int cmd,
  406 + unsigned long arg)
364 407 {
365 408 int new_heartbeat;
366 409 int status;
... ... @@ -383,33 +426,29 @@
383 426 ident.options |= WDIOF_FANFAULT;
384 427 #endif /* CONFIG_WDT_501_PCI */
385 428  
386   - switch(cmd)
387   - {
388   - default:
389   - return -ENOTTY;
390   - case WDIOC_GETSUPPORT:
391   - return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0;
392   -
393   - case WDIOC_GETSTATUS:
394   - wdtpci_get_status(&status);
395   - return put_user(status, p);
396   - case WDIOC_GETBOOTSTATUS:
397   - return put_user(0, p);
398   - case WDIOC_KEEPALIVE:
399   - wdtpci_ping();
400   - return 0;
401   - case WDIOC_SETTIMEOUT:
402   - if (get_user(new_heartbeat, p))
403   - return -EFAULT;
404   -
405   - if (wdtpci_set_heartbeat(new_heartbeat))
406   - return -EINVAL;
407   -
408   - wdtpci_ping();
409   - /* Fall */
410   - case WDIOC_GETTIMEOUT:
411   - return put_user(heartbeat, p);
412   - }
  429 + switch (cmd) {
  430 + default:
  431 + return -ENOTTY;
  432 + case WDIOC_GETSUPPORT:
  433 + return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
  434 + case WDIOC_GETSTATUS:
  435 + wdtpci_get_status(&status);
  436 + return put_user(status, p);
  437 + case WDIOC_GETBOOTSTATUS:
  438 + return put_user(0, p);
  439 + case WDIOC_KEEPALIVE:
  440 + wdtpci_ping();
  441 + return 0;
  442 + case WDIOC_SETTIMEOUT:
  443 + if (get_user(new_heartbeat, p))
  444 + return -EFAULT;
  445 + if (wdtpci_set_heartbeat(new_heartbeat))
  446 + return -EINVAL;
  447 + wdtpci_ping();
  448 + /* Fall */
  449 + case WDIOC_GETTIMEOUT:
  450 + return put_user(heartbeat, p);
  451 + }
413 452 }
414 453  
415 454 /**
416 455  
417 456  
... ... @@ -426,12 +465,11 @@
426 465  
427 466 static int wdtpci_open(struct inode *inode, struct file *file)
428 467 {
429   - if (down_trylock(&open_sem))
  468 + if (test_and_set_bit(0, &open_lock))
430 469 return -EBUSY;
431 470  
432   - if (nowayout) {
  471 + if (nowayout)
433 472 __module_get(THIS_MODULE);
434   - }
435 473 /*
436 474 * Activate
437 475 */
... ... @@ -460,7 +498,7 @@
460 498 wdtpci_ping();
461 499 }
462 500 expect_close = 0;
463   - up(&open_sem);
  501 + clear_bit(0, &open_lock);
464 502 return 0;
465 503 }
466 504  
467 505  
... ... @@ -476,14 +514,15 @@
476 514 * fahrenheit. It was designed by an imperial measurement luddite.
477 515 */
478 516  
479   -static ssize_t wdtpci_temp_read(struct file *file, char __user *buf, size_t count, loff_t *ptr)
  517 +static ssize_t wdtpci_temp_read(struct file *file, char __user *buf,
  518 + size_t count, loff_t *ptr)
480 519 {
481 520 int temperature;
482 521  
483 522 if (wdtpci_get_temperature(&temperature))
484 523 return -EFAULT;
485 524  
486   - if (copy_to_user (buf, &temperature, 1))
  525 + if (copy_to_user(buf, &temperature, 1))
487 526 return -EFAULT;
488 527  
489 528 return 1;
490 529  
491 530  
... ... @@ -529,12 +568,10 @@
529 568 */
530 569  
531 570 static int wdtpci_notify_sys(struct notifier_block *this, unsigned long code,
532   - void *unused)
  571 + void *unused)
533 572 {
534   - if (code==SYS_DOWN || code==SYS_HALT) {
535   - /* Turn the card off */
  573 + if (code == SYS_DOWN || code == SYS_HALT)
536 574 wdtpci_stop();
537   - }
538 575 return NOTIFY_DONE;
539 576 }
540 577  
... ... @@ -547,7 +584,7 @@
547 584 .owner = THIS_MODULE,
548 585 .llseek = no_llseek,
549 586 .write = wdtpci_write,
550   - .ioctl = wdtpci_ioctl,
  587 + .unlocked_ioctl = wdtpci_ioctl,
551 588 .open = wdtpci_open,
552 589 .release = wdtpci_release,
553 590 };
554 591  
555 592  
556 593  
557 594  
558 595  
559 596  
560 597  
561 598  
562 599  
563 600  
564 601  
565 602  
566 603  
567 604  
568 605  
569 606  
570 607  
571 608  
... ... @@ -584,80 +621,85 @@
584 621 };
585 622  
586 623  
587   -static int __devinit wdtpci_init_one (struct pci_dev *dev,
588   - const struct pci_device_id *ent)
  624 +static int __devinit wdtpci_init_one(struct pci_dev *dev,
  625 + const struct pci_device_id *ent)
589 626 {
590 627 int ret = -EIO;
591 628  
592 629 dev_count++;
593 630 if (dev_count > 1) {
594   - printk (KERN_ERR PFX "this driver only supports 1 device\n");
  631 + printk(KERN_ERR PFX "This driver only supports one device\n");
595 632 return -ENODEV;
596 633 }
597 634  
598   - if (pci_enable_device (dev)) {
599   - printk (KERN_ERR PFX "Not possible to enable PCI Device\n");
  635 + if (pci_enable_device(dev)) {
  636 + printk(KERN_ERR PFX "Not possible to enable PCI Device\n");
600 637 return -ENODEV;
601 638 }
602 639  
603   - if (pci_resource_start (dev, 2) == 0x0000) {
604   - printk (KERN_ERR PFX "No I/O-Address for card detected\n");
  640 + if (pci_resource_start(dev, 2) == 0x0000) {
  641 + printk(KERN_ERR PFX "No I/O-Address for card detected\n");
605 642 ret = -ENODEV;
606 643 goto out_pci;
607 644 }
608 645  
609   - sema_init(&open_sem, 1);
610   -
611 646 irq = dev->irq;
612   - io = pci_resource_start (dev, 2);
  647 + io = pci_resource_start(dev, 2);
613 648  
614   - if (request_region (io, 16, "wdt_pci") == NULL) {
615   - printk (KERN_ERR PFX "I/O address 0x%04x already in use\n", io);
  649 + if (request_region(io, 16, "wdt_pci") == NULL) {
  650 + printk(KERN_ERR PFX "I/O address 0x%04x already in use\n", io);
616 651 goto out_pci;
617 652 }
618 653  
619   - if (request_irq (irq, wdtpci_interrupt, IRQF_DISABLED | IRQF_SHARED,
  654 + if (request_irq(irq, wdtpci_interrupt, IRQF_DISABLED | IRQF_SHARED,
620 655 "wdt_pci", &wdtpci_miscdev)) {
621   - printk (KERN_ERR PFX "IRQ %d is not free\n", irq);
  656 + printk(KERN_ERR PFX "IRQ %d is not free\n", irq);
622 657 goto out_reg;
623 658 }
624 659  
625   - printk ("PCI-WDT500/501 (PCI-WDG-CSM) driver 0.10 at 0x%04x (Interrupt %d)\n",
626   - io, irq);
  660 + printk(KERN_INFO
  661 + "PCI-WDT500/501 (PCI-WDG-CSM) driver 0.10 at 0x%04x (Interrupt %d)\n",
  662 + io, irq);
627 663  
628   - /* Check that the heartbeat value is within it's range ; if not reset to the default */
  664 + /* Check that the heartbeat value is within its range;
  665 + if not reset to the default */
629 666 if (wdtpci_set_heartbeat(heartbeat)) {
630 667 wdtpci_set_heartbeat(WD_TIMO);
631   - printk(KERN_INFO PFX "heartbeat value must be 0<heartbeat<65536, using %d\n",
632   - WD_TIMO);
  668 + printk(KERN_INFO PFX
  669 + "heartbeat value must be 0 < heartbeat < 65536, using %d\n",
  670 + WD_TIMO);
633 671 }
634 672  
635   - ret = register_reboot_notifier (&wdtpci_notifier);
  673 + ret = register_reboot_notifier(&wdtpci_notifier);
636 674 if (ret) {
637   - printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", ret);
  675 + printk(KERN_ERR PFX
  676 + "cannot register reboot notifier (err=%d)\n", ret);
638 677 goto out_irq;
639 678 }
640 679  
641 680 #ifdef CONFIG_WDT_501_PCI
642   - ret = misc_register (&temp_miscdev);
  681 + ret = misc_register(&temp_miscdev);
643 682 if (ret) {
644   - printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
645   - TEMP_MINOR, ret);
  683 + printk(KERN_ERR PFX
  684 + "cannot register miscdev on minor=%d (err=%d)\n",
  685 + TEMP_MINOR, ret);
646 686 goto out_rbt;
647 687 }
648 688 #endif /* CONFIG_WDT_501_PCI */
649 689  
650   - ret = misc_register (&wdtpci_miscdev);
  690 + ret = misc_register(&wdtpci_miscdev);
651 691 if (ret) {
652   - printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
653   - WATCHDOG_MINOR, ret);
  692 + printk(KERN_ERR PFX
  693 + "cannot register miscdev on minor=%d (err=%d)\n",
  694 + WATCHDOG_MINOR, ret);
654 695 goto out_misc;
655 696 }
656 697  
657 698 printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n",
658 699 heartbeat, nowayout);
659 700 #ifdef CONFIG_WDT_501_PCI
660   - printk(KERN_INFO "wdt: Fan Tachometer is %s\n", (tachometer ? "Enabled" : "Disabled"));
  701 + printk(KERN_INFO "wdt: Fan Tachometer is %s\n",
  702 + (tachometer ? "Enabled" : "Disabled"));
661 703 #endif /* CONFIG_WDT_501_PCI */
662 704  
663 705 ret = 0;
664 706  
... ... @@ -673,14 +715,14 @@
673 715 out_irq:
674 716 free_irq(irq, &wdtpci_miscdev);
675 717 out_reg:
676   - release_region (io, 16);
  718 + release_region(io, 16);
677 719 out_pci:
678 720 pci_disable_device(dev);
679 721 goto out;
680 722 }
681 723  
682 724  
683   -static void __devexit wdtpci_remove_one (struct pci_dev *pdev)
  725 +static void __devexit wdtpci_remove_one(struct pci_dev *pdev)
684 726 {
685 727 /* here we assume only one device will ever have
686 728 * been picked up and registered by probe function */
... ... @@ -728,7 +770,7 @@
728 770  
729 771 static void __exit wdtpci_cleanup(void)
730 772 {
731   - pci_unregister_driver (&wdtpci_driver);
  773 + pci_unregister_driver(&wdtpci_driver);
732 774 }
733 775  
734 776  
... ... @@ -742,7 +784,7 @@
742 784  
743 785 static int __init wdtpci_init(void)
744 786 {
745   - return pci_register_driver (&wdtpci_driver);
  787 + return pci_register_driver(&wdtpci_driver);
746 788 }
747 789  
748 790