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