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