[WATCHDOG] pcwd.c private data struct patch

more private data of the card to one struct.

Signed-off-by: Wim Van Sebroeck <wim@iguana.be>

+104 -102
+104 -102
drivers/char/watchdog/pcwd.c
··· 73 73 #include <asm/io.h> /* For inb/outb/... */ 74 74 75 75 /* Module and version information */ 76 - #define WD_VER "1.16 (06/12/2004)" 76 + #define WD_VER "1.16 (03/01/2006)" 77 77 #define PFX "pcwd: " 78 78 79 79 /* ··· 133 133 /* internal variables */ 134 134 static atomic_t open_allowed = ATOMIC_INIT(1); 135 135 static char expect_close; 136 - static struct timer_list timer; 137 - static unsigned long next_heartbeat; 138 136 static int temp_panic; 139 - static int revision; /* The card's revision */ 140 - static int supports_temp; /* Wether or not the card has a temperature device */ 141 - static int command_mode; /* Wether or not the card is in command mode */ 142 - static int initial_status; /* The card's boot status */ 143 - static int current_readport; /* The cards I/O address */ 144 - static spinlock_t io_lock; 137 + static struct { /* this is private data for each ISA-PC watchdog card */ 138 + int revision; /* The card's revision */ 139 + int supports_temp; /* Wether or not the card has a temperature device */ 140 + int command_mode; /* Wether or not the card is in command mode */ 141 + int boot_status; /* The card's boot status */ 142 + int io_addr; /* The cards I/O address */ 143 + spinlock_t io_lock; /* the lock for io operations */ 144 + struct timer_list timer; /* The timer that pings the watchdog */ 145 + unsigned long next_heartbeat; /* the next_heartbeat for the timer */ 146 + } pcwd_private; 145 147 146 148 /* module parameters */ 147 149 #define WATCHDOG_HEARTBEAT 60 /* 60 sec default heartbeat */ ··· 167 165 168 166 /* The WCMD bit must be 1 and the command is only 4 bits in size */ 169 167 control_status = (cmd & 0x0F) | 0x80; 170 - outb_p(control_status, current_readport + 2); 168 + outb_p(control_status, pcwd_private.io_addr + 2); 171 169 udelay(ISA_COMMAND_TIMEOUT); 172 170 173 - port0 = inb_p(current_readport); 171 + port0 = inb_p(pcwd_private.io_addr); 174 172 for (i = 0; i < 25; ++i) { 175 173 last_port0 = port0; 176 - port0 = inb_p(current_readport); 174 + port0 = inb_p(pcwd_private.io_addr); 177 175 178 176 if (port0 == last_port0) 179 177 break; /* Data is stable */ ··· 189 187 int i, found=0, count=0; 190 188 191 189 /* Set the card into command mode */ 192 - spin_lock(&io_lock); 190 + spin_lock(&pcwd_private.io_lock); 193 191 while ((!found) && (count < 3)) { 194 192 i = send_isa_command(CMD_ISA_IDLE); 195 193 ··· 197 195 found = 1; 198 196 else if (i == 0xF3) { 199 197 /* Card does not like what we've done to it */ 200 - outb_p(0x00, current_readport + 2); 198 + outb_p(0x00, pcwd_private.io_addr + 2); 201 199 udelay(1200); /* Spec says wait 1ms */ 202 - outb_p(0x00, current_readport + 2); 200 + outb_p(0x00, pcwd_private.io_addr + 2); 203 201 udelay(ISA_COMMAND_TIMEOUT); 204 202 } 205 203 count++; 206 204 } 207 - spin_unlock(&io_lock); 208 - command_mode = found; 205 + spin_unlock(&pcwd_private.io_lock); 206 + pcwd_private.command_mode = found; 209 207 210 208 return(found); 211 209 } ··· 213 211 static void unset_command_mode(void) 214 212 { 215 213 /* Set the card into normal mode */ 216 - spin_lock(&io_lock); 217 - outb_p(0x00, current_readport + 2); 214 + spin_lock(&pcwd_private.io_lock); 215 + outb_p(0x00, pcwd_private.io_addr + 2); 218 216 udelay(ISA_COMMAND_TIMEOUT); 219 - spin_unlock(&io_lock); 217 + spin_unlock(&pcwd_private.io_lock); 220 218 221 - command_mode = 0; 219 + pcwd_private.command_mode = 0; 222 220 } 223 221 224 222 static void pcwd_timer_ping(unsigned long data) ··· 227 225 228 226 /* If we got a heartbeat pulse within the WDT_INTERVAL 229 227 * we agree to ping the WDT */ 230 - if(time_before(jiffies, next_heartbeat)) { 228 + if(time_before(jiffies, pcwd_private.next_heartbeat)) { 231 229 /* Ping the watchdog */ 232 - spin_lock(&io_lock); 233 - if (revision == PCWD_REVISION_A) { 230 + spin_lock(&pcwd_private.io_lock); 231 + if (pcwd_private.revision == PCWD_REVISION_A) { 234 232 /* Rev A cards are reset by setting the WD_WDRST bit in register 1 */ 235 - wdrst_stat = inb_p(current_readport); 233 + wdrst_stat = inb_p(pcwd_private.io_addr); 236 234 wdrst_stat &= 0x0F; 237 235 wdrst_stat |= WD_WDRST; 238 236 239 - outb_p(wdrst_stat, current_readport + 1); 237 + outb_p(wdrst_stat, pcwd_private.io_addr + 1); 240 238 } else { 241 239 /* Re-trigger watchdog by writing to port 0 */ 242 - outb_p(0x00, current_readport); 240 + outb_p(0x00, pcwd_private.io_addr); 243 241 } 244 242 245 243 /* Re-set the timer interval */ 246 - mod_timer(&timer, jiffies + WDT_INTERVAL); 244 + mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL); 247 245 248 - spin_unlock(&io_lock); 246 + spin_unlock(&pcwd_private.io_lock); 249 247 } else { 250 248 printk(KERN_WARNING PFX "Heartbeat lost! Will not ping the watchdog\n"); 251 249 } ··· 255 253 { 256 254 int stat_reg; 257 255 258 - next_heartbeat = jiffies + (heartbeat * HZ); 256 + pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ); 259 257 260 258 /* Start the timer */ 261 - mod_timer(&timer, jiffies + WDT_INTERVAL); 259 + mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL); 262 260 263 261 /* Enable the port */ 264 - if (revision == PCWD_REVISION_C) { 265 - spin_lock(&io_lock); 266 - outb_p(0x00, current_readport + 3); 262 + if (pcwd_private.revision == PCWD_REVISION_C) { 263 + spin_lock(&pcwd_private.io_lock); 264 + outb_p(0x00, pcwd_private.io_addr + 3); 267 265 udelay(ISA_COMMAND_TIMEOUT); 268 - stat_reg = inb_p(current_readport + 2); 269 - spin_unlock(&io_lock); 266 + stat_reg = inb_p(pcwd_private.io_addr + 2); 267 + spin_unlock(&pcwd_private.io_lock); 270 268 if (stat_reg & 0x10) { 271 269 printk(KERN_INFO PFX "Could not start watchdog\n"); 272 270 return -EIO; ··· 280 278 int stat_reg; 281 279 282 280 /* Stop the timer */ 283 - del_timer(&timer); 281 + del_timer(&pcwd_private.timer); 284 282 285 283 /* Disable the board */ 286 - if (revision == PCWD_REVISION_C) { 287 - spin_lock(&io_lock); 288 - outb_p(0xA5, current_readport + 3); 284 + if (pcwd_private.revision == PCWD_REVISION_C) { 285 + spin_lock(&pcwd_private.io_lock); 286 + outb_p(0xA5, pcwd_private.io_addr + 3); 289 287 udelay(ISA_COMMAND_TIMEOUT); 290 - outb_p(0xA5, current_readport + 3); 288 + outb_p(0xA5, pcwd_private.io_addr + 3); 291 289 udelay(ISA_COMMAND_TIMEOUT); 292 - stat_reg = inb_p(current_readport + 2); 293 - spin_unlock(&io_lock); 290 + stat_reg = inb_p(pcwd_private.io_addr + 2); 291 + spin_unlock(&pcwd_private.io_lock); 294 292 if ((stat_reg & 0x10) == 0) { 295 293 printk(KERN_INFO PFX "Could not stop watchdog\n"); 296 294 return -EIO; ··· 302 300 static int pcwd_keepalive(void) 303 301 { 304 302 /* user land ping */ 305 - next_heartbeat = jiffies + (heartbeat * HZ); 303 + pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ); 306 304 return 0; 307 305 } 308 306 ··· 320 318 int card_status; 321 319 322 320 *status=0; 323 - spin_lock(&io_lock); 324 - if (revision == PCWD_REVISION_A) 321 + spin_lock(&pcwd_private.io_lock); 322 + if (pcwd_private.revision == PCWD_REVISION_A) 325 323 /* Rev A cards return status information from 326 324 * the base register, which is used for the 327 325 * temperature in other cards. */ 328 - card_status = inb(current_readport); 326 + card_status = inb(pcwd_private.io_addr); 329 327 else { 330 328 /* Rev C cards return card status in the base 331 329 * address + 1 register. And use different bits 332 330 * to indicate a card initiated reset, and an 333 331 * over-temperature condition. And the reboot 334 332 * status can be reset. */ 335 - card_status = inb(current_readport + 1); 333 + card_status = inb(pcwd_private.io_addr + 1); 336 334 } 337 - spin_unlock(&io_lock); 335 + spin_unlock(&pcwd_private.io_lock); 338 336 339 - if (revision == PCWD_REVISION_A) { 337 + if (pcwd_private.revision == PCWD_REVISION_A) { 340 338 if (card_status & WD_WDRST) 341 339 *status |= WDIOF_CARDRESET; 342 340 ··· 365 363 366 364 static int pcwd_clear_status(void) 367 365 { 368 - if (revision == PCWD_REVISION_C) { 369 - spin_lock(&io_lock); 370 - outb_p(0x00, current_readport + 1); /* clear reset status */ 371 - spin_unlock(&io_lock); 366 + if (pcwd_private.revision == PCWD_REVISION_C) { 367 + spin_lock(&pcwd_private.io_lock); 368 + outb_p(0x00, pcwd_private.io_addr + 1); /* clear reset status */ 369 + spin_unlock(&pcwd_private.io_lock); 372 370 } 373 371 return 0; 374 372 } ··· 376 374 static int pcwd_get_temperature(int *temperature) 377 375 { 378 376 /* check that port 0 gives temperature info and no command results */ 379 - if (command_mode) 377 + if (pcwd_private.command_mode) 380 378 return -1; 381 379 382 380 *temperature = 0; 383 - if (!supports_temp) 381 + if (!pcwd_private.supports_temp) 384 382 return -ENODEV; 385 383 386 384 /* 387 385 * Convert celsius to fahrenheit, since this was 388 386 * the decided 'standard' for this return value. 389 387 */ 390 - spin_lock(&io_lock); 391 - *temperature = ((inb(current_readport)) * 9 / 5) + 32; 392 - spin_unlock(&io_lock); 388 + spin_lock(&pcwd_private.io_lock); 389 + *temperature = ((inb(pcwd_private.io_addr)) * 9 / 5) + 32; 390 + spin_unlock(&pcwd_private.io_lock); 393 391 394 392 return 0; 395 393 } ··· 430 428 return put_user(status, argp); 431 429 432 430 case WDIOC_GETBOOTSTATUS: 433 - return put_user(initial_status, argp); 431 + return put_user(pcwd_private.boot_status, argp); 434 432 435 433 case WDIOC_GETTEMP: 436 434 if (pcwd_get_temperature(&temperature)) ··· 439 437 return put_user(temperature, argp); 440 438 441 439 case WDIOC_SETOPTIONS: 442 - if (revision == PCWD_REVISION_C) 440 + if (pcwd_private.revision == PCWD_REVISION_C) 443 441 { 444 442 if(copy_from_user(&rv, argp, sizeof(int))) 445 443 return -EFAULT; ··· 555 553 556 554 static int pcwd_temp_open(struct inode *inode, struct file *file) 557 555 { 558 - if (!supports_temp) 556 + if (!pcwd_private.supports_temp) 559 557 return -ENODEV; 560 558 561 559 return nonseekable_open(inode, file); ··· 623 621 624 622 static inline void get_support(void) 625 623 { 626 - if (inb(current_readport) != 0xF0) 627 - supports_temp = 1; 624 + if (inb(pcwd_private.io_addr) != 0xF0) 625 + pcwd_private.supports_temp = 1; 628 626 } 629 627 630 628 static inline int get_revision(void) 631 629 { 632 630 int r = PCWD_REVISION_C; 633 631 634 - spin_lock(&io_lock); 632 + spin_lock(&pcwd_private.io_lock); 635 633 /* REV A cards use only 2 io ports; test 636 634 * presumes a floating bus reads as 0xff. */ 637 - if ((inb(current_readport + 2) == 0xFF) || 638 - (inb(current_readport + 3) == 0xFF)) 635 + if ((inb(pcwd_private.io_addr + 2) == 0xFF) || 636 + (inb(pcwd_private.io_addr + 3) == 0xFF)) 639 637 r=PCWD_REVISION_A; 640 - spin_unlock(&io_lock); 638 + spin_unlock(&pcwd_private.io_lock); 641 639 642 640 return r; 643 641 } ··· 697 695 printk(KERN_ERR PFX "No I/O-Address for card detected\n"); 698 696 return -ENODEV; 699 697 } 700 - current_readport = base_addr; 698 + pcwd_private.io_addr = base_addr; 701 699 702 700 /* Check card's revision */ 703 - revision = get_revision(); 701 + pcwd_private.revision = get_revision(); 704 702 705 - if (!request_region(current_readport, (revision == PCWD_REVISION_A) ? 2 : 4, "PCWD")) { 703 + if (!request_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4, "PCWD")) { 706 704 printk(KERN_ERR PFX "I/O address 0x%04x already in use\n", 707 - current_readport); 708 - current_readport = 0x0000; 705 + pcwd_private.io_addr); 706 + pcwd_private.io_addr = 0x0000; 709 707 return -EIO; 710 708 } 711 709 712 710 /* Initial variables */ 713 - supports_temp = 0; 711 + pcwd_private.supports_temp = 0; 714 712 temp_panic = 0; 715 - initial_status = 0x0000; 713 + pcwd_private.boot_status = 0x0000; 716 714 717 715 /* get the boot_status */ 718 - pcwd_get_status(&initial_status); 716 + pcwd_get_status(&pcwd_private.boot_status); 719 717 720 718 /* clear the "card caused reboot" flag */ 721 719 pcwd_clear_status(); 722 720 723 - init_timer(&timer); 724 - timer.function = pcwd_timer_ping; 725 - timer.data = 0; 721 + init_timer(&pcwd_private.timer); 722 + pcwd_private.timer.function = pcwd_timer_ping; 723 + pcwd_private.timer.data = 0; 726 724 727 725 /* Disable the board */ 728 726 pcwd_stop(); ··· 731 729 get_support(); 732 730 733 731 /* Get some extra info from the hardware (in command/debug/diag mode) */ 734 - if (revision == PCWD_REVISION_A) 735 - printk(KERN_INFO PFX "ISA-PC Watchdog (REV.A) detected at port 0x%04x\n", current_readport); 736 - else if (revision == PCWD_REVISION_C) { 732 + if (pcwd_private.revision == PCWD_REVISION_A) 733 + printk(KERN_INFO PFX "ISA-PC Watchdog (REV.A) detected at port 0x%04x\n", pcwd_private.io_addr); 734 + else if (pcwd_private.revision == PCWD_REVISION_C) { 737 735 firmware = get_firmware(); 738 736 printk(KERN_INFO PFX "ISA-PC Watchdog (REV.C) detected at port 0x%04x (Firmware version: %s)\n", 739 - current_readport, firmware); 737 + pcwd_private.io_addr, firmware); 740 738 kfree(firmware); 741 739 option_switches = get_option_switches(); 742 740 printk(KERN_INFO PFX "Option switches (0x%02x): Temperature Reset Enable=%s, Power On Delay=%s\n", ··· 752 750 } else { 753 751 /* Should NEVER happen, unless get_revision() fails. */ 754 752 printk(KERN_INFO PFX "Unable to get revision\n"); 755 - release_region(current_readport, (revision == PCWD_REVISION_A) ? 2 : 4); 756 - current_readport = 0x0000; 753 + release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4); 754 + pcwd_private.io_addr = 0x0000; 757 755 return -1; 758 756 } 759 757 760 - if (supports_temp) 758 + if (pcwd_private.supports_temp) 761 759 printk(KERN_INFO PFX "Temperature Option Detected\n"); 762 760 763 - if (initial_status & WDIOF_CARDRESET) 761 + if (pcwd_private.boot_status & WDIOF_CARDRESET) 764 762 printk(KERN_INFO PFX "Previous reboot was caused by the card\n"); 765 763 766 - if (initial_status & WDIOF_OVERHEAT) { 764 + if (pcwd_private.boot_status & WDIOF_OVERHEAT) { 767 765 printk(KERN_EMERG PFX "Card senses a CPU Overheat. Panicking!\n"); 768 766 printk(KERN_EMERG PFX "CPU Overheat\n"); 769 767 } 770 768 771 - if (initial_status == 0) 769 + if (pcwd_private.boot_status == 0) 772 770 printk(KERN_INFO PFX "No previous trip detected - Cold boot or reset\n"); 773 771 774 772 /* Check that the heartbeat value is within it's range ; if not reset to the default */ ··· 782 780 if (ret) { 783 781 printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", 784 782 ret); 785 - release_region(current_readport, (revision == PCWD_REVISION_A) ? 2 : 4); 786 - current_readport = 0x0000; 783 + release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4); 784 + pcwd_private.io_addr = 0x0000; 787 785 return ret; 788 786 } 789 787 790 - if (supports_temp) { 788 + if (pcwd_private.supports_temp) { 791 789 ret = misc_register(&temp_miscdev); 792 790 if (ret) { 793 791 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", 794 792 TEMP_MINOR, ret); 795 793 unregister_reboot_notifier(&pcwd_notifier); 796 - release_region(current_readport, (revision == PCWD_REVISION_A) ? 2 : 4); 797 - current_readport = 0x0000; 794 + release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4); 795 + pcwd_private.io_addr = 0x0000; 798 796 return ret; 799 797 } 800 798 } ··· 803 801 if (ret) { 804 802 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", 805 803 WATCHDOG_MINOR, ret); 806 - if (supports_temp) 804 + if (pcwd_private.supports_temp) 807 805 misc_deregister(&temp_miscdev); 808 806 unregister_reboot_notifier(&pcwd_notifier); 809 - release_region(current_readport, (revision == PCWD_REVISION_A) ? 2 : 4); 810 - current_readport = 0x0000; 807 + release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4); 808 + pcwd_private.io_addr = 0x0000; 811 809 return ret; 812 810 } 813 811 ··· 825 823 826 824 /* Deregister */ 827 825 misc_deregister(&pcwd_miscdev); 828 - if (supports_temp) 826 + if (pcwd_private.supports_temp) 829 827 misc_deregister(&temp_miscdev); 830 828 unregister_reboot_notifier(&pcwd_notifier); 831 - release_region(current_readport, (revision == PCWD_REVISION_A) ? 2 : 4); 832 - current_readport = 0x0000; 829 + release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4); 830 + pcwd_private.io_addr = 0x0000; 833 831 cards_found--; 834 832 } 835 833 ··· 893 891 { 894 892 int i, found = 0; 895 893 896 - spin_lock_init(&io_lock); 894 + spin_lock_init(&pcwd_private.io_lock); 897 895 898 896 for (i = 0; pcwd_ioports[i] != 0; i++) { 899 897 if (pcwd_checkcard(pcwd_ioports[i])) { ··· 912 910 913 911 static void __exit pcwd_cleanup_module(void) 914 912 { 915 - if (current_readport) 913 + if (pcwd_private.io_addr) 916 914 pcwatchdog_exit(); 917 915 return; 918 916 }