blob: 410800f8432a2dfc9b7f3deda2c51bb015246451 [file] [log] [blame]
David Daney4c076fb2010-07-24 10:16:05 -07001/*
2 * Octeon Watchdog driver
3 *
Steven J. Hill381cec02017-08-29 10:40:36 -05004 * Copyright (C) 2007-2017 Cavium, Inc.
David Daney4c076fb2010-07-24 10:16:05 -07005 *
Aaro Koskinen3d588c92015-03-28 20:05:38 +02006 * Converted to use WATCHDOG_CORE by Aaro Koskinen <aaro.koskinen@iki.fi>.
7 *
David Daney4c076fb2010-07-24 10:16:05 -07008 * Some parts derived from wdt.c
9 *
10 * (c) Copyright 1996-1997 Alan Cox <alan@lxorguk.ukuu.org.uk>,
11 * All Rights Reserved.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version
16 * 2 of the License, or (at your option) any later version.
17 *
18 * Neither Alan Cox nor CymruNet Ltd. admit liability nor provide
19 * warranty for any of this software. This material is provided
20 * "AS-IS" and at no charge.
21 *
22 * (c) Copyright 1995 Alan Cox <alan@lxorguk.ukuu.org.uk>
23 *
24 * This file is subject to the terms and conditions of the GNU General Public
25 * License. See the file "COPYING" in the main directory of this archive
26 * for more details.
27 *
28 *
29 * The OCTEON watchdog has a maximum timeout of 2^32 * io_clock.
30 * For most systems this is less than 10 seconds, so to allow for
31 * software to request longer watchdog heartbeats, we maintain software
32 * counters to count multiples of the base rate. If the system locks
33 * up in such a manner that we can not run the software counters, the
34 * only result is a watchdog reset sooner than was requested. But
35 * that is OK, because in this case userspace would likely not be able
36 * to do anything anyhow.
37 *
38 * The hardware watchdog interval we call the period. The OCTEON
39 * watchdog goes through several stages, after the first period an
40 * irq is asserted, then if it is not reset, after the next period NMI
41 * is asserted, then after an additional period a chip wide soft reset.
42 * So for the software counters, we reset watchdog after each period
43 * and decrement the counter. But for the last two periods we need to
44 * let the watchdog progress to the NMI stage so we disable the irq
45 * and let it proceed. Once in the NMI, we print the register state
46 * to the serial port and then wait for the reset.
47 *
48 * A watchdog is maintained for each CPU in the system, that way if
49 * one CPU suffers a lockup, we also get a register dump and reset.
50 * The userspace ping resets the watchdog on all CPUs.
51 *
52 * Before userspace opens the watchdog device, we still run the
53 * watchdogs to catch any lockups that may be kernel related.
54 *
55 */
56
Joe Perches27c766a2012-02-15 15:06:19 -080057#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
58
David Daney4c076fb2010-07-24 10:16:05 -070059#include <linux/interrupt.h>
60#include <linux/watchdog.h>
61#include <linux/cpumask.h>
David Daney4c076fb2010-07-24 10:16:05 -070062#include <linux/module.h>
David Daney4c076fb2010-07-24 10:16:05 -070063#include <linux/delay.h>
64#include <linux/cpu.h>
David Howellsca4d3e672010-10-07 14:08:54 +010065#include <linux/irq.h>
David Daney4c076fb2010-07-24 10:16:05 -070066
67#include <asm/mipsregs.h>
68#include <asm/uasm.h>
69
70#include <asm/octeon/octeon.h>
Steven J. Hill49d148b2017-08-29 10:40:32 -050071#include <asm/octeon/cvmx-boot-vector.h>
David Daney0cd4e7a2017-08-29 10:40:37 -050072#include <asm/octeon/cvmx-ciu2-defs.h>
73
74static int divisor;
David Daney4c076fb2010-07-24 10:16:05 -070075
76/* The count needed to achieve timeout_sec. */
77static unsigned int timeout_cnt;
78
79/* The maximum period supported. */
80static unsigned int max_timeout_sec;
81
82/* The current period. */
83static unsigned int timeout_sec;
84
85/* Set to non-zero when userspace countdown mode active */
Steven J. Hill381cec02017-08-29 10:40:36 -050086static bool do_countdown;
David Daney4c076fb2010-07-24 10:16:05 -070087static unsigned int countdown_reset;
88static unsigned int per_cpu_countdown[NR_CPUS];
89
90static cpumask_t irq_enabled_cpus;
91
92#define WD_TIMO 60 /* Default heartbeat = 60 seconds */
93
94static int heartbeat = WD_TIMO;
Steven J. Hill381cec02017-08-29 10:40:36 -050095module_param(heartbeat, int, 0444);
David Daney4c076fb2010-07-24 10:16:05 -070096MODULE_PARM_DESC(heartbeat,
97 "Watchdog heartbeat in seconds. (0 < heartbeat, default="
98 __MODULE_STRING(WD_TIMO) ")");
99
Wim Van Sebroeck86a1e182012-03-05 16:51:11 +0100100static bool nowayout = WATCHDOG_NOWAYOUT;
Steven J. Hill381cec02017-08-29 10:40:36 -0500101module_param(nowayout, bool, 0444);
David Daney4c076fb2010-07-24 10:16:05 -0700102MODULE_PARM_DESC(nowayout,
103 "Watchdog cannot be stopped once started (default="
104 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
105
Steven J. Hill381cec02017-08-29 10:40:36 -0500106static int disable;
107module_param(disable, int, 0444);
108MODULE_PARM_DESC(disable,
109 "Disable the watchdog entirely (default=0)");
110
Steven J. Hill49d148b2017-08-29 10:40:32 -0500111static struct cvmx_boot_vector_element *octeon_wdt_bootvector;
David Daney4c076fb2010-07-24 10:16:05 -0700112
113void octeon_wdt_nmi_stage2(void);
114
David Daney4c076fb2010-07-24 10:16:05 -0700115static int cpu2core(int cpu)
116{
117#ifdef CONFIG_SMP
118 return cpu_logical_map(cpu);
119#else
120 return cvmx_get_core_num();
121#endif
122}
123
124static int core2cpu(int coreid)
125{
126#ifdef CONFIG_SMP
127 return cpu_number_map(coreid);
128#else
129 return 0;
130#endif
131}
132
133/**
134 * Poke the watchdog when an interrupt is received
135 *
136 * @cpl:
137 * @dev_id:
138 *
139 * Returns
140 */
141static irqreturn_t octeon_wdt_poke_irq(int cpl, void *dev_id)
142{
143 unsigned int core = cvmx_get_core_num();
144 int cpu = core2cpu(core);
145
Steven J. Hill381cec02017-08-29 10:40:36 -0500146 if (do_countdown) {
David Daney4c076fb2010-07-24 10:16:05 -0700147 if (per_cpu_countdown[cpu] > 0) {
148 /* We're alive, poke the watchdog */
149 cvmx_write_csr(CVMX_CIU_PP_POKEX(core), 1);
150 per_cpu_countdown[cpu]--;
151 } else {
152 /* Bad news, you are about to reboot. */
153 disable_irq_nosync(cpl);
154 cpumask_clear_cpu(cpu, &irq_enabled_cpus);
155 }
156 } else {
157 /* Not open, just ping away... */
158 cvmx_write_csr(CVMX_CIU_PP_POKEX(core), 1);
159 }
160 return IRQ_HANDLED;
161}
162
163/* From setup.c */
164extern int prom_putchar(char c);
165
166/**
167 * Write a string to the uart
168 *
169 * @str: String to write
170 */
171static void octeon_wdt_write_string(const char *str)
172{
173 /* Just loop writing one byte at a time */
174 while (*str)
175 prom_putchar(*str++);
176}
177
178/**
179 * Write a hex number out of the uart
180 *
181 * @value: Number to display
182 * @digits: Number of digits to print (1 to 16)
183 */
184static void octeon_wdt_write_hex(u64 value, int digits)
185{
186 int d;
187 int v;
Aaro Koskinen8692cf02015-03-28 20:05:39 +0200188
David Daney4c076fb2010-07-24 10:16:05 -0700189 for (d = 0; d < digits; d++) {
190 v = (value >> ((digits - d - 1) * 4)) & 0xf;
191 if (v >= 10)
192 prom_putchar('a' + v - 10);
193 else
194 prom_putchar('0' + v);
195 }
196}
197
Aaro Koskinen3a30c072015-03-28 20:05:40 +0200198static const char reg_name[][3] = {
David Daney4c076fb2010-07-24 10:16:05 -0700199 "$0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
200 "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3",
201 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
202 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
203};
204
205/**
206 * NMI stage 3 handler. NMIs are handled in the following manner:
207 * 1) The first NMI handler enables CVMSEG and transfers from
208 * the bootbus region into normal memory. It is careful to not
209 * destroy any registers.
210 * 2) The second stage handler uses CVMSEG to save the registers
211 * and create a stack for C code. It then calls the third level
212 * handler with one argument, a pointer to the register values.
213 * 3) The third, and final, level handler is the following C
214 * function that prints out some useful infomration.
215 *
216 * @reg: Pointer to register state before the NMI
217 */
218void octeon_wdt_nmi_stage3(u64 reg[32])
219{
220 u64 i;
221
222 unsigned int coreid = cvmx_get_core_num();
223 /*
224 * Save status and cause early to get them before any changes
225 * might happen.
226 */
227 u64 cp0_cause = read_c0_cause();
228 u64 cp0_status = read_c0_status();
229 u64 cp0_error_epc = read_c0_errorepc();
230 u64 cp0_epc = read_c0_epc();
231
232 /* Delay so output from all cores output is not jumbled together. */
David Daney0cd4e7a2017-08-29 10:40:37 -0500233 udelay(85000 * coreid);
David Daney4c076fb2010-07-24 10:16:05 -0700234
235 octeon_wdt_write_string("\r\n*** NMI Watchdog interrupt on Core 0x");
David Daney0cd4e7a2017-08-29 10:40:37 -0500236 octeon_wdt_write_hex(coreid, 2);
David Daney4c076fb2010-07-24 10:16:05 -0700237 octeon_wdt_write_string(" ***\r\n");
238 for (i = 0; i < 32; i++) {
239 octeon_wdt_write_string("\t");
240 octeon_wdt_write_string(reg_name[i]);
241 octeon_wdt_write_string("\t0x");
242 octeon_wdt_write_hex(reg[i], 16);
243 if (i & 1)
244 octeon_wdt_write_string("\r\n");
245 }
246 octeon_wdt_write_string("\terr_epc\t0x");
247 octeon_wdt_write_hex(cp0_error_epc, 16);
248
249 octeon_wdt_write_string("\tepc\t0x");
250 octeon_wdt_write_hex(cp0_epc, 16);
251 octeon_wdt_write_string("\r\n");
252
253 octeon_wdt_write_string("\tstatus\t0x");
254 octeon_wdt_write_hex(cp0_status, 16);
255 octeon_wdt_write_string("\tcause\t0x");
256 octeon_wdt_write_hex(cp0_cause, 16);
257 octeon_wdt_write_string("\r\n");
258
David Daney0cd4e7a2017-08-29 10:40:37 -0500259 /* The CIU register is different for each Octeon model. */
260 if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
261 octeon_wdt_write_string("\tsrc_wd\t0x");
262 octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU2_SRC_PPX_IP2_WDOG(coreid)), 16);
263 octeon_wdt_write_string("\ten_wd\t0x");
264 octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU2_EN_PPX_IP2_WDOG(coreid)), 16);
265 octeon_wdt_write_string("\r\n");
266 octeon_wdt_write_string("\tsrc_rml\t0x");
267 octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU2_SRC_PPX_IP2_RML(coreid)), 16);
268 octeon_wdt_write_string("\ten_rml\t0x");
269 octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU2_EN_PPX_IP2_RML(coreid)), 16);
270 octeon_wdt_write_string("\r\n");
271 octeon_wdt_write_string("\tsum\t0x");
272 octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU2_SUM_PPX_IP2(coreid)), 16);
273 octeon_wdt_write_string("\r\n");
274 } else if (!octeon_has_feature(OCTEON_FEATURE_CIU3)) {
275 octeon_wdt_write_string("\tsum0\t0x");
276 octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU_INTX_SUM0(coreid * 2)), 16);
277 octeon_wdt_write_string("\ten0\t0x");
278 octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU_INTX_EN0(coreid * 2)), 16);
279 octeon_wdt_write_string("\r\n");
280 }
David Daney4c076fb2010-07-24 10:16:05 -0700281
282 octeon_wdt_write_string("*** Chip soft reset soon ***\r\n");
283}
284
Sebastian Andrzej Siewior948b9c62016-11-17 19:35:32 +0100285static int octeon_wdt_cpu_pre_down(unsigned int cpu)
David Daney4c076fb2010-07-24 10:16:05 -0700286{
287 unsigned int core;
288 unsigned int irq;
289 union cvmx_ciu_wdogx ciu_wdog;
290
291 core = cpu2core(cpu);
292
293 irq = OCTEON_IRQ_WDOG0 + core;
294
295 /* Poke the watchdog to clear out its state */
296 cvmx_write_csr(CVMX_CIU_PP_POKEX(core), 1);
297
298 /* Disable the hardware. */
299 ciu_wdog.u64 = 0;
300 cvmx_write_csr(CVMX_CIU_WDOGX(core), ciu_wdog.u64);
301
302 free_irq(irq, octeon_wdt_poke_irq);
Sebastian Andrzej Siewior948b9c62016-11-17 19:35:32 +0100303 return 0;
David Daney4c076fb2010-07-24 10:16:05 -0700304}
305
Sebastian Andrzej Siewior948b9c62016-11-17 19:35:32 +0100306static int octeon_wdt_cpu_online(unsigned int cpu)
David Daney4c076fb2010-07-24 10:16:05 -0700307{
308 unsigned int core;
309 unsigned int irq;
310 union cvmx_ciu_wdogx ciu_wdog;
311
312 core = cpu2core(cpu);
313
Steven J. Hill49d148b2017-08-29 10:40:32 -0500314 octeon_wdt_bootvector[core].target_ptr = (u64)octeon_wdt_nmi_stage2;
315
David Daney4c076fb2010-07-24 10:16:05 -0700316 /* Disable it before doing anything with the interrupts. */
317 ciu_wdog.u64 = 0;
318 cvmx_write_csr(CVMX_CIU_WDOGX(core), ciu_wdog.u64);
319
320 per_cpu_countdown[cpu] = countdown_reset;
321
322 irq = OCTEON_IRQ_WDOG0 + core;
323
324 if (request_irq(irq, octeon_wdt_poke_irq,
Venkat Subbiah47bfd052011-10-03 17:22:04 -0700325 IRQF_NO_THREAD, "octeon_wdt", octeon_wdt_poke_irq))
David Daney4c076fb2010-07-24 10:16:05 -0700326 panic("octeon_wdt: Couldn't obtain irq %d", irq);
327
328 cpumask_set_cpu(cpu, &irq_enabled_cpus);
329
330 /* Poke the watchdog to clear out its state */
331 cvmx_write_csr(CVMX_CIU_PP_POKEX(core), 1);
332
333 /* Finally enable the watchdog now that all handlers are installed */
334 ciu_wdog.u64 = 0;
335 ciu_wdog.s.len = timeout_cnt;
336 ciu_wdog.s.mode = 3; /* 3 = Interrupt + NMI + Soft-Reset */
337 cvmx_write_csr(CVMX_CIU_WDOGX(core), ciu_wdog.u64);
David Daney4c076fb2010-07-24 10:16:05 -0700338
Sebastian Andrzej Siewior948b9c62016-11-17 19:35:32 +0100339 return 0;
David Daney4c076fb2010-07-24 10:16:05 -0700340}
341
Aaro Koskinen3d588c92015-03-28 20:05:38 +0200342static int octeon_wdt_ping(struct watchdog_device __always_unused *wdog)
David Daney4c076fb2010-07-24 10:16:05 -0700343{
344 int cpu;
345 int coreid;
346
Steven J. Hill381cec02017-08-29 10:40:36 -0500347 if (disable)
348 return 0;
349
David Daney4c076fb2010-07-24 10:16:05 -0700350 for_each_online_cpu(cpu) {
351 coreid = cpu2core(cpu);
352 cvmx_write_csr(CVMX_CIU_PP_POKEX(coreid), 1);
353 per_cpu_countdown[cpu] = countdown_reset;
Steven J. Hill381cec02017-08-29 10:40:36 -0500354 if ((countdown_reset || !do_countdown) &&
David Daney4c076fb2010-07-24 10:16:05 -0700355 !cpumask_test_cpu(cpu, &irq_enabled_cpus)) {
356 /* We have to enable the irq */
357 int irq = OCTEON_IRQ_WDOG0 + coreid;
Aaro Koskinen8692cf02015-03-28 20:05:39 +0200358
David Daney4c076fb2010-07-24 10:16:05 -0700359 enable_irq(irq);
360 cpumask_set_cpu(cpu, &irq_enabled_cpus);
361 }
362 }
Aaro Koskinen3d588c92015-03-28 20:05:38 +0200363 return 0;
David Daney4c076fb2010-07-24 10:16:05 -0700364}
365
366static void octeon_wdt_calc_parameters(int t)
367{
368 unsigned int periods;
369
370 timeout_sec = max_timeout_sec;
371
372
373 /*
374 * Find the largest interrupt period, that can evenly divide
375 * the requested heartbeat time.
376 */
377 while ((t % timeout_sec) != 0)
378 timeout_sec--;
379
380 periods = t / timeout_sec;
381
382 /*
383 * The last two periods are after the irq is disabled, and
384 * then to the nmi, so we subtract them off.
385 */
386
387 countdown_reset = periods > 2 ? periods - 2 : 0;
388 heartbeat = t;
David Daney0cd4e7a2017-08-29 10:40:37 -0500389 timeout_cnt = ((octeon_get_io_clock_rate() / divisor) * timeout_sec) >> 8;
David Daney4c076fb2010-07-24 10:16:05 -0700390}
391
Aaro Koskinen3d588c92015-03-28 20:05:38 +0200392static int octeon_wdt_set_timeout(struct watchdog_device *wdog,
393 unsigned int t)
David Daney4c076fb2010-07-24 10:16:05 -0700394{
395 int cpu;
396 int coreid;
397 union cvmx_ciu_wdogx ciu_wdog;
398
399 if (t <= 0)
400 return -1;
401
402 octeon_wdt_calc_parameters(t);
403
Steven J. Hill381cec02017-08-29 10:40:36 -0500404 if (disable)
405 return 0;
406
David Daney4c076fb2010-07-24 10:16:05 -0700407 for_each_online_cpu(cpu) {
408 coreid = cpu2core(cpu);
409 cvmx_write_csr(CVMX_CIU_PP_POKEX(coreid), 1);
410 ciu_wdog.u64 = 0;
411 ciu_wdog.s.len = timeout_cnt;
412 ciu_wdog.s.mode = 3; /* 3 = Interrupt + NMI + Soft-Reset */
413 cvmx_write_csr(CVMX_CIU_WDOGX(coreid), ciu_wdog.u64);
414 cvmx_write_csr(CVMX_CIU_PP_POKEX(coreid), 1);
415 }
Aaro Koskinen3d588c92015-03-28 20:05:38 +0200416 octeon_wdt_ping(wdog); /* Get the irqs back on. */
David Daney4c076fb2010-07-24 10:16:05 -0700417 return 0;
418}
419
Aaro Koskinen3d588c92015-03-28 20:05:38 +0200420static int octeon_wdt_start(struct watchdog_device *wdog)
David Daney4c076fb2010-07-24 10:16:05 -0700421{
Aaro Koskinen3d588c92015-03-28 20:05:38 +0200422 octeon_wdt_ping(wdog);
Steven J. Hill381cec02017-08-29 10:40:36 -0500423 do_countdown = 1;
David Daney4c076fb2010-07-24 10:16:05 -0700424 return 0;
425}
426
Aaro Koskinen3d588c92015-03-28 20:05:38 +0200427static int octeon_wdt_stop(struct watchdog_device *wdog)
428{
Steven J. Hill381cec02017-08-29 10:40:36 -0500429 do_countdown = 0;
Aaro Koskinen3d588c92015-03-28 20:05:38 +0200430 octeon_wdt_ping(wdog);
431 return 0;
432}
David Daney4c076fb2010-07-24 10:16:05 -0700433
Aaro Koskinen3d588c92015-03-28 20:05:38 +0200434static const struct watchdog_info octeon_wdt_info = {
435 .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING,
436 .identity = "OCTEON",
437};
438
439static const struct watchdog_ops octeon_wdt_ops = {
440 .owner = THIS_MODULE,
441 .start = octeon_wdt_start,
442 .stop = octeon_wdt_stop,
443 .ping = octeon_wdt_ping,
444 .set_timeout = octeon_wdt_set_timeout,
445};
446
447static struct watchdog_device octeon_wdt = {
448 .info = &octeon_wdt_info,
449 .ops = &octeon_wdt_ops,
450};
David Daney4c076fb2010-07-24 10:16:05 -0700451
Sebastian Andrzej Siewior948b9c62016-11-17 19:35:32 +0100452static enum cpuhp_state octeon_wdt_online;
David Daney4c076fb2010-07-24 10:16:05 -0700453/**
454 * Module/ driver initialization.
455 *
456 * Returns Zero on success
457 */
458static int __init octeon_wdt_init(void)
459{
David Daney4c076fb2010-07-24 10:16:05 -0700460 int ret;
David Daney4c076fb2010-07-24 10:16:05 -0700461
Steven J. Hill49d148b2017-08-29 10:40:32 -0500462 octeon_wdt_bootvector = cvmx_boot_vector_get();
463 if (!octeon_wdt_bootvector) {
464 pr_err("Error: Cannot allocate boot vector.\n");
465 return -ENOMEM;
466 }
467
David Daney0cd4e7a2017-08-29 10:40:37 -0500468 if (OCTEON_IS_MODEL(OCTEON_CN68XX))
469 divisor = 0x200;
470 else
471 divisor = 0x100;
472
David Daney4c076fb2010-07-24 10:16:05 -0700473 /*
474 * Watchdog time expiration length = The 16 bits of LEN
475 * represent the most significant bits of a 24 bit decrementer
David Daney0cd4e7a2017-08-29 10:40:37 -0500476 * that decrements every divisor cycle.
David Daney4c076fb2010-07-24 10:16:05 -0700477 *
478 * Try for a timeout of 5 sec, if that fails a smaller number
479 * of even seconds,
480 */
481 max_timeout_sec = 6;
482 do {
483 max_timeout_sec--;
David Daney0cd4e7a2017-08-29 10:40:37 -0500484 timeout_cnt = ((octeon_get_io_clock_rate() / divisor) * max_timeout_sec) >> 8;
David Daney4c076fb2010-07-24 10:16:05 -0700485 } while (timeout_cnt > 65535);
486
487 BUG_ON(timeout_cnt == 0);
488
489 octeon_wdt_calc_parameters(heartbeat);
490
Joe Perches27c766a2012-02-15 15:06:19 -0800491 pr_info("Initial granularity %d Sec\n", timeout_sec);
David Daney4c076fb2010-07-24 10:16:05 -0700492
Aaro Koskinen3d588c92015-03-28 20:05:38 +0200493 octeon_wdt.timeout = timeout_sec;
494 octeon_wdt.max_timeout = UINT_MAX;
495
496 watchdog_set_nowayout(&octeon_wdt, nowayout);
497
498 ret = watchdog_register_device(&octeon_wdt);
David Daney4c076fb2010-07-24 10:16:05 -0700499 if (ret) {
Aaro Koskinen3d588c92015-03-28 20:05:38 +0200500 pr_err("watchdog_register_device() failed: %d\n", ret);
501 return ret;
David Daney4c076fb2010-07-24 10:16:05 -0700502 }
503
Steven J. Hill381cec02017-08-29 10:40:36 -0500504 if (disable) {
505 pr_notice("disabled\n");
506 return 0;
507 }
508
David Daney4c076fb2010-07-24 10:16:05 -0700509 cpumask_clear(&irq_enabled_cpus);
510
Sebastian Andrzej Siewior948b9c62016-11-17 19:35:32 +0100511 ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "watchdog/octeon:online",
512 octeon_wdt_cpu_online, octeon_wdt_cpu_pre_down);
513 if (ret < 0)
514 goto err;
515 octeon_wdt_online = ret;
Aaro Koskinen3d588c92015-03-28 20:05:38 +0200516 return 0;
Sebastian Andrzej Siewior948b9c62016-11-17 19:35:32 +0100517err:
518 cvmx_write_csr(CVMX_MIO_BOOT_LOC_CFGX(0), 0);
519 watchdog_unregister_device(&octeon_wdt);
520 return ret;
David Daney4c076fb2010-07-24 10:16:05 -0700521}
522
523/**
524 * Module / driver shutdown
525 */
526static void __exit octeon_wdt_cleanup(void)
527{
Aaro Koskinen3d588c92015-03-28 20:05:38 +0200528 watchdog_unregister_device(&octeon_wdt);
Steven J. Hill381cec02017-08-29 10:40:36 -0500529
530 if (disable)
531 return;
532
Sebastian Andrzej Siewior948b9c62016-11-17 19:35:32 +0100533 cpuhp_remove_state(octeon_wdt_online);
Srivatsa S. Bhat99c3bf32014-03-11 02:10:43 +0530534
David Daney4c076fb2010-07-24 10:16:05 -0700535 /*
536 * Disable the boot-bus memory, the code it points to is soon
537 * to go missing.
538 */
539 cvmx_write_csr(CVMX_MIO_BOOT_LOC_CFGX(0), 0);
540}
541
542MODULE_LICENSE("GPL");
Steven J. Hill381cec02017-08-29 10:40:36 -0500543MODULE_AUTHOR("Cavium Inc. <support@cavium.com>");
544MODULE_DESCRIPTION("Cavium Inc. OCTEON Watchdog driver.");
David Daney4c076fb2010-07-24 10:16:05 -0700545module_init(octeon_wdt_init);
546module_exit(octeon_wdt_cleanup);