Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 1 | /* |
Mingarelli, Thomas | ca22e79 | 2015-12-14 20:22:09 +0000 | [diff] [blame] | 2 | * HPE WatchDog Driver |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 3 | * based on |
| 4 | * |
| 5 | * SoftDog 0.05: A Software Watchdog Device |
| 6 | * |
Mingarelli, Thomas | ca22e79 | 2015-12-14 20:22:09 +0000 | [diff] [blame] | 7 | * (c) Copyright 2015 Hewlett Packard Enterprise Development LP |
| 8 | * Thomas Mingarelli <thomas.mingarelli@hpe.com> |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License |
| 12 | * version 2 as published by the Free Software Foundation |
| 13 | * |
| 14 | */ |
| 15 | |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 16 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 17 | |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 18 | #include <linux/device.h> |
| 19 | #include <linux/fs.h> |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 20 | #include <linux/io.h> |
dann frazier | a52e6d1 | 2010-07-27 17:50:50 -0600 | [diff] [blame] | 21 | #include <linux/bitops.h> |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 22 | #include <linux/kernel.h> |
| 23 | #include <linux/miscdevice.h> |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 24 | #include <linux/module.h> |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 25 | #include <linux/moduleparam.h> |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 26 | #include <linux/pci.h> |
| 27 | #include <linux/pci_ids.h> |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 28 | #include <linux/types.h> |
| 29 | #include <linux/uaccess.h> |
| 30 | #include <linux/watchdog.h> |
Ingo Molnar | d48b0e1 | 2011-10-06 14:20:27 +0200 | [diff] [blame] | 31 | #include <asm/nmi.h> |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 32 | |
Brian Boylston | fc113d5 | 2016-09-26 13:57:14 -0500 | [diff] [blame] | 33 | #define HPWDT_VERSION "1.4.0" |
dann frazier | e802e32 | 2010-06-02 16:23:39 -0600 | [diff] [blame] | 34 | #define SECS_TO_TICKS(secs) ((secs) * 1000 / 128) |
dann frazier | 6f681c2 | 2010-06-02 16:23:40 -0600 | [diff] [blame] | 35 | #define TICKS_TO_SECS(ticks) ((ticks) * 128 / 1000) |
| 36 | #define HPWDT_MAX_TIMER TICKS_TO_SECS(65535) |
dann frazier | 923410d | 2010-07-27 17:50:54 -0600 | [diff] [blame] | 37 | #define DEFAULT_MARGIN 30 |
| 38 | |
| 39 | static unsigned int soft_margin = DEFAULT_MARGIN; /* in seconds */ |
| 40 | static unsigned int reload; /* the computed soft_margin */ |
Wim Van Sebroeck | 86a1e18 | 2012-03-05 16:51:11 +0100 | [diff] [blame] | 41 | static bool nowayout = WATCHDOG_NOWAYOUT; |
Jerry Hoemann | 25d5767 | 2018-02-25 20:22:20 -0700 | [diff] [blame] | 42 | #ifdef CONFIG_HPWDT_NMI_DECODING |
| 43 | static unsigned int allow_kdump = 1; |
| 44 | #endif |
dann frazier | 923410d | 2010-07-27 17:50:54 -0600 | [diff] [blame] | 45 | static char expect_release; |
| 46 | static unsigned long hpwdt_is_open; |
| 47 | |
| 48 | static void __iomem *pci_mem_addr; /* the PCI-memory address */ |
Jerry Hoemann | c387231 | 2017-10-23 16:46:17 -0600 | [diff] [blame] | 49 | static unsigned long __iomem *hpwdt_nmistat; |
dann frazier | 923410d | 2010-07-27 17:50:54 -0600 | [diff] [blame] | 50 | static unsigned long __iomem *hpwdt_timer_reg; |
| 51 | static unsigned long __iomem *hpwdt_timer_con; |
| 52 | |
Jingoo Han | bc17f9d | 2013-12-03 08:30:22 +0900 | [diff] [blame] | 53 | static const struct pci_device_id hpwdt_devices[] = { |
dann frazier | 36e3ff4 | 2010-07-27 17:50:57 -0600 | [diff] [blame] | 54 | { PCI_DEVICE(PCI_VENDOR_ID_COMPAQ, 0xB203) }, /* iLO2 */ |
| 55 | { PCI_DEVICE(PCI_VENDOR_ID_HP, 0x3306) }, /* iLO3 */ |
dann frazier | 923410d | 2010-07-27 17:50:54 -0600 | [diff] [blame] | 56 | {0}, /* terminate list */ |
| 57 | }; |
| 58 | MODULE_DEVICE_TABLE(pci, hpwdt_devices); |
| 59 | |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 60 | |
| 61 | /* |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 62 | * Watchdog operations |
| 63 | */ |
| 64 | static void hpwdt_start(void) |
| 65 | { |
dann frazier | e802e32 | 2010-06-02 16:23:39 -0600 | [diff] [blame] | 66 | reload = SECS_TO_TICKS(soft_margin); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 67 | iowrite16(reload, hpwdt_timer_reg); |
Mingarelli, Thomas | d08c9a3 | 2012-04-03 05:37:01 +0000 | [diff] [blame] | 68 | iowrite8(0x85, hpwdt_timer_con); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static void hpwdt_stop(void) |
| 72 | { |
| 73 | unsigned long data; |
| 74 | |
Mingarelli, Thomas | d08c9a3 | 2012-04-03 05:37:01 +0000 | [diff] [blame] | 75 | data = ioread8(hpwdt_timer_con); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 76 | data &= 0xFE; |
Mingarelli, Thomas | d08c9a3 | 2012-04-03 05:37:01 +0000 | [diff] [blame] | 77 | iowrite8(data, hpwdt_timer_con); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | static void hpwdt_ping(void) |
| 81 | { |
| 82 | iowrite16(reload, hpwdt_timer_reg); |
| 83 | } |
| 84 | |
| 85 | static int hpwdt_change_timer(int new_margin) |
| 86 | { |
dann frazier | 6f681c2 | 2010-06-02 16:23:40 -0600 | [diff] [blame] | 87 | if (new_margin < 1 || new_margin > HPWDT_MAX_TIMER) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 88 | pr_warn("New value passed in is invalid: %d seconds\n", |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 89 | new_margin); |
| 90 | return -EINVAL; |
| 91 | } |
| 92 | |
| 93 | soft_margin = new_margin; |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 94 | pr_debug("New timer passed in is %d seconds\n", new_margin); |
dann frazier | e802e32 | 2010-06-02 16:23:39 -0600 | [diff] [blame] | 95 | reload = SECS_TO_TICKS(soft_margin); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
dann frazier | aae67f3 | 2010-06-02 16:23:41 -0600 | [diff] [blame] | 100 | static int hpwdt_time_left(void) |
| 101 | { |
| 102 | return TICKS_TO_SECS(ioread16(hpwdt_timer_reg)); |
| 103 | } |
| 104 | |
Arnd Bergmann | 6cda76d | 2017-12-06 22:02:37 +0100 | [diff] [blame] | 105 | #ifdef CONFIG_HPWDT_NMI_DECODING |
Jerry Hoemann | c387231 | 2017-10-23 16:46:17 -0600 | [diff] [blame] | 106 | static int hpwdt_my_nmi(void) |
| 107 | { |
| 108 | return ioread8(hpwdt_nmistat) & 0x6; |
| 109 | } |
| 110 | |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 111 | /* |
Thomas Mingarelli | ab4ba3c | 2008-07-15 19:40:41 +0000 | [diff] [blame] | 112 | * NMI Handler |
| 113 | */ |
Don Zickus | 9c48f1c | 2011-09-30 15:06:21 -0400 | [diff] [blame] | 114 | static int hpwdt_pretimeout(unsigned int ulReason, struct pt_regs *regs) |
Thomas Mingarelli | ab4ba3c | 2008-07-15 19:40:41 +0000 | [diff] [blame] | 115 | { |
Jerry Hoemann | c387231 | 2017-10-23 16:46:17 -0600 | [diff] [blame] | 116 | if ((ulReason == NMI_UNKNOWN) && !hpwdt_my_nmi()) |
| 117 | return NMI_DONE; |
| 118 | |
Thomas Mingarelli | 5efc7a6 | 2011-07-26 14:05:53 +0100 | [diff] [blame] | 119 | if (allow_kdump) |
| 120 | hpwdt_stop(); |
Naga Chumbalkar | dbc018e | 2011-08-09 22:27:26 +0000 | [diff] [blame] | 121 | |
Hidehiro Kawai | abc514c | 2016-03-22 14:27:24 -0700 | [diff] [blame] | 122 | nmi_panic(regs, "An NMI occurred. Depending on your system the reason " |
Thomas Mingarelli | 7bb5be9 | 2014-01-28 21:26:10 +0100 | [diff] [blame] | 123 | "for the NMI is logged in any one of the following " |
| 124 | "resources:\n" |
| 125 | "1. Integrated Management Log (IML)\n" |
| 126 | "2. OA Syslog\n" |
| 127 | "3. OA Forward Progress Log\n" |
| 128 | "4. iLO Event Log"); |
Thomas Mingarelli | 5efc7a6 | 2011-07-26 14:05:53 +0100 | [diff] [blame] | 129 | |
Hidehiro Kawai | abc514c | 2016-03-22 14:27:24 -0700 | [diff] [blame] | 130 | return NMI_HANDLED; |
Thomas Mingarelli | ab4ba3c | 2008-07-15 19:40:41 +0000 | [diff] [blame] | 131 | } |
dann frazier | 86ded1f | 2010-07-27 17:51:02 -0600 | [diff] [blame] | 132 | #endif /* CONFIG_HPWDT_NMI_DECODING */ |
Thomas Mingarelli | ab4ba3c | 2008-07-15 19:40:41 +0000 | [diff] [blame] | 133 | |
| 134 | /* |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 135 | * /dev/watchdog handling |
| 136 | */ |
| 137 | static int hpwdt_open(struct inode *inode, struct file *file) |
| 138 | { |
| 139 | /* /dev/watchdog can only be opened once */ |
| 140 | if (test_and_set_bit(0, &hpwdt_is_open)) |
| 141 | return -EBUSY; |
| 142 | |
| 143 | /* Start the watchdog */ |
| 144 | hpwdt_start(); |
| 145 | hpwdt_ping(); |
| 146 | |
| 147 | return nonseekable_open(inode, file); |
| 148 | } |
| 149 | |
| 150 | static int hpwdt_release(struct inode *inode, struct file *file) |
| 151 | { |
| 152 | /* Stop the watchdog */ |
| 153 | if (expect_release == 42) { |
| 154 | hpwdt_stop(); |
| 155 | } else { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 156 | pr_crit("Unexpected close, not stopping watchdog!\n"); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 157 | hpwdt_ping(); |
| 158 | } |
| 159 | |
| 160 | expect_release = 0; |
| 161 | |
| 162 | /* /dev/watchdog is being closed, make sure it can be re-opened */ |
| 163 | clear_bit(0, &hpwdt_is_open); |
| 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | static ssize_t hpwdt_write(struct file *file, const char __user *data, |
| 169 | size_t len, loff_t *ppos) |
| 170 | { |
| 171 | /* See if we got the magic character 'V' and reload the timer */ |
| 172 | if (len) { |
| 173 | if (!nowayout) { |
| 174 | size_t i; |
| 175 | |
| 176 | /* note: just in case someone wrote the magic character |
| 177 | * five months ago... */ |
| 178 | expect_release = 0; |
| 179 | |
| 180 | /* scan to see whether or not we got the magic char. */ |
| 181 | for (i = 0; i != len; i++) { |
| 182 | char c; |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 183 | if (get_user(c, data + i)) |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 184 | return -EFAULT; |
| 185 | if (c == 'V') |
| 186 | expect_release = 42; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | /* someone wrote to us, we should reload the timer */ |
| 191 | hpwdt_ping(); |
| 192 | } |
| 193 | |
| 194 | return len; |
| 195 | } |
| 196 | |
Wim Van Sebroeck | 42747d7 | 2009-12-26 18:55:22 +0000 | [diff] [blame] | 197 | static const struct watchdog_info ident = { |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 198 | .options = WDIOF_SETTIMEOUT | |
| 199 | WDIOF_KEEPALIVEPING | |
| 200 | WDIOF_MAGICCLOSE, |
Mingarelli, Thomas | ca22e79 | 2015-12-14 20:22:09 +0000 | [diff] [blame] | 201 | .identity = "HPE iLO2+ HW Watchdog Timer", |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 202 | }; |
| 203 | |
| 204 | static long hpwdt_ioctl(struct file *file, unsigned int cmd, |
| 205 | unsigned long arg) |
| 206 | { |
| 207 | void __user *argp = (void __user *)arg; |
| 208 | int __user *p = argp; |
Jean Delvare | 46c80b2 | 2015-06-21 09:32:33 +0200 | [diff] [blame] | 209 | int new_margin, options; |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 210 | int ret = -ENOTTY; |
| 211 | |
| 212 | switch (cmd) { |
| 213 | case WDIOC_GETSUPPORT: |
| 214 | ret = 0; |
| 215 | if (copy_to_user(argp, &ident, sizeof(ident))) |
| 216 | ret = -EFAULT; |
| 217 | break; |
| 218 | |
| 219 | case WDIOC_GETSTATUS: |
| 220 | case WDIOC_GETBOOTSTATUS: |
| 221 | ret = put_user(0, p); |
| 222 | break; |
| 223 | |
| 224 | case WDIOC_KEEPALIVE: |
| 225 | hpwdt_ping(); |
| 226 | ret = 0; |
| 227 | break; |
| 228 | |
Jean Delvare | 46c80b2 | 2015-06-21 09:32:33 +0200 | [diff] [blame] | 229 | case WDIOC_SETOPTIONS: |
| 230 | ret = get_user(options, p); |
| 231 | if (ret) |
| 232 | break; |
| 233 | |
| 234 | if (options & WDIOS_DISABLECARD) |
| 235 | hpwdt_stop(); |
| 236 | |
| 237 | if (options & WDIOS_ENABLECARD) { |
| 238 | hpwdt_start(); |
| 239 | hpwdt_ping(); |
| 240 | } |
| 241 | break; |
| 242 | |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 243 | case WDIOC_SETTIMEOUT: |
| 244 | ret = get_user(new_margin, p); |
| 245 | if (ret) |
| 246 | break; |
| 247 | |
| 248 | ret = hpwdt_change_timer(new_margin); |
| 249 | if (ret) |
| 250 | break; |
| 251 | |
| 252 | hpwdt_ping(); |
| 253 | /* Fall */ |
| 254 | case WDIOC_GETTIMEOUT: |
| 255 | ret = put_user(soft_margin, p); |
| 256 | break; |
dann frazier | aae67f3 | 2010-06-02 16:23:41 -0600 | [diff] [blame] | 257 | |
| 258 | case WDIOC_GETTIMELEFT: |
| 259 | ret = put_user(hpwdt_time_left(), p); |
| 260 | break; |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 261 | } |
| 262 | return ret; |
| 263 | } |
| 264 | |
| 265 | /* |
| 266 | * Kernel interfaces |
| 267 | */ |
Wim Van Sebroeck | d5c26a5 | 2009-03-18 08:18:43 +0000 | [diff] [blame] | 268 | static const struct file_operations hpwdt_fops = { |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 269 | .owner = THIS_MODULE, |
| 270 | .llseek = no_llseek, |
| 271 | .write = hpwdt_write, |
| 272 | .unlocked_ioctl = hpwdt_ioctl, |
| 273 | .open = hpwdt_open, |
| 274 | .release = hpwdt_release, |
| 275 | }; |
| 276 | |
| 277 | static struct miscdevice hpwdt_miscdev = { |
| 278 | .minor = WATCHDOG_MINOR, |
| 279 | .name = "watchdog", |
| 280 | .fops = &hpwdt_fops, |
| 281 | }; |
| 282 | |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 283 | /* |
| 284 | * Init & Exit |
| 285 | */ |
| 286 | |
Thomas Mingarelli | 5efc7a6 | 2011-07-26 14:05:53 +0100 | [diff] [blame] | 287 | |
Bill Pemberton | 2d991a1 | 2012-11-19 13:21:41 -0500 | [diff] [blame] | 288 | static int hpwdt_init_nmi_decoding(struct pci_dev *dev) |
dann frazier | 2ec7ed6 | 2010-07-28 12:38:43 -0600 | [diff] [blame] | 289 | { |
Jerry Hoemann | 25d5767 | 2018-02-25 20:22:20 -0700 | [diff] [blame] | 290 | #ifdef CONFIG_HPWDT_NMI_DECODING |
dann frazier | 2ec7ed6 | 2010-07-28 12:38:43 -0600 | [diff] [blame] | 291 | int retval; |
dann frazier | 2ec7ed6 | 2010-07-28 12:38:43 -0600 | [diff] [blame] | 292 | /* |
Don Zickus | 09ee101 | 2012-03-29 16:11:15 -0400 | [diff] [blame] | 293 | * Only one function can register for NMI_UNKNOWN |
dann frazier | 2ec7ed6 | 2010-07-28 12:38:43 -0600 | [diff] [blame] | 294 | */ |
Don Zickus | 09ee101 | 2012-03-29 16:11:15 -0400 | [diff] [blame] | 295 | retval = register_nmi_handler(NMI_UNKNOWN, hpwdt_pretimeout, 0, "hpwdt"); |
Don Zickus | 553222f | 2012-03-29 16:11:16 -0400 | [diff] [blame] | 296 | if (retval) |
| 297 | goto error; |
| 298 | retval = register_nmi_handler(NMI_SERR, hpwdt_pretimeout, 0, "hpwdt"); |
| 299 | if (retval) |
| 300 | goto error1; |
| 301 | retval = register_nmi_handler(NMI_IO_CHECK, hpwdt_pretimeout, 0, "hpwdt"); |
| 302 | if (retval) |
| 303 | goto error2; |
dann frazier | 2ec7ed6 | 2010-07-28 12:38:43 -0600 | [diff] [blame] | 304 | |
| 305 | dev_info(&dev->dev, |
Mingarelli, Thomas | ca22e79 | 2015-12-14 20:22:09 +0000 | [diff] [blame] | 306 | "HPE Watchdog Timer Driver: NMI decoding initialized" |
Masanari Iida | b91b5be | 2014-10-22 20:24:35 +0900 | [diff] [blame] | 307 | ", allow kernel dump: %s (default = 1/ON)\n", |
Don Zickus | 09ee101 | 2012-03-29 16:11:15 -0400 | [diff] [blame] | 308 | (allow_kdump == 0) ? "OFF" : "ON"); |
dann frazier | 2ec7ed6 | 2010-07-28 12:38:43 -0600 | [diff] [blame] | 309 | return 0; |
Don Zickus | 553222f | 2012-03-29 16:11:16 -0400 | [diff] [blame] | 310 | |
| 311 | error2: |
| 312 | unregister_nmi_handler(NMI_SERR, "hpwdt"); |
| 313 | error1: |
| 314 | unregister_nmi_handler(NMI_UNKNOWN, "hpwdt"); |
| 315 | error: |
| 316 | dev_warn(&dev->dev, |
| 317 | "Unable to register a die notifier (err=%d).\n", |
| 318 | retval); |
Don Zickus | 553222f | 2012-03-29 16:11:16 -0400 | [diff] [blame] | 319 | return retval; |
Jerry Hoemann | 25d5767 | 2018-02-25 20:22:20 -0700 | [diff] [blame] | 320 | #endif /* CONFIG_HPWDT_NMI_DECODING */ |
dann frazier | 86ded1f | 2010-07-27 17:51:02 -0600 | [diff] [blame] | 321 | return 0; |
| 322 | } |
| 323 | |
Axel Lin | b77b708 | 2011-03-02 11:49:44 +0800 | [diff] [blame] | 324 | static void hpwdt_exit_nmi_decoding(void) |
dann frazier | 86ded1f | 2010-07-27 17:51:02 -0600 | [diff] [blame] | 325 | { |
Jerry Hoemann | 25d5767 | 2018-02-25 20:22:20 -0700 | [diff] [blame] | 326 | #ifdef CONFIG_HPWDT_NMI_DECODING |
| 327 | unregister_nmi_handler(NMI_UNKNOWN, "hpwdt"); |
| 328 | unregister_nmi_handler(NMI_SERR, "hpwdt"); |
| 329 | unregister_nmi_handler(NMI_IO_CHECK, "hpwdt"); |
| 330 | #endif |
dann frazier | 86ded1f | 2010-07-27 17:51:02 -0600 | [diff] [blame] | 331 | } |
Thomas Mingarelli | 47bece8 | 2009-06-04 19:50:45 +0000 | [diff] [blame] | 332 | |
Bill Pemberton | 2d991a1 | 2012-11-19 13:21:41 -0500 | [diff] [blame] | 333 | static int hpwdt_init_one(struct pci_dev *dev, |
Thomas Mingarelli | ab4ba3c | 2008-07-15 19:40:41 +0000 | [diff] [blame] | 334 | const struct pci_device_id *ent) |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 335 | { |
| 336 | int retval; |
| 337 | |
| 338 | /* |
dann frazier | 36e3ff4 | 2010-07-27 17:50:57 -0600 | [diff] [blame] | 339 | * First let's find out if we are on an iLO2+ server. We will |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 340 | * not run on a legacy ASM box. |
Thomas Mingarelli | ab4ba3c | 2008-07-15 19:40:41 +0000 | [diff] [blame] | 341 | * So we only support the G5 ProLiant servers and higher. |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 342 | */ |
Brian Boylston | fc113d5 | 2016-09-26 13:57:14 -0500 | [diff] [blame] | 343 | if (dev->subsystem_vendor != PCI_VENDOR_ID_HP && |
| 344 | dev->subsystem_vendor != PCI_VENDOR_ID_HP_3PAR) { |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 345 | dev_warn(&dev->dev, |
dann frazier | 36e3ff4 | 2010-07-27 17:50:57 -0600 | [diff] [blame] | 346 | "This server does not have an iLO2+ ASIC.\n"); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 347 | return -ENODEV; |
| 348 | } |
| 349 | |
Mingarelli, Thomas | 0821f20 | 2013-08-09 16:31:09 +0000 | [diff] [blame] | 350 | /* |
| 351 | * Ignore all auxilary iLO devices with the following PCI ID |
| 352 | */ |
Brian Boylston | fc113d5 | 2016-09-26 13:57:14 -0500 | [diff] [blame] | 353 | if (dev->subsystem_vendor == PCI_VENDOR_ID_HP && |
| 354 | dev->subsystem_device == 0x1979) |
Mingarelli, Thomas | 0821f20 | 2013-08-09 16:31:09 +0000 | [diff] [blame] | 355 | return -ENODEV; |
| 356 | |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 357 | if (pci_enable_device(dev)) { |
| 358 | dev_warn(&dev->dev, |
| 359 | "Not possible to enable PCI Device: 0x%x:0x%x.\n", |
| 360 | ent->vendor, ent->device); |
| 361 | return -ENODEV; |
| 362 | } |
| 363 | |
| 364 | pci_mem_addr = pci_iomap(dev, 1, 0x80); |
| 365 | if (!pci_mem_addr) { |
| 366 | dev_warn(&dev->dev, |
dann frazier | 36e3ff4 | 2010-07-27 17:50:57 -0600 | [diff] [blame] | 367 | "Unable to detect the iLO2+ server memory.\n"); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 368 | retval = -ENOMEM; |
| 369 | goto error_pci_iomap; |
| 370 | } |
Jerry Hoemann | c387231 | 2017-10-23 16:46:17 -0600 | [diff] [blame] | 371 | hpwdt_nmistat = pci_mem_addr + 0x6e; |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 372 | hpwdt_timer_reg = pci_mem_addr + 0x70; |
| 373 | hpwdt_timer_con = pci_mem_addr + 0x72; |
| 374 | |
Toshi Kani | 308b135 | 2012-08-27 12:52:24 -0600 | [diff] [blame] | 375 | /* Make sure that timer is disabled until /dev/watchdog is opened */ |
| 376 | hpwdt_stop(); |
| 377 | |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 378 | /* Make sure that we have a valid soft_margin */ |
| 379 | if (hpwdt_change_timer(soft_margin)) |
| 380 | hpwdt_change_timer(DEFAULT_MARGIN); |
| 381 | |
dann frazier | 2ec7ed6 | 2010-07-28 12:38:43 -0600 | [diff] [blame] | 382 | /* Initialize NMI Decoding functionality */ |
| 383 | retval = hpwdt_init_nmi_decoding(dev); |
| 384 | if (retval != 0) |
| 385 | goto error_init_nmi_decoding; |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 386 | |
| 387 | retval = misc_register(&hpwdt_miscdev); |
| 388 | if (retval < 0) { |
| 389 | dev_warn(&dev->dev, |
| 390 | "Unable to register miscdev on minor=%d (err=%d).\n", |
| 391 | WATCHDOG_MINOR, retval); |
| 392 | goto error_misc_register; |
| 393 | } |
| 394 | |
Mingarelli, Thomas | ca22e79 | 2015-12-14 20:22:09 +0000 | [diff] [blame] | 395 | dev_info(&dev->dev, "HPE Watchdog Timer Driver: %s" |
dann frazier | 2ec7ed6 | 2010-07-28 12:38:43 -0600 | [diff] [blame] | 396 | ", timer margin: %d seconds (nowayout=%d).\n", |
| 397 | HPWDT_VERSION, soft_margin, nowayout); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 398 | return 0; |
| 399 | |
| 400 | error_misc_register: |
dann frazier | 2ec7ed6 | 2010-07-28 12:38:43 -0600 | [diff] [blame] | 401 | hpwdt_exit_nmi_decoding(); |
| 402 | error_init_nmi_decoding: |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 403 | pci_iounmap(dev, pci_mem_addr); |
| 404 | error_pci_iomap: |
| 405 | pci_disable_device(dev); |
| 406 | return retval; |
| 407 | } |
| 408 | |
Bill Pemberton | 4b12b89 | 2012-11-19 13:26:24 -0500 | [diff] [blame] | 409 | static void hpwdt_exit(struct pci_dev *dev) |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 410 | { |
| 411 | if (!nowayout) |
| 412 | hpwdt_stop(); |
| 413 | |
| 414 | misc_deregister(&hpwdt_miscdev); |
dann frazier | 2ec7ed6 | 2010-07-28 12:38:43 -0600 | [diff] [blame] | 415 | hpwdt_exit_nmi_decoding(); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 416 | pci_iounmap(dev, pci_mem_addr); |
| 417 | pci_disable_device(dev); |
| 418 | } |
| 419 | |
| 420 | static struct pci_driver hpwdt_driver = { |
| 421 | .name = "hpwdt", |
| 422 | .id_table = hpwdt_devices, |
| 423 | .probe = hpwdt_init_one, |
Bill Pemberton | 8226871 | 2012-11-19 13:21:12 -0500 | [diff] [blame] | 424 | .remove = hpwdt_exit, |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 425 | }; |
| 426 | |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 427 | MODULE_AUTHOR("Tom Mingarelli"); |
| 428 | MODULE_DESCRIPTION("hp watchdog driver"); |
| 429 | MODULE_LICENSE("GPL"); |
Thomas Mingarelli | d8100c3 | 2009-03-03 00:17:16 +0000 | [diff] [blame] | 430 | MODULE_VERSION(HPWDT_VERSION); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 431 | |
| 432 | module_param(soft_margin, int, 0); |
| 433 | MODULE_PARM_DESC(soft_margin, "Watchdog timeout in seconds"); |
| 434 | |
Wim Van Sebroeck | 86a1e18 | 2012-03-05 16:51:11 +0100 | [diff] [blame] | 435 | module_param(nowayout, bool, 0); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 436 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" |
| 437 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
| 438 | |
dann frazier | 86ded1f | 2010-07-27 17:51:02 -0600 | [diff] [blame] | 439 | #ifdef CONFIG_HPWDT_NMI_DECODING |
dann frazier | 550d299 | 2010-07-27 17:50:54 -0600 | [diff] [blame] | 440 | module_param(allow_kdump, int, 0); |
| 441 | MODULE_PARM_DESC(allow_kdump, "Start a kernel dump after NMI occurs"); |
Jerry Hoemann | 25d5767 | 2018-02-25 20:22:20 -0700 | [diff] [blame] | 442 | #endif /* CONFIG_HPWDT_NMI_DECODING */ |
Tom Mingarelli | 44df753 | 2009-06-18 23:28:57 +0000 | [diff] [blame] | 443 | |
Wim Van Sebroeck | 5ce9c37 | 2012-05-04 14:43:25 +0200 | [diff] [blame] | 444 | module_pci_driver(hpwdt_driver); |