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 | * |
Jerry Hoemann | 9a46fc4 | 2018-02-25 20:22:19 -0700 | [diff] [blame] | 7 | * (c) Copyright 2018 Hewlett Packard Enterprise Development LP |
Mingarelli, Thomas | ca22e79 | 2015-12-14 20:22:09 +0000 | [diff] [blame] | 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> |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 19 | #include <linux/io.h> |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 20 | #include <linux/kernel.h> |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 21 | #include <linux/module.h> |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 22 | #include <linux/moduleparam.h> |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 23 | #include <linux/pci.h> |
| 24 | #include <linux/pci_ids.h> |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 25 | #include <linux/types.h> |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 26 | #include <linux/watchdog.h> |
Ingo Molnar | d48b0e1 | 2011-10-06 14:20:27 +0200 | [diff] [blame] | 27 | #include <asm/nmi.h> |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 28 | |
Jerry Hoemann | e1c7f79 | 2018-08-08 13:13:27 -0600 | [diff] [blame] | 29 | #define HPWDT_VERSION "2.0.1" |
dann frazier | e802e32 | 2010-06-02 16:23:39 -0600 | [diff] [blame] | 30 | #define SECS_TO_TICKS(secs) ((secs) * 1000 / 128) |
dann frazier | 6f681c2 | 2010-06-02 16:23:40 -0600 | [diff] [blame] | 31 | #define TICKS_TO_SECS(ticks) ((ticks) * 128 / 1000) |
| 32 | #define HPWDT_MAX_TIMER TICKS_TO_SECS(65535) |
dann frazier | 923410d | 2010-07-27 17:50:54 -0600 | [diff] [blame] | 33 | #define DEFAULT_MARGIN 30 |
Jerry Hoemann | 0458f40 | 2018-02-25 20:22:25 -0700 | [diff] [blame] | 34 | #define PRETIMEOUT_SEC 9 |
dann frazier | 923410d | 2010-07-27 17:50:54 -0600 | [diff] [blame] | 35 | |
Jerry Hoemann | a6c2473 | 2018-02-25 20:22:23 -0700 | [diff] [blame] | 36 | static bool ilo5; |
dann frazier | 923410d | 2010-07-27 17:50:54 -0600 | [diff] [blame] | 37 | static unsigned int soft_margin = DEFAULT_MARGIN; /* in seconds */ |
Wim Van Sebroeck | 86a1e18 | 2012-03-05 16:51:11 +0100 | [diff] [blame] | 38 | static bool nowayout = WATCHDOG_NOWAYOUT; |
Jerry Hoemann | 0458f40 | 2018-02-25 20:22:25 -0700 | [diff] [blame] | 39 | static bool pretimeout = IS_ENABLED(CONFIG_HPWDT_NMI_DECODING); |
dann frazier | 923410d | 2010-07-27 17:50:54 -0600 | [diff] [blame] | 40 | |
| 41 | static void __iomem *pci_mem_addr; /* the PCI-memory address */ |
Jerry Hoemann | 838534e | 2017-10-23 16:46:17 -0600 | [diff] [blame] | 42 | static unsigned long __iomem *hpwdt_nmistat; |
dann frazier | 923410d | 2010-07-27 17:50:54 -0600 | [diff] [blame] | 43 | static unsigned long __iomem *hpwdt_timer_reg; |
| 44 | static unsigned long __iomem *hpwdt_timer_con; |
| 45 | |
Jingoo Han | bc17f9d | 2013-12-03 08:30:22 +0900 | [diff] [blame] | 46 | static const struct pci_device_id hpwdt_devices[] = { |
dann frazier | 36e3ff4 | 2010-07-27 17:50:57 -0600 | [diff] [blame] | 47 | { PCI_DEVICE(PCI_VENDOR_ID_COMPAQ, 0xB203) }, /* iLO2 */ |
| 48 | { PCI_DEVICE(PCI_VENDOR_ID_HP, 0x3306) }, /* iLO3 */ |
dann frazier | 923410d | 2010-07-27 17:50:54 -0600 | [diff] [blame] | 49 | {0}, /* terminate list */ |
| 50 | }; |
| 51 | MODULE_DEVICE_TABLE(pci, hpwdt_devices); |
| 52 | |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 53 | |
| 54 | /* |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 55 | * Watchdog operations |
| 56 | */ |
Jerry Hoemann | d0a4027 | 2018-02-25 20:22:22 -0700 | [diff] [blame] | 57 | static int hpwdt_start(struct watchdog_device *wdd) |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 58 | { |
Jerry Hoemann | 0458f40 | 2018-02-25 20:22:25 -0700 | [diff] [blame] | 59 | int control = 0x81 | (pretimeout ? 0x4 : 0); |
| 60 | int reload = SECS_TO_TICKS(wdd->timeout); |
Jerry Hoemann | d0a4027 | 2018-02-25 20:22:22 -0700 | [diff] [blame] | 61 | |
Jerry Hoemann | ccfd692 | 2018-02-25 20:22:26 -0700 | [diff] [blame] | 62 | dev_dbg(wdd->parent, "start watchdog 0x%08x:0x%02x\n", reload, control); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 63 | iowrite16(reload, hpwdt_timer_reg); |
Jerry Hoemann | 0458f40 | 2018-02-25 20:22:25 -0700 | [diff] [blame] | 64 | iowrite8(control, hpwdt_timer_con); |
Jerry Hoemann | d0a4027 | 2018-02-25 20:22:22 -0700 | [diff] [blame] | 65 | |
| 66 | return 0; |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static void hpwdt_stop(void) |
| 70 | { |
| 71 | unsigned long data; |
| 72 | |
Jerry Hoemann | ccfd692 | 2018-02-25 20:22:26 -0700 | [diff] [blame] | 73 | pr_debug("stop watchdog\n"); |
| 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 | |
Jerry Hoemann | d0a4027 | 2018-02-25 20:22:22 -0700 | [diff] [blame] | 80 | static int hpwdt_stop_core(struct watchdog_device *wdd) |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 81 | { |
Jerry Hoemann | d0a4027 | 2018-02-25 20:22:22 -0700 | [diff] [blame] | 82 | hpwdt_stop(); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
Jerry Hoemann | d0a4027 | 2018-02-25 20:22:22 -0700 | [diff] [blame] | 87 | static int hpwdt_ping(struct watchdog_device *wdd) |
| 88 | { |
Jerry Hoemann | 0458f40 | 2018-02-25 20:22:25 -0700 | [diff] [blame] | 89 | int reload = SECS_TO_TICKS(wdd->timeout); |
| 90 | |
Jerry Hoemann | ccfd692 | 2018-02-25 20:22:26 -0700 | [diff] [blame] | 91 | dev_dbg(wdd->parent, "ping watchdog 0x%08x\n", reload); |
Jerry Hoemann | d0a4027 | 2018-02-25 20:22:22 -0700 | [diff] [blame] | 92 | iowrite16(reload, hpwdt_timer_reg); |
Jerry Hoemann | 0458f40 | 2018-02-25 20:22:25 -0700 | [diff] [blame] | 93 | |
Jerry Hoemann | d0a4027 | 2018-02-25 20:22:22 -0700 | [diff] [blame] | 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | static unsigned int hpwdt_gettimeleft(struct watchdog_device *wdd) |
dann frazier | aae67f3 | 2010-06-02 16:23:41 -0600 | [diff] [blame] | 98 | { |
| 99 | return TICKS_TO_SECS(ioread16(hpwdt_timer_reg)); |
| 100 | } |
| 101 | |
Jerry Hoemann | d0a4027 | 2018-02-25 20:22:22 -0700 | [diff] [blame] | 102 | static int hpwdt_settimeout(struct watchdog_device *wdd, unsigned int val) |
| 103 | { |
Jerry Hoemann | ccfd692 | 2018-02-25 20:22:26 -0700 | [diff] [blame] | 104 | dev_dbg(wdd->parent, "set_timeout = %d\n", val); |
| 105 | |
Jerry Hoemann | d0a4027 | 2018-02-25 20:22:22 -0700 | [diff] [blame] | 106 | wdd->timeout = val; |
Jerry Hoemann | 0458f40 | 2018-02-25 20:22:25 -0700 | [diff] [blame] | 107 | if (val <= wdd->pretimeout) { |
Jerry Hoemann | ccfd692 | 2018-02-25 20:22:26 -0700 | [diff] [blame] | 108 | dev_dbg(wdd->parent, "pretimeout < timeout. Setting to zero\n"); |
Jerry Hoemann | 0458f40 | 2018-02-25 20:22:25 -0700 | [diff] [blame] | 109 | wdd->pretimeout = 0; |
| 110 | pretimeout = 0; |
| 111 | if (watchdog_active(wdd)) |
| 112 | hpwdt_start(wdd); |
| 113 | } |
Jerry Hoemann | d0a4027 | 2018-02-25 20:22:22 -0700 | [diff] [blame] | 114 | hpwdt_ping(wdd); |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
Arnd Bergmann | aeebc6b | 2017-12-06 22:02:37 +0100 | [diff] [blame] | 119 | #ifdef CONFIG_HPWDT_NMI_DECODING |
Jerry Hoemann | 0458f40 | 2018-02-25 20:22:25 -0700 | [diff] [blame] | 120 | static int hpwdt_set_pretimeout(struct watchdog_device *wdd, unsigned int req) |
| 121 | { |
| 122 | unsigned int val = 0; |
| 123 | |
Jerry Hoemann | ccfd692 | 2018-02-25 20:22:26 -0700 | [diff] [blame] | 124 | dev_dbg(wdd->parent, "set_pretimeout = %d\n", req); |
Jerry Hoemann | 0458f40 | 2018-02-25 20:22:25 -0700 | [diff] [blame] | 125 | if (req) { |
| 126 | val = PRETIMEOUT_SEC; |
| 127 | if (val >= wdd->timeout) |
| 128 | return -EINVAL; |
| 129 | } |
| 130 | |
Jerry Hoemann | ccfd692 | 2018-02-25 20:22:26 -0700 | [diff] [blame] | 131 | if (val != req) |
| 132 | dev_dbg(wdd->parent, "Rounding pretimeout to: %d\n", val); |
| 133 | |
Jerry Hoemann | 0458f40 | 2018-02-25 20:22:25 -0700 | [diff] [blame] | 134 | wdd->pretimeout = val; |
| 135 | pretimeout = !!val; |
| 136 | |
| 137 | if (watchdog_active(wdd)) |
| 138 | hpwdt_start(wdd); |
| 139 | |
| 140 | return 0; |
| 141 | } |
| 142 | |
Jerry Hoemann | 838534e | 2017-10-23 16:46:17 -0600 | [diff] [blame] | 143 | static int hpwdt_my_nmi(void) |
| 144 | { |
| 145 | return ioread8(hpwdt_nmistat) & 0x6; |
| 146 | } |
| 147 | |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 148 | /* |
Thomas Mingarelli | ab4ba3c | 2008-07-15 19:40:41 +0000 | [diff] [blame] | 149 | * NMI Handler |
| 150 | */ |
Don Zickus | 9c48f1c | 2011-09-30 15:06:21 -0400 | [diff] [blame] | 151 | static int hpwdt_pretimeout(unsigned int ulReason, struct pt_regs *regs) |
Thomas Mingarelli | ab4ba3c | 2008-07-15 19:40:41 +0000 | [diff] [blame] | 152 | { |
Jerry Hoemann | a042229 | 2018-02-25 20:22:21 -0700 | [diff] [blame] | 153 | unsigned int mynmi = hpwdt_my_nmi(); |
| 154 | static char panic_msg[] = |
| 155 | "00: An NMI occurred. Depending on your system the reason " |
| 156 | "for the NMI is logged in any one of the following resources:\n" |
| 157 | "1. Integrated Management Log (IML)\n" |
| 158 | "2. OA Syslog\n" |
| 159 | "3. OA Forward Progress Log\n" |
| 160 | "4. iLO Event Log"; |
| 161 | |
Jerry Hoemann | 62290a5 | 2018-05-03 15:00:55 -0600 | [diff] [blame] | 162 | if (ilo5 && ulReason == NMI_UNKNOWN && !mynmi) |
Jerry Hoemann | 838534e | 2017-10-23 16:46:17 -0600 | [diff] [blame] | 163 | return NMI_DONE; |
| 164 | |
Jerry Hoemann | 093d438 | 2018-08-08 13:13:24 -0600 | [diff] [blame] | 165 | if (ilo5 && !pretimeout && !mynmi) |
Jerry Hoemann | 0458f40 | 2018-02-25 20:22:25 -0700 | [diff] [blame] | 166 | return NMI_DONE; |
| 167 | |
Jerry Hoemann | 703fc3d | 2018-02-25 20:22:24 -0700 | [diff] [blame] | 168 | hpwdt_stop(); |
Naga Chumbalkar | dbc018e | 2011-08-09 22:27:26 +0000 | [diff] [blame] | 169 | |
Jerry Hoemann | a042229 | 2018-02-25 20:22:21 -0700 | [diff] [blame] | 170 | hex_byte_pack(panic_msg, mynmi); |
| 171 | nmi_panic(regs, panic_msg); |
Thomas Mingarelli | 5efc7a6 | 2011-07-26 14:05:53 +0100 | [diff] [blame] | 172 | |
Hidehiro Kawai | abc514c | 2016-03-22 14:27:24 -0700 | [diff] [blame] | 173 | return NMI_HANDLED; |
Thomas Mingarelli | ab4ba3c | 2008-07-15 19:40:41 +0000 | [diff] [blame] | 174 | } |
dann frazier | 86ded1f | 2010-07-27 17:51:02 -0600 | [diff] [blame] | 175 | #endif /* CONFIG_HPWDT_NMI_DECODING */ |
Thomas Mingarelli | ab4ba3c | 2008-07-15 19:40:41 +0000 | [diff] [blame] | 176 | |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 177 | |
Wim Van Sebroeck | 42747d7 | 2009-12-26 18:55:22 +0000 | [diff] [blame] | 178 | static const struct watchdog_info ident = { |
Jerry Hoemann | 0458f40 | 2018-02-25 20:22:25 -0700 | [diff] [blame] | 179 | .options = WDIOF_PRETIMEOUT | |
| 180 | WDIOF_SETTIMEOUT | |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 181 | WDIOF_KEEPALIVEPING | |
| 182 | WDIOF_MAGICCLOSE, |
Mingarelli, Thomas | ca22e79 | 2015-12-14 20:22:09 +0000 | [diff] [blame] | 183 | .identity = "HPE iLO2+ HW Watchdog Timer", |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 184 | }; |
| 185 | |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 186 | /* |
| 187 | * Kernel interfaces |
| 188 | */ |
Jerry Hoemann | d0a4027 | 2018-02-25 20:22:22 -0700 | [diff] [blame] | 189 | |
| 190 | static const struct watchdog_ops hpwdt_ops = { |
| 191 | .owner = THIS_MODULE, |
| 192 | .start = hpwdt_start, |
| 193 | .stop = hpwdt_stop_core, |
| 194 | .ping = hpwdt_ping, |
| 195 | .set_timeout = hpwdt_settimeout, |
| 196 | .get_timeleft = hpwdt_gettimeleft, |
Jerry Hoemann | 0458f40 | 2018-02-25 20:22:25 -0700 | [diff] [blame] | 197 | #ifdef CONFIG_HPWDT_NMI_DECODING |
| 198 | .set_pretimeout = hpwdt_set_pretimeout, |
| 199 | #endif |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 200 | }; |
| 201 | |
Jerry Hoemann | d0a4027 | 2018-02-25 20:22:22 -0700 | [diff] [blame] | 202 | static struct watchdog_device hpwdt_dev = { |
| 203 | .info = &ident, |
| 204 | .ops = &hpwdt_ops, |
| 205 | .min_timeout = 1, |
| 206 | .max_timeout = HPWDT_MAX_TIMER, |
| 207 | .timeout = DEFAULT_MARGIN, |
Jerry Hoemann | 0458f40 | 2018-02-25 20:22:25 -0700 | [diff] [blame] | 208 | .pretimeout = PRETIMEOUT_SEC, |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 209 | }; |
| 210 | |
Jerry Hoemann | d0a4027 | 2018-02-25 20:22:22 -0700 | [diff] [blame] | 211 | |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 212 | /* |
| 213 | * Init & Exit |
| 214 | */ |
| 215 | |
Bill Pemberton | 2d991a1 | 2012-11-19 13:21:41 -0500 | [diff] [blame] | 216 | static int hpwdt_init_nmi_decoding(struct pci_dev *dev) |
dann frazier | 2ec7ed6 | 2010-07-28 12:38:43 -0600 | [diff] [blame] | 217 | { |
Jerry Hoemann | 2b3d89b | 2018-02-25 20:22:20 -0700 | [diff] [blame] | 218 | #ifdef CONFIG_HPWDT_NMI_DECODING |
dann frazier | 2ec7ed6 | 2010-07-28 12:38:43 -0600 | [diff] [blame] | 219 | int retval; |
dann frazier | 2ec7ed6 | 2010-07-28 12:38:43 -0600 | [diff] [blame] | 220 | /* |
Don Zickus | 09ee101 | 2012-03-29 16:11:15 -0400 | [diff] [blame] | 221 | * Only one function can register for NMI_UNKNOWN |
dann frazier | 2ec7ed6 | 2010-07-28 12:38:43 -0600 | [diff] [blame] | 222 | */ |
Don Zickus | 09ee101 | 2012-03-29 16:11:15 -0400 | [diff] [blame] | 223 | retval = register_nmi_handler(NMI_UNKNOWN, hpwdt_pretimeout, 0, "hpwdt"); |
Don Zickus | 553222f | 2012-03-29 16:11:16 -0400 | [diff] [blame] | 224 | if (retval) |
| 225 | goto error; |
| 226 | retval = register_nmi_handler(NMI_SERR, hpwdt_pretimeout, 0, "hpwdt"); |
| 227 | if (retval) |
| 228 | goto error1; |
| 229 | retval = register_nmi_handler(NMI_IO_CHECK, hpwdt_pretimeout, 0, "hpwdt"); |
| 230 | if (retval) |
| 231 | goto error2; |
dann frazier | 2ec7ed6 | 2010-07-28 12:38:43 -0600 | [diff] [blame] | 232 | |
| 233 | dev_info(&dev->dev, |
Jerry Hoemann | 703fc3d | 2018-02-25 20:22:24 -0700 | [diff] [blame] | 234 | "HPE Watchdog Timer Driver: NMI decoding initialized\n"); |
| 235 | |
dann frazier | 2ec7ed6 | 2010-07-28 12:38:43 -0600 | [diff] [blame] | 236 | return 0; |
Don Zickus | 553222f | 2012-03-29 16:11:16 -0400 | [diff] [blame] | 237 | |
| 238 | error2: |
| 239 | unregister_nmi_handler(NMI_SERR, "hpwdt"); |
| 240 | error1: |
| 241 | unregister_nmi_handler(NMI_UNKNOWN, "hpwdt"); |
| 242 | error: |
| 243 | dev_warn(&dev->dev, |
| 244 | "Unable to register a die notifier (err=%d).\n", |
| 245 | retval); |
Don Zickus | 553222f | 2012-03-29 16:11:16 -0400 | [diff] [blame] | 246 | return retval; |
Jerry Hoemann | 2b3d89b | 2018-02-25 20:22:20 -0700 | [diff] [blame] | 247 | #endif /* CONFIG_HPWDT_NMI_DECODING */ |
dann frazier | 86ded1f | 2010-07-27 17:51:02 -0600 | [diff] [blame] | 248 | return 0; |
| 249 | } |
| 250 | |
Axel Lin | b77b708 | 2011-03-02 11:49:44 +0800 | [diff] [blame] | 251 | static void hpwdt_exit_nmi_decoding(void) |
dann frazier | 86ded1f | 2010-07-27 17:51:02 -0600 | [diff] [blame] | 252 | { |
Jerry Hoemann | 2b3d89b | 2018-02-25 20:22:20 -0700 | [diff] [blame] | 253 | #ifdef CONFIG_HPWDT_NMI_DECODING |
| 254 | unregister_nmi_handler(NMI_UNKNOWN, "hpwdt"); |
| 255 | unregister_nmi_handler(NMI_SERR, "hpwdt"); |
| 256 | unregister_nmi_handler(NMI_IO_CHECK, "hpwdt"); |
| 257 | #endif |
dann frazier | 86ded1f | 2010-07-27 17:51:02 -0600 | [diff] [blame] | 258 | } |
Thomas Mingarelli | 47bece8 | 2009-06-04 19:50:45 +0000 | [diff] [blame] | 259 | |
Bill Pemberton | 2d991a1 | 2012-11-19 13:21:41 -0500 | [diff] [blame] | 260 | static int hpwdt_init_one(struct pci_dev *dev, |
Thomas Mingarelli | ab4ba3c | 2008-07-15 19:40:41 +0000 | [diff] [blame] | 261 | const struct pci_device_id *ent) |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 262 | { |
| 263 | int retval; |
| 264 | |
| 265 | /* |
dann frazier | 36e3ff4 | 2010-07-27 17:50:57 -0600 | [diff] [blame] | 266 | * 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] | 267 | * not run on a legacy ASM box. |
Thomas Mingarelli | ab4ba3c | 2008-07-15 19:40:41 +0000 | [diff] [blame] | 268 | * So we only support the G5 ProLiant servers and higher. |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 269 | */ |
Brian Boylston | fc113d5 | 2016-09-26 13:57:14 -0500 | [diff] [blame] | 270 | if (dev->subsystem_vendor != PCI_VENDOR_ID_HP && |
| 271 | dev->subsystem_vendor != PCI_VENDOR_ID_HP_3PAR) { |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 272 | dev_warn(&dev->dev, |
dann frazier | 36e3ff4 | 2010-07-27 17:50:57 -0600 | [diff] [blame] | 273 | "This server does not have an iLO2+ ASIC.\n"); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 274 | return -ENODEV; |
| 275 | } |
| 276 | |
Mingarelli, Thomas | 0821f20 | 2013-08-09 16:31:09 +0000 | [diff] [blame] | 277 | /* |
| 278 | * Ignore all auxilary iLO devices with the following PCI ID |
| 279 | */ |
Brian Boylston | fc113d5 | 2016-09-26 13:57:14 -0500 | [diff] [blame] | 280 | if (dev->subsystem_vendor == PCI_VENDOR_ID_HP && |
| 281 | dev->subsystem_device == 0x1979) |
Mingarelli, Thomas | 0821f20 | 2013-08-09 16:31:09 +0000 | [diff] [blame] | 282 | return -ENODEV; |
| 283 | |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 284 | if (pci_enable_device(dev)) { |
| 285 | dev_warn(&dev->dev, |
| 286 | "Not possible to enable PCI Device: 0x%x:0x%x.\n", |
| 287 | ent->vendor, ent->device); |
| 288 | return -ENODEV; |
| 289 | } |
| 290 | |
| 291 | pci_mem_addr = pci_iomap(dev, 1, 0x80); |
| 292 | if (!pci_mem_addr) { |
| 293 | dev_warn(&dev->dev, |
dann frazier | 36e3ff4 | 2010-07-27 17:50:57 -0600 | [diff] [blame] | 294 | "Unable to detect the iLO2+ server memory.\n"); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 295 | retval = -ENOMEM; |
| 296 | goto error_pci_iomap; |
| 297 | } |
Jerry Hoemann | 838534e | 2017-10-23 16:46:17 -0600 | [diff] [blame] | 298 | hpwdt_nmistat = pci_mem_addr + 0x6e; |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 299 | hpwdt_timer_reg = pci_mem_addr + 0x70; |
| 300 | hpwdt_timer_con = pci_mem_addr + 0x72; |
| 301 | |
Toshi Kani | 308b135 | 2012-08-27 12:52:24 -0600 | [diff] [blame] | 302 | /* Make sure that timer is disabled until /dev/watchdog is opened */ |
| 303 | hpwdt_stop(); |
| 304 | |
dann frazier | 2ec7ed6 | 2010-07-28 12:38:43 -0600 | [diff] [blame] | 305 | /* Initialize NMI Decoding functionality */ |
| 306 | retval = hpwdt_init_nmi_decoding(dev); |
| 307 | if (retval != 0) |
| 308 | goto error_init_nmi_decoding; |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 309 | |
Jerry Hoemann | d0a4027 | 2018-02-25 20:22:22 -0700 | [diff] [blame] | 310 | watchdog_set_nowayout(&hpwdt_dev, nowayout); |
| 311 | if (watchdog_init_timeout(&hpwdt_dev, soft_margin, NULL)) |
| 312 | dev_warn(&dev->dev, "Invalid soft_margin: %d.\n", soft_margin); |
| 313 | |
Jerry Hoemann | 10d790d1 | 2018-09-21 14:50:39 -0600 | [diff] [blame^] | 314 | if (pretimeout && hpwdt_dev.timeout <= PRETIMEOUT_SEC) { |
| 315 | dev_warn(&dev->dev, "timeout <= pretimeout. Setting pretimeout to zero\n"); |
| 316 | pretimeout = 0; |
| 317 | } |
Jerry Hoemann | 4d9186d | 2018-08-08 13:13:23 -0600 | [diff] [blame] | 318 | hpwdt_dev.pretimeout = pretimeout ? PRETIMEOUT_SEC : 0; |
| 319 | |
Jerry Hoemann | d0a4027 | 2018-02-25 20:22:22 -0700 | [diff] [blame] | 320 | hpwdt_dev.parent = &dev->dev; |
| 321 | retval = watchdog_register_device(&hpwdt_dev); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 322 | if (retval < 0) { |
Jerry Hoemann | d0a4027 | 2018-02-25 20:22:22 -0700 | [diff] [blame] | 323 | dev_err(&dev->dev, "watchdog register failed: %d.\n", retval); |
| 324 | goto error_wd_register; |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Jerry Hoemann | 9230146 | 2018-08-08 13:13:25 -0600 | [diff] [blame] | 327 | dev_info(&dev->dev, "HPE Watchdog Timer Driver: Version: %s\n", |
| 328 | HPWDT_VERSION); |
| 329 | dev_info(&dev->dev, "timeout: %d seconds (nowayout=%d)\n", |
| 330 | hpwdt_dev.timeout, nowayout); |
| 331 | dev_info(&dev->dev, "pretimeout: %s.\n", |
| 332 | pretimeout ? "on" : "off"); |
Jerry Hoemann | d0a4027 | 2018-02-25 20:22:22 -0700 | [diff] [blame] | 333 | |
Jerry Hoemann | a6c2473 | 2018-02-25 20:22:23 -0700 | [diff] [blame] | 334 | if (dev->subsystem_vendor == PCI_VENDOR_ID_HP_3PAR) |
| 335 | ilo5 = true; |
| 336 | |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 337 | return 0; |
| 338 | |
Jerry Hoemann | d0a4027 | 2018-02-25 20:22:22 -0700 | [diff] [blame] | 339 | error_wd_register: |
dann frazier | 2ec7ed6 | 2010-07-28 12:38:43 -0600 | [diff] [blame] | 340 | hpwdt_exit_nmi_decoding(); |
| 341 | error_init_nmi_decoding: |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 342 | pci_iounmap(dev, pci_mem_addr); |
| 343 | error_pci_iomap: |
| 344 | pci_disable_device(dev); |
| 345 | return retval; |
| 346 | } |
| 347 | |
Bill Pemberton | 4b12b89 | 2012-11-19 13:26:24 -0500 | [diff] [blame] | 348 | static void hpwdt_exit(struct pci_dev *dev) |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 349 | { |
| 350 | if (!nowayout) |
| 351 | hpwdt_stop(); |
| 352 | |
Jerry Hoemann | d0a4027 | 2018-02-25 20:22:22 -0700 | [diff] [blame] | 353 | watchdog_unregister_device(&hpwdt_dev); |
dann frazier | 2ec7ed6 | 2010-07-28 12:38:43 -0600 | [diff] [blame] | 354 | hpwdt_exit_nmi_decoding(); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 355 | pci_iounmap(dev, pci_mem_addr); |
| 356 | pci_disable_device(dev); |
| 357 | } |
| 358 | |
| 359 | static struct pci_driver hpwdt_driver = { |
| 360 | .name = "hpwdt", |
| 361 | .id_table = hpwdt_devices, |
| 362 | .probe = hpwdt_init_one, |
Bill Pemberton | 8226871 | 2012-11-19 13:21:12 -0500 | [diff] [blame] | 363 | .remove = hpwdt_exit, |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 364 | }; |
| 365 | |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 366 | MODULE_AUTHOR("Tom Mingarelli"); |
Jerry Hoemann | 9a46fc4 | 2018-02-25 20:22:19 -0700 | [diff] [blame] | 367 | MODULE_DESCRIPTION("hpe watchdog driver"); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 368 | MODULE_LICENSE("GPL"); |
Thomas Mingarelli | d8100c3 | 2009-03-03 00:17:16 +0000 | [diff] [blame] | 369 | MODULE_VERSION(HPWDT_VERSION); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 370 | |
| 371 | module_param(soft_margin, int, 0); |
| 372 | MODULE_PARM_DESC(soft_margin, "Watchdog timeout in seconds"); |
| 373 | |
Jerry Hoemann | 397a35d | 2018-08-08 13:13:26 -0600 | [diff] [blame] | 374 | module_param_named(timeout, soft_margin, int, 0); |
| 375 | MODULE_PARM_DESC(timeout, "Alias of soft_margin"); |
| 376 | |
Wim Van Sebroeck | 86a1e18 | 2012-03-05 16:51:11 +0100 | [diff] [blame] | 377 | module_param(nowayout, bool, 0); |
Thomas Mingarelli | 7f4da47 | 2007-12-04 17:41:54 +0000 | [diff] [blame] | 378 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" |
| 379 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
| 380 | |
Jerry Hoemann | 0458f40 | 2018-02-25 20:22:25 -0700 | [diff] [blame] | 381 | #ifdef CONFIG_HPWDT_NMI_DECODING |
| 382 | module_param(pretimeout, bool, 0); |
| 383 | MODULE_PARM_DESC(pretimeout, "Watchdog pretimeout enabled"); |
| 384 | #endif |
| 385 | |
Wim Van Sebroeck | 5ce9c37 | 2012-05-04 14:43:25 +0200 | [diff] [blame] | 386 | module_pci_driver(hpwdt_driver); |