blob: a5006a58e0dbb680167197c0c9466e6982dc9c2e [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Thomas Mingarelli7f4da472007-12-04 17:41:54 +00002/*
Mingarelli, Thomasca22e792015-12-14 20:22:09 +00003 * HPE WatchDog Driver
Thomas Mingarelli7f4da472007-12-04 17:41:54 +00004 * based on
5 *
6 * SoftDog 0.05: A Software Watchdog Device
7 *
Jerry Hoemann9a46fc42018-02-25 20:22:19 -07008 * (c) Copyright 2018 Hewlett Packard Enterprise Development LP
Mingarelli, Thomasca22e792015-12-14 20:22:09 +00009 * Thomas Mingarelli <thomas.mingarelli@hpe.com>
Thomas Mingarelli7f4da472007-12-04 17:41:54 +000010 */
11
Joe Perches27c766a2012-02-15 15:06:19 -080012#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
Thomas Mingarelli7f4da472007-12-04 17:41:54 +000014#include <linux/device.h>
Thomas Mingarelli7f4da472007-12-04 17:41:54 +000015#include <linux/io.h>
Thomas Mingarelli7f4da472007-12-04 17:41:54 +000016#include <linux/kernel.h>
Thomas Mingarelli7f4da472007-12-04 17:41:54 +000017#include <linux/module.h>
Thomas Mingarelli7f4da472007-12-04 17:41:54 +000018#include <linux/moduleparam.h>
Thomas Mingarelli7f4da472007-12-04 17:41:54 +000019#include <linux/pci.h>
20#include <linux/pci_ids.h>
Thomas Mingarelli7f4da472007-12-04 17:41:54 +000021#include <linux/types.h>
Thomas Mingarelli7f4da472007-12-04 17:41:54 +000022#include <linux/watchdog.h>
Ingo Molnard48b0e12011-10-06 14:20:27 +020023#include <asm/nmi.h>
Jerry Hoemannacc195b2020-11-22 19:08:39 -070024#include <linux/crash_dump.h>
Thomas Mingarelli7f4da472007-12-04 17:41:54 +000025
Jerry Hoemann5674b742020-11-22 19:08:40 -070026#define HPWDT_VERSION "2.0.4"
dann fraziere802e322010-06-02 16:23:39 -060027#define SECS_TO_TICKS(secs) ((secs) * 1000 / 128)
dann frazier6f681c22010-06-02 16:23:40 -060028#define TICKS_TO_SECS(ticks) ((ticks) * 128 / 1000)
Jerry Hoemannbe3d7f72019-05-17 14:59:41 -060029#define HPWDT_MAX_TICKS 65535
30#define HPWDT_MAX_TIMER TICKS_TO_SECS(HPWDT_MAX_TICKS)
dann frazier923410d2010-07-27 17:50:54 -060031#define DEFAULT_MARGIN 30
Jerry Hoemann0458f402018-02-25 20:22:25 -070032#define PRETIMEOUT_SEC 9
dann frazier923410d2010-07-27 17:50:54 -060033
Jerry Hoemanna6c24732018-02-25 20:22:23 -070034static bool ilo5;
dann frazier923410d2010-07-27 17:50:54 -060035static unsigned int soft_margin = DEFAULT_MARGIN; /* in seconds */
Wim Van Sebroeck86a1e182012-03-05 16:51:11 +010036static bool nowayout = WATCHDOG_NOWAYOUT;
Jerry Hoemann0458f402018-02-25 20:22:25 -070037static bool pretimeout = IS_ENABLED(CONFIG_HPWDT_NMI_DECODING);
Jerry Hoemannbe3d7f72019-05-17 14:59:41 -060038static int kdumptimeout = -1;
dann frazier923410d2010-07-27 17:50:54 -060039
40static void __iomem *pci_mem_addr; /* the PCI-memory address */
Jerry Hoemann838534e2017-10-23 16:46:17 -060041static unsigned long __iomem *hpwdt_nmistat;
dann frazier923410d2010-07-27 17:50:54 -060042static unsigned long __iomem *hpwdt_timer_reg;
43static unsigned long __iomem *hpwdt_timer_con;
44
Jingoo Hanbc17f9d2013-12-03 08:30:22 +090045static const struct pci_device_id hpwdt_devices[] = {
dann frazier36e3ff42010-07-27 17:50:57 -060046 { PCI_DEVICE(PCI_VENDOR_ID_COMPAQ, 0xB203) }, /* iLO2 */
47 { PCI_DEVICE(PCI_VENDOR_ID_HP, 0x3306) }, /* iLO3 */
Jerry Hoemann742b80c2021-05-12 22:03:32 -060048 { PCI_DEVICE(PCI_VENDOR_ID_HP_3PAR, 0x0389) }, /* PCtrl */
dann frazier923410d2010-07-27 17:50:54 -060049 {0}, /* terminate list */
50};
51MODULE_DEVICE_TABLE(pci, hpwdt_devices);
52
Jerry Hoemann94d6b802018-12-05 17:42:21 -070053static const struct pci_device_id hpwdt_blacklist[] = {
54 { PCI_DEVICE_SUB(PCI_VENDOR_ID_HP, 0x3306, PCI_VENDOR_ID_HP, 0x1979) }, /* auxilary iLO */
Jerry Hoemannde2cb0c2018-12-05 17:42:22 -070055 { PCI_DEVICE_SUB(PCI_VENDOR_ID_HP, 0x3306, PCI_VENDOR_ID_HP_3PAR, 0x0289) }, /* CL */
Jerry Hoemann94d6b802018-12-05 17:42:21 -070056 {0}, /* terminate list */
57};
Thomas Mingarelli7f4da472007-12-04 17:41:54 +000058
Jerry Hoemannbe3d7f72019-05-17 14:59:41 -060059static struct watchdog_device hpwdt_dev;
Thomas Mingarelli7f4da472007-12-04 17:41:54 +000060/*
Thomas Mingarelli7f4da472007-12-04 17:41:54 +000061 * Watchdog operations
62 */
Jerry Hoemannbb721d62019-05-17 14:59:40 -060063static int hpwdt_hw_is_running(void)
64{
65 return ioread8(hpwdt_timer_con) & 0x01;
66}
67
Jerry Hoemannd0a40272018-02-25 20:22:22 -070068static int hpwdt_start(struct watchdog_device *wdd)
Thomas Mingarelli7f4da472007-12-04 17:41:54 +000069{
Jerry Hoemann0458f402018-02-25 20:22:25 -070070 int control = 0x81 | (pretimeout ? 0x4 : 0);
Jerry Hoemannc22d8e32019-05-17 14:59:39 -060071 int reload = SECS_TO_TICKS(min(wdd->timeout, wdd->max_hw_heartbeat_ms/1000));
Jerry Hoemannd0a40272018-02-25 20:22:22 -070072
Jerry Hoemannc22d8e32019-05-17 14:59:39 -060073 dev_dbg(wdd->parent, "start watchdog 0x%08x:0x%08x:0x%02x\n", wdd->timeout, reload, control);
Thomas Mingarelli7f4da472007-12-04 17:41:54 +000074 iowrite16(reload, hpwdt_timer_reg);
Jerry Hoemann0458f402018-02-25 20:22:25 -070075 iowrite8(control, hpwdt_timer_con);
Jerry Hoemannd0a40272018-02-25 20:22:22 -070076
77 return 0;
Thomas Mingarelli7f4da472007-12-04 17:41:54 +000078}
79
80static void hpwdt_stop(void)
81{
82 unsigned long data;
83
Jerry Hoemannccfd6922018-02-25 20:22:26 -070084 pr_debug("stop watchdog\n");
85
Mingarelli, Thomasd08c9a32012-04-03 05:37:01 +000086 data = ioread8(hpwdt_timer_con);
Thomas Mingarelli7f4da472007-12-04 17:41:54 +000087 data &= 0xFE;
Mingarelli, Thomasd08c9a32012-04-03 05:37:01 +000088 iowrite8(data, hpwdt_timer_con);
Thomas Mingarelli7f4da472007-12-04 17:41:54 +000089}
90
Jerry Hoemannd0a40272018-02-25 20:22:22 -070091static int hpwdt_stop_core(struct watchdog_device *wdd)
Thomas Mingarelli7f4da472007-12-04 17:41:54 +000092{
Jerry Hoemannd0a40272018-02-25 20:22:22 -070093 hpwdt_stop();
Thomas Mingarelli7f4da472007-12-04 17:41:54 +000094
95 return 0;
96}
97
Jerry Hoemannbe3d7f72019-05-17 14:59:41 -060098static void hpwdt_ping_ticks(int val)
99{
100 val = min(val, HPWDT_MAX_TICKS);
101 iowrite16(val, hpwdt_timer_reg);
102}
103
Jerry Hoemannd0a40272018-02-25 20:22:22 -0700104static int hpwdt_ping(struct watchdog_device *wdd)
105{
Jerry Hoemannc22d8e32019-05-17 14:59:39 -0600106 int reload = SECS_TO_TICKS(min(wdd->timeout, wdd->max_hw_heartbeat_ms/1000));
Jerry Hoemann0458f402018-02-25 20:22:25 -0700107
Jerry Hoemannc22d8e32019-05-17 14:59:39 -0600108 dev_dbg(wdd->parent, "ping watchdog 0x%08x:0x%08x\n", wdd->timeout, reload);
Jerry Hoemannbe3d7f72019-05-17 14:59:41 -0600109 hpwdt_ping_ticks(reload);
Jerry Hoemann0458f402018-02-25 20:22:25 -0700110
Jerry Hoemannd0a40272018-02-25 20:22:22 -0700111 return 0;
112}
113
114static unsigned int hpwdt_gettimeleft(struct watchdog_device *wdd)
dann frazieraae67f32010-06-02 16:23:41 -0600115{
116 return TICKS_TO_SECS(ioread16(hpwdt_timer_reg));
117}
118
Jerry Hoemannd0a40272018-02-25 20:22:22 -0700119static int hpwdt_settimeout(struct watchdog_device *wdd, unsigned int val)
120{
Jerry Hoemannccfd6922018-02-25 20:22:26 -0700121 dev_dbg(wdd->parent, "set_timeout = %d\n", val);
122
Jerry Hoemannd0a40272018-02-25 20:22:22 -0700123 wdd->timeout = val;
Jerry Hoemann0458f402018-02-25 20:22:25 -0700124 if (val <= wdd->pretimeout) {
Jerry Hoemannccfd6922018-02-25 20:22:26 -0700125 dev_dbg(wdd->parent, "pretimeout < timeout. Setting to zero\n");
Jerry Hoemann0458f402018-02-25 20:22:25 -0700126 wdd->pretimeout = 0;
Jiapeng Zhong17f0d1b2021-01-20 15:48:10 +0800127 pretimeout = false;
Jerry Hoemann0458f402018-02-25 20:22:25 -0700128 if (watchdog_active(wdd))
129 hpwdt_start(wdd);
130 }
Jerry Hoemannd0a40272018-02-25 20:22:22 -0700131 hpwdt_ping(wdd);
132
133 return 0;
134}
135
Arnd Bergmannaeebc6b2017-12-06 22:02:37 +0100136#ifdef CONFIG_HPWDT_NMI_DECODING
Jerry Hoemann0458f402018-02-25 20:22:25 -0700137static int hpwdt_set_pretimeout(struct watchdog_device *wdd, unsigned int req)
138{
139 unsigned int val = 0;
140
Jerry Hoemannccfd6922018-02-25 20:22:26 -0700141 dev_dbg(wdd->parent, "set_pretimeout = %d\n", req);
Jerry Hoemann0458f402018-02-25 20:22:25 -0700142 if (req) {
143 val = PRETIMEOUT_SEC;
144 if (val >= wdd->timeout)
145 return -EINVAL;
146 }
147
Jerry Hoemannccfd6922018-02-25 20:22:26 -0700148 if (val != req)
149 dev_dbg(wdd->parent, "Rounding pretimeout to: %d\n", val);
150
Jerry Hoemann0458f402018-02-25 20:22:25 -0700151 wdd->pretimeout = val;
152 pretimeout = !!val;
153
154 if (watchdog_active(wdd))
155 hpwdt_start(wdd);
156
157 return 0;
158}
159
Jerry Hoemann838534e2017-10-23 16:46:17 -0600160static int hpwdt_my_nmi(void)
161{
162 return ioread8(hpwdt_nmistat) & 0x6;
163}
164
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000165/*
Thomas Mingarelliab4ba3c2008-07-15 19:40:41 +0000166 * NMI Handler
167 */
Don Zickus9c48f1c2011-09-30 15:06:21 -0400168static int hpwdt_pretimeout(unsigned int ulReason, struct pt_regs *regs)
Thomas Mingarelliab4ba3c2008-07-15 19:40:41 +0000169{
Jerry Hoemanna0422292018-02-25 20:22:21 -0700170 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 Hoemann62290a52018-05-03 15:00:55 -0600179 if (ilo5 && ulReason == NMI_UNKNOWN && !mynmi)
Jerry Hoemann838534e2017-10-23 16:46:17 -0600180 return NMI_DONE;
181
Jerry Hoemann093d4382018-08-08 13:13:24 -0600182 if (ilo5 && !pretimeout && !mynmi)
Jerry Hoemann0458f402018-02-25 20:22:25 -0700183 return NMI_DONE;
184
Jerry Hoemannbe3d7f72019-05-17 14:59:41 -0600185 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 Chumbalkardbc018e2011-08-09 22:27:26 +0000193
Jerry Hoemanna0422292018-02-25 20:22:21 -0700194 hex_byte_pack(panic_msg, mynmi);
195 nmi_panic(regs, panic_msg);
Thomas Mingarelli5efc7a62011-07-26 14:05:53 +0100196
Hidehiro Kawaiabc514c2016-03-22 14:27:24 -0700197 return NMI_HANDLED;
Thomas Mingarelliab4ba3c2008-07-15 19:40:41 +0000198}
dann frazier86ded1f2010-07-27 17:51:02 -0600199#endif /* CONFIG_HPWDT_NMI_DECODING */
Thomas Mingarelliab4ba3c2008-07-15 19:40:41 +0000200
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000201
Wim Van Sebroeck42747d72009-12-26 18:55:22 +0000202static const struct watchdog_info ident = {
Jerry Hoemann0458f402018-02-25 20:22:25 -0700203 .options = WDIOF_PRETIMEOUT |
204 WDIOF_SETTIMEOUT |
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000205 WDIOF_KEEPALIVEPING |
206 WDIOF_MAGICCLOSE,
Mingarelli, Thomasca22e792015-12-14 20:22:09 +0000207 .identity = "HPE iLO2+ HW Watchdog Timer",
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000208};
209
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000210/*
211 * Kernel interfaces
212 */
Jerry Hoemannd0a40272018-02-25 20:22:22 -0700213
214static 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 Hoemann0458f402018-02-25 20:22:25 -0700221#ifdef CONFIG_HPWDT_NMI_DECODING
222 .set_pretimeout = hpwdt_set_pretimeout,
223#endif
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000224};
225
Jerry Hoemannd0a40272018-02-25 20:22:22 -0700226static struct watchdog_device hpwdt_dev = {
227 .info = &ident,
228 .ops = &hpwdt_ops,
229 .min_timeout = 1,
Jerry Hoemannd0a40272018-02-25 20:22:22 -0700230 .timeout = DEFAULT_MARGIN,
Jerry Hoemann0458f402018-02-25 20:22:25 -0700231 .pretimeout = PRETIMEOUT_SEC,
Jerry Hoemannc22d8e32019-05-17 14:59:39 -0600232 .max_hw_heartbeat_ms = HPWDT_MAX_TIMER * 1000,
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000233};
234
Jerry Hoemannd0a40272018-02-25 20:22:22 -0700235
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000236/*
237 * Init & Exit
238 */
239
Bill Pemberton2d991a12012-11-19 13:21:41 -0500240static int hpwdt_init_nmi_decoding(struct pci_dev *dev)
dann frazier2ec7ed62010-07-28 12:38:43 -0600241{
Jerry Hoemann2b3d89b2018-02-25 20:22:20 -0700242#ifdef CONFIG_HPWDT_NMI_DECODING
dann frazier2ec7ed62010-07-28 12:38:43 -0600243 int retval;
dann frazier2ec7ed62010-07-28 12:38:43 -0600244 /*
Don Zickus09ee1012012-03-29 16:11:15 -0400245 * Only one function can register for NMI_UNKNOWN
dann frazier2ec7ed62010-07-28 12:38:43 -0600246 */
Don Zickus09ee1012012-03-29 16:11:15 -0400247 retval = register_nmi_handler(NMI_UNKNOWN, hpwdt_pretimeout, 0, "hpwdt");
Don Zickus553222f2012-03-29 16:11:16 -0400248 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 frazier2ec7ed62010-07-28 12:38:43 -0600256
257 dev_info(&dev->dev,
Jerry Hoemann703fc3d2018-02-25 20:22:24 -0700258 "HPE Watchdog Timer Driver: NMI decoding initialized\n");
259
dann frazier2ec7ed62010-07-28 12:38:43 -0600260 return 0;
Don Zickus553222f2012-03-29 16:11:16 -0400261
262error2:
263 unregister_nmi_handler(NMI_SERR, "hpwdt");
264error1:
265 unregister_nmi_handler(NMI_UNKNOWN, "hpwdt");
266error:
267 dev_warn(&dev->dev,
268 "Unable to register a die notifier (err=%d).\n",
269 retval);
Don Zickus553222f2012-03-29 16:11:16 -0400270 return retval;
Jerry Hoemann2b3d89b2018-02-25 20:22:20 -0700271#endif /* CONFIG_HPWDT_NMI_DECODING */
dann frazier86ded1f2010-07-27 17:51:02 -0600272 return 0;
273}
274
Axel Linb77b7082011-03-02 11:49:44 +0800275static void hpwdt_exit_nmi_decoding(void)
dann frazier86ded1f2010-07-27 17:51:02 -0600276{
Jerry Hoemann2b3d89b2018-02-25 20:22:20 -0700277#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 frazier86ded1f2010-07-27 17:51:02 -0600282}
Thomas Mingarelli47bece82009-06-04 19:50:45 +0000283
Bill Pemberton2d991a12012-11-19 13:21:41 -0500284static int hpwdt_init_one(struct pci_dev *dev,
Thomas Mingarelliab4ba3c2008-07-15 19:40:41 +0000285 const struct pci_device_id *ent)
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000286{
287 int retval;
288
289 /*
dann frazier36e3ff42010-07-27 17:50:57 -0600290 * First let's find out if we are on an iLO2+ server. We will
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000291 * not run on a legacy ASM box.
Thomas Mingarelliab4ba3c2008-07-15 19:40:41 +0000292 * So we only support the G5 ProLiant servers and higher.
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000293 */
Brian Boylstonfc113d52016-09-26 13:57:14 -0500294 if (dev->subsystem_vendor != PCI_VENDOR_ID_HP &&
295 dev->subsystem_vendor != PCI_VENDOR_ID_HP_3PAR) {
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000296 dev_warn(&dev->dev,
dann frazier36e3ff42010-07-27 17:50:57 -0600297 "This server does not have an iLO2+ ASIC.\n");
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000298 return -ENODEV;
299 }
300
Jerry Hoemann94d6b802018-12-05 17:42:21 -0700301 if (pci_match_id(hpwdt_blacklist, dev)) {
302 dev_dbg(&dev->dev, "Not supported on this device\n");
Mingarelli, Thomas0821f202013-08-09 16:31:09 +0000303 return -ENODEV;
Jerry Hoemann94d6b802018-12-05 17:42:21 -0700304 }
Mingarelli, Thomas0821f202013-08-09 16:31:09 +0000305
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000306 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 frazier36e3ff42010-07-27 17:50:57 -0600316 "Unable to detect the iLO2+ server memory.\n");
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000317 retval = -ENOMEM;
318 goto error_pci_iomap;
319 }
Jerry Hoemann838534e2017-10-23 16:46:17 -0600320 hpwdt_nmistat = pci_mem_addr + 0x6e;
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000321 hpwdt_timer_reg = pci_mem_addr + 0x70;
322 hpwdt_timer_con = pci_mem_addr + 0x72;
323
Jerry Hoemannbb721d62019-05-17 14:59:40 -0600324 /* 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 Kani308b1352012-08-27 12:52:24 -0600329
dann frazier2ec7ed62010-07-28 12:38:43 -0600330 /* Initialize NMI Decoding functionality */
331 retval = hpwdt_init_nmi_decoding(dev);
332 if (retval != 0)
333 goto error_init_nmi_decoding;
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000334
Jerry Hoemann48b32192019-05-17 14:59:38 -0600335 watchdog_stop_on_unregister(&hpwdt_dev);
Jerry Hoemannd0a40272018-02-25 20:22:22 -0700336 watchdog_set_nowayout(&hpwdt_dev, nowayout);
Wolfram Sang87dfe212019-04-19 20:15:51 +0200337 watchdog_init_timeout(&hpwdt_dev, soft_margin, NULL);
Jerry Hoemannd0a40272018-02-25 20:22:22 -0700338
Jerry Hoemannacc195b2020-11-22 19:08:39 -0700339 if (is_kdump_kernel()) {
Jiapeng Zhong17f0d1b2021-01-20 15:48:10 +0800340 pretimeout = false;
Jerry Hoemannacc195b2020-11-22 19:08:39 -0700341 kdumptimeout = 0;
342 }
343
Jerry Hoemann10d790d12018-09-21 14:50:39 -0600344 if (pretimeout && hpwdt_dev.timeout <= PRETIMEOUT_SEC) {
345 dev_warn(&dev->dev, "timeout <= pretimeout. Setting pretimeout to zero\n");
Jiapeng Zhong17f0d1b2021-01-20 15:48:10 +0800346 pretimeout = false;
Jerry Hoemann10d790d12018-09-21 14:50:39 -0600347 }
Jerry Hoemann4d9186d2018-08-08 13:13:23 -0600348 hpwdt_dev.pretimeout = pretimeout ? PRETIMEOUT_SEC : 0;
Jerry Hoemannbe3d7f72019-05-17 14:59:41 -0600349 kdumptimeout = min(kdumptimeout, HPWDT_MAX_TIMER);
Jerry Hoemann4d9186d2018-08-08 13:13:23 -0600350
Jerry Hoemannd0a40272018-02-25 20:22:22 -0700351 hpwdt_dev.parent = &dev->dev;
352 retval = watchdog_register_device(&hpwdt_dev);
Wolfram Sangf51540b2019-05-18 23:27:28 +0200353 if (retval < 0)
Jerry Hoemannd0a40272018-02-25 20:22:22 -0700354 goto error_wd_register;
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000355
Jerry Hoemann92301462018-08-08 13:13:25 -0600356 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 Hoemannbe3d7f72019-05-17 14:59:41 -0600362 dev_info(&dev->dev, "kdumptimeout: %d.\n", kdumptimeout);
Jerry Hoemannd0a40272018-02-25 20:22:22 -0700363
Jerry Hoemanna6c24732018-02-25 20:22:23 -0700364 if (dev->subsystem_vendor == PCI_VENDOR_ID_HP_3PAR)
365 ilo5 = true;
366
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000367 return 0;
368
Jerry Hoemannd0a40272018-02-25 20:22:22 -0700369error_wd_register:
dann frazier2ec7ed62010-07-28 12:38:43 -0600370 hpwdt_exit_nmi_decoding();
371error_init_nmi_decoding:
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000372 pci_iounmap(dev, pci_mem_addr);
373error_pci_iomap:
374 pci_disable_device(dev);
375 return retval;
376}
377
Bill Pemberton4b12b892012-11-19 13:26:24 -0500378static void hpwdt_exit(struct pci_dev *dev)
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000379{
Jerry Hoemannd0a40272018-02-25 20:22:22 -0700380 watchdog_unregister_device(&hpwdt_dev);
dann frazier2ec7ed62010-07-28 12:38:43 -0600381 hpwdt_exit_nmi_decoding();
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000382 pci_iounmap(dev, pci_mem_addr);
383 pci_disable_device(dev);
384}
385
386static struct pci_driver hpwdt_driver = {
387 .name = "hpwdt",
388 .id_table = hpwdt_devices,
389 .probe = hpwdt_init_one,
Bill Pemberton82268712012-11-19 13:21:12 -0500390 .remove = hpwdt_exit,
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000391};
392
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000393MODULE_AUTHOR("Tom Mingarelli");
Jerry Hoemann9a46fc42018-02-25 20:22:19 -0700394MODULE_DESCRIPTION("hpe watchdog driver");
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000395MODULE_LICENSE("GPL");
Thomas Mingarellid8100c32009-03-03 00:17:16 +0000396MODULE_VERSION(HPWDT_VERSION);
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000397
398module_param(soft_margin, int, 0);
399MODULE_PARM_DESC(soft_margin, "Watchdog timeout in seconds");
400
Jerry Hoemann397a35d2018-08-08 13:13:26 -0600401module_param_named(timeout, soft_margin, int, 0);
402MODULE_PARM_DESC(timeout, "Alias of soft_margin");
403
Wim Van Sebroeck86a1e182012-03-05 16:51:11 +0100404module_param(nowayout, bool, 0);
Thomas Mingarelli7f4da472007-12-04 17:41:54 +0000405MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
406 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
407
Jerry Hoemannbe3d7f72019-05-17 14:59:41 -0600408module_param(kdumptimeout, int, 0444);
409MODULE_PARM_DESC(kdumptimeout, "Timeout applied for crash kernel transition in seconds");
410
Jerry Hoemann0458f402018-02-25 20:22:25 -0700411#ifdef CONFIG_HPWDT_NMI_DECODING
412module_param(pretimeout, bool, 0);
413MODULE_PARM_DESC(pretimeout, "Watchdog pretimeout enabled");
414#endif
415
Wim Van Sebroeck5ce9c372012-05-04 14:43:25 +0200416module_pci_driver(hpwdt_driver);