Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
[linux-2.6-block.git] / drivers / watchdog / octeon-wdt-main.c
CommitLineData
d0173278 1// SPDX-License-Identifier: GPL-2.0+
4c076fb4
DD
2/*
3 * Octeon Watchdog driver
4 *
381cec02 5 * Copyright (C) 2007-2017 Cavium, Inc.
4c076fb4 6 *
3d588c93
AK
7 * Converted to use WATCHDOG_CORE by Aaro Koskinen <aaro.koskinen@iki.fi>.
8 *
4c076fb4
DD
9 * Some parts derived from wdt.c
10 *
11 * (c) Copyright 1996-1997 Alan Cox <alan@lxorguk.ukuu.org.uk>,
12 * All Rights Reserved.
13 *
4c076fb4
DD
14 * Neither Alan Cox nor CymruNet Ltd. admit liability nor provide
15 * warranty for any of this software. This material is provided
16 * "AS-IS" and at no charge.
17 *
18 * (c) Copyright 1995 Alan Cox <alan@lxorguk.ukuu.org.uk>
19 *
4c076fb4
DD
20 * The OCTEON watchdog has a maximum timeout of 2^32 * io_clock.
21 * For most systems this is less than 10 seconds, so to allow for
22 * software to request longer watchdog heartbeats, we maintain software
23 * counters to count multiples of the base rate. If the system locks
24 * up in such a manner that we can not run the software counters, the
25 * only result is a watchdog reset sooner than was requested. But
26 * that is OK, because in this case userspace would likely not be able
27 * to do anything anyhow.
28 *
29 * The hardware watchdog interval we call the period. The OCTEON
30 * watchdog goes through several stages, after the first period an
31 * irq is asserted, then if it is not reset, after the next period NMI
32 * is asserted, then after an additional period a chip wide soft reset.
33 * So for the software counters, we reset watchdog after each period
34 * and decrement the counter. But for the last two periods we need to
35 * let the watchdog progress to the NMI stage so we disable the irq
36 * and let it proceed. Once in the NMI, we print the register state
37 * to the serial port and then wait for the reset.
38 *
39 * A watchdog is maintained for each CPU in the system, that way if
40 * one CPU suffers a lockup, we also get a register dump and reset.
41 * The userspace ping resets the watchdog on all CPUs.
42 *
43 * Before userspace opens the watchdog device, we still run the
44 * watchdogs to catch any lockups that may be kernel related.
45 *
46 */
47
27c766aa
JP
48#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
49
4c076fb4
DD
50#include <linux/interrupt.h>
51#include <linux/watchdog.h>
52#include <linux/cpumask.h>
4c076fb4 53#include <linux/module.h>
4c076fb4
DD
54#include <linux/delay.h>
55#include <linux/cpu.h>
ca4d3e67 56#include <linux/irq.h>
bc9a454a 57#include <linux/irqdomain.h>
4c076fb4
DD
58
59#include <asm/mipsregs.h>
60#include <asm/uasm.h>
61
62#include <asm/octeon/octeon.h>
49d148b4 63#include <asm/octeon/cvmx-boot-vector.h>
0cd4e7a9 64#include <asm/octeon/cvmx-ciu2-defs.h>
1d1821b2
CM
65#include <asm/octeon/cvmx-rst-defs.h>
66
67/* Watchdog interrupt major block number (8 MSBs of intsn) */
68#define WD_BLOCK_NUMBER 0x01
0cd4e7a9
DD
69
70static int divisor;
4c076fb4
DD
71
72/* The count needed to achieve timeout_sec. */
73static unsigned int timeout_cnt;
74
75/* The maximum period supported. */
76static unsigned int max_timeout_sec;
77
78/* The current period. */
79static unsigned int timeout_sec;
80
81/* Set to non-zero when userspace countdown mode active */
381cec02 82static bool do_countdown;
4c076fb4
DD
83static unsigned int countdown_reset;
84static unsigned int per_cpu_countdown[NR_CPUS];
85
86static cpumask_t irq_enabled_cpus;
87
88#define WD_TIMO 60 /* Default heartbeat = 60 seconds */
89
1d1821b2
CM
90#define CVMX_GSERX_SCRATCH(offset) (CVMX_ADD_IO_SEG(0x0001180090000020ull) + ((offset) & 15) * 0x1000000ull)
91
4c076fb4 92static int heartbeat = WD_TIMO;
381cec02 93module_param(heartbeat, int, 0444);
4c076fb4
DD
94MODULE_PARM_DESC(heartbeat,
95 "Watchdog heartbeat in seconds. (0 < heartbeat, default="
96 __MODULE_STRING(WD_TIMO) ")");
97
86a1e189 98static bool nowayout = WATCHDOG_NOWAYOUT;
381cec02 99module_param(nowayout, bool, 0444);
4c076fb4
DD
100MODULE_PARM_DESC(nowayout,
101 "Watchdog cannot be stopped once started (default="
102 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
103
381cec02
SH
104static int disable;
105module_param(disable, int, 0444);
106MODULE_PARM_DESC(disable,
107 "Disable the watchdog entirely (default=0)");
108
49d148b4 109static struct cvmx_boot_vector_element *octeon_wdt_bootvector;
4c076fb4
DD
110
111void octeon_wdt_nmi_stage2(void);
112
4c076fb4
DD
113static int cpu2core(int cpu)
114{
115#ifdef CONFIG_SMP
1d1821b2 116 return cpu_logical_map(cpu) & 0x3f;
4c076fb4
DD
117#else
118 return cvmx_get_core_num();
119#endif
120}
121
4c076fb4 122/**
4700df05 123 * octeon_wdt_poke_irq - Poke the watchdog when an interrupt is received
4c076fb4
DD
124 *
125 * @cpl:
126 * @dev_id:
127 *
128 * Returns
129 */
130static irqreturn_t octeon_wdt_poke_irq(int cpl, void *dev_id)
131{
1d1821b2
CM
132 int cpu = raw_smp_processor_id();
133 unsigned int core = cpu2core(cpu);
134 int node = cpu_to_node(cpu);
4c076fb4 135
381cec02 136 if (do_countdown) {
4c076fb4
DD
137 if (per_cpu_countdown[cpu] > 0) {
138 /* We're alive, poke the watchdog */
1d1821b2 139 cvmx_write_csr_node(node, CVMX_CIU_PP_POKEX(core), 1);
4c076fb4
DD
140 per_cpu_countdown[cpu]--;
141 } else {
142 /* Bad news, you are about to reboot. */
143 disable_irq_nosync(cpl);
144 cpumask_clear_cpu(cpu, &irq_enabled_cpus);
145 }
146 } else {
147 /* Not open, just ping away... */
1d1821b2 148 cvmx_write_csr_node(node, CVMX_CIU_PP_POKEX(core), 1);
4c076fb4
DD
149 }
150 return IRQ_HANDLED;
151}
152
153/* From setup.c */
154extern int prom_putchar(char c);
155
156/**
4700df05 157 * octeon_wdt_write_string - Write a string to the uart
4c076fb4
DD
158 *
159 * @str: String to write
160 */
161static void octeon_wdt_write_string(const char *str)
162{
163 /* Just loop writing one byte at a time */
164 while (*str)
165 prom_putchar(*str++);
166}
167
168/**
4700df05 169 * octeon_wdt_write_hex() - Write a hex number out of the uart
4c076fb4
DD
170 *
171 * @value: Number to display
172 * @digits: Number of digits to print (1 to 16)
173 */
174static void octeon_wdt_write_hex(u64 value, int digits)
175{
176 int d;
177 int v;
8692cf0a 178
4c076fb4
DD
179 for (d = 0; d < digits; d++) {
180 v = (value >> ((digits - d - 1) * 4)) & 0xf;
181 if (v >= 10)
182 prom_putchar('a' + v - 10);
183 else
184 prom_putchar('0' + v);
185 }
186}
187
3a30c07e 188static const char reg_name[][3] = {
4c076fb4
DD
189 "$0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
190 "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3",
191 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
192 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
193};
194
195/**
4700df05
LB
196 * octeon_wdt_nmi_stage3:
197 *
4c076fb4
DD
198 * NMI stage 3 handler. NMIs are handled in the following manner:
199 * 1) The first NMI handler enables CVMSEG and transfers from
200 * the bootbus region into normal memory. It is careful to not
201 * destroy any registers.
202 * 2) The second stage handler uses CVMSEG to save the registers
203 * and create a stack for C code. It then calls the third level
204 * handler with one argument, a pointer to the register values.
205 * 3) The third, and final, level handler is the following C
206 * function that prints out some useful infomration.
207 *
208 * @reg: Pointer to register state before the NMI
209 */
210void octeon_wdt_nmi_stage3(u64 reg[32])
211{
212 u64 i;
213
214 unsigned int coreid = cvmx_get_core_num();
215 /*
216 * Save status and cause early to get them before any changes
217 * might happen.
218 */
219 u64 cp0_cause = read_c0_cause();
220 u64 cp0_status = read_c0_status();
221 u64 cp0_error_epc = read_c0_errorepc();
222 u64 cp0_epc = read_c0_epc();
223
224 /* Delay so output from all cores output is not jumbled together. */
0cd4e7a9 225 udelay(85000 * coreid);
4c076fb4
DD
226
227 octeon_wdt_write_string("\r\n*** NMI Watchdog interrupt on Core 0x");
0cd4e7a9 228 octeon_wdt_write_hex(coreid, 2);
4c076fb4
DD
229 octeon_wdt_write_string(" ***\r\n");
230 for (i = 0; i < 32; i++) {
231 octeon_wdt_write_string("\t");
232 octeon_wdt_write_string(reg_name[i]);
233 octeon_wdt_write_string("\t0x");
234 octeon_wdt_write_hex(reg[i], 16);
235 if (i & 1)
236 octeon_wdt_write_string("\r\n");
237 }
238 octeon_wdt_write_string("\terr_epc\t0x");
239 octeon_wdt_write_hex(cp0_error_epc, 16);
240
241 octeon_wdt_write_string("\tepc\t0x");
242 octeon_wdt_write_hex(cp0_epc, 16);
243 octeon_wdt_write_string("\r\n");
244
245 octeon_wdt_write_string("\tstatus\t0x");
246 octeon_wdt_write_hex(cp0_status, 16);
247 octeon_wdt_write_string("\tcause\t0x");
248 octeon_wdt_write_hex(cp0_cause, 16);
249 octeon_wdt_write_string("\r\n");
250
0cd4e7a9
DD
251 /* The CIU register is different for each Octeon model. */
252 if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
253 octeon_wdt_write_string("\tsrc_wd\t0x");
254 octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU2_SRC_PPX_IP2_WDOG(coreid)), 16);
255 octeon_wdt_write_string("\ten_wd\t0x");
256 octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU2_EN_PPX_IP2_WDOG(coreid)), 16);
257 octeon_wdt_write_string("\r\n");
258 octeon_wdt_write_string("\tsrc_rml\t0x");
259 octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU2_SRC_PPX_IP2_RML(coreid)), 16);
260 octeon_wdt_write_string("\ten_rml\t0x");
261 octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU2_EN_PPX_IP2_RML(coreid)), 16);
262 octeon_wdt_write_string("\r\n");
263 octeon_wdt_write_string("\tsum\t0x");
264 octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU2_SUM_PPX_IP2(coreid)), 16);
265 octeon_wdt_write_string("\r\n");
266 } else if (!octeon_has_feature(OCTEON_FEATURE_CIU3)) {
267 octeon_wdt_write_string("\tsum0\t0x");
268 octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU_INTX_SUM0(coreid * 2)), 16);
269 octeon_wdt_write_string("\ten0\t0x");
270 octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU_INTX_EN0(coreid * 2)), 16);
271 octeon_wdt_write_string("\r\n");
272 }
4c076fb4
DD
273
274 octeon_wdt_write_string("*** Chip soft reset soon ***\r\n");
1d1821b2
CM
275
276 /*
277 * G-30204: We must trigger a soft reset before watchdog
278 * does an incomplete job of doing it.
279 */
280 if (OCTEON_IS_OCTEON3() && !OCTEON_IS_MODEL(OCTEON_CN70XX)) {
281 u64 scr;
282 unsigned int node = cvmx_get_node_num();
283 unsigned int lcore = cvmx_get_local_core_num();
284 union cvmx_ciu_wdogx ciu_wdog;
285
286 /*
287 * Wait for other cores to print out information, but
288 * not too long. Do the soft reset before watchdog
289 * can trigger it.
290 */
291 do {
292 ciu_wdog.u64 = cvmx_read_csr_node(node, CVMX_CIU_WDOGX(lcore));
293 } while (ciu_wdog.s.cnt > 0x10000);
294
295 scr = cvmx_read_csr_node(0, CVMX_GSERX_SCRATCH(0));
296 scr |= 1 << 11; /* Indicate watchdog in bit 11 */
297 cvmx_write_csr_node(0, CVMX_GSERX_SCRATCH(0), scr);
298 cvmx_write_csr_node(0, CVMX_RST_SOFT_RST, 1);
299 }
300}
301
302static int octeon_wdt_cpu_to_irq(int cpu)
303{
304 unsigned int coreid;
305 int node;
306 int irq;
307
308 coreid = cpu2core(cpu);
309 node = cpu_to_node(cpu);
310
311 if (octeon_has_feature(OCTEON_FEATURE_CIU3)) {
312 struct irq_domain *domain;
313 int hwirq;
314
315 domain = octeon_irq_get_block_domain(node,
316 WD_BLOCK_NUMBER);
317 hwirq = WD_BLOCK_NUMBER << 12 | 0x200 | coreid;
318 irq = irq_find_mapping(domain, hwirq);
319 } else {
320 irq = OCTEON_IRQ_WDOG0 + coreid;
321 }
322 return irq;
4c076fb4
DD
323}
324
948b9c60 325static int octeon_wdt_cpu_pre_down(unsigned int cpu)
4c076fb4
DD
326{
327 unsigned int core;
1d1821b2 328 int node;
4c076fb4
DD
329 union cvmx_ciu_wdogx ciu_wdog;
330
331 core = cpu2core(cpu);
332
1d1821b2 333 node = cpu_to_node(cpu);
4c076fb4
DD
334
335 /* Poke the watchdog to clear out its state */
1d1821b2 336 cvmx_write_csr_node(node, CVMX_CIU_PP_POKEX(core), 1);
4c076fb4
DD
337
338 /* Disable the hardware. */
339 ciu_wdog.u64 = 0;
1d1821b2 340 cvmx_write_csr_node(node, CVMX_CIU_WDOGX(core), ciu_wdog.u64);
4c076fb4 341
1d1821b2 342 free_irq(octeon_wdt_cpu_to_irq(cpu), octeon_wdt_poke_irq);
948b9c60 343 return 0;
4c076fb4
DD
344}
345
948b9c60 346static int octeon_wdt_cpu_online(unsigned int cpu)
4c076fb4
DD
347{
348 unsigned int core;
349 unsigned int irq;
350 union cvmx_ciu_wdogx ciu_wdog;
1d1821b2
CM
351 int node;
352 struct irq_domain *domain;
353 int hwirq;
4c076fb4
DD
354
355 core = cpu2core(cpu);
1d1821b2 356 node = cpu_to_node(cpu);
4c076fb4 357
49d148b4
SH
358 octeon_wdt_bootvector[core].target_ptr = (u64)octeon_wdt_nmi_stage2;
359
4c076fb4
DD
360 /* Disable it before doing anything with the interrupts. */
361 ciu_wdog.u64 = 0;
1d1821b2 362 cvmx_write_csr_node(node, CVMX_CIU_WDOGX(core), ciu_wdog.u64);
4c076fb4
DD
363
364 per_cpu_countdown[cpu] = countdown_reset;
365
1d1821b2
CM
366 if (octeon_has_feature(OCTEON_FEATURE_CIU3)) {
367 /* Must get the domain for the watchdog block */
368 domain = octeon_irq_get_block_domain(node, WD_BLOCK_NUMBER);
369
370 /* Get a irq for the wd intsn (hardware interrupt) */
371 hwirq = WD_BLOCK_NUMBER << 12 | 0x200 | core;
372 irq = irq_create_mapping(domain, hwirq);
373 irqd_set_trigger_type(irq_get_irq_data(irq),
374 IRQ_TYPE_EDGE_RISING);
375 } else
376 irq = OCTEON_IRQ_WDOG0 + core;
4c076fb4
DD
377
378 if (request_irq(irq, octeon_wdt_poke_irq,
47bfd058 379 IRQF_NO_THREAD, "octeon_wdt", octeon_wdt_poke_irq))
4c076fb4
DD
380 panic("octeon_wdt: Couldn't obtain irq %d", irq);
381
1d1821b2
CM
382 /* Must set the irq affinity here */
383 if (octeon_has_feature(OCTEON_FEATURE_CIU3)) {
4c97f043 384 irq_set_affinity(irq, cpumask_of(cpu));
1d1821b2
CM
385 }
386
4c076fb4
DD
387 cpumask_set_cpu(cpu, &irq_enabled_cpus);
388
389 /* Poke the watchdog to clear out its state */
1d1821b2 390 cvmx_write_csr_node(node, CVMX_CIU_PP_POKEX(core), 1);
4c076fb4
DD
391
392 /* Finally enable the watchdog now that all handlers are installed */
393 ciu_wdog.u64 = 0;
394 ciu_wdog.s.len = timeout_cnt;
395 ciu_wdog.s.mode = 3; /* 3 = Interrupt + NMI + Soft-Reset */
1d1821b2 396 cvmx_write_csr_node(node, CVMX_CIU_WDOGX(core), ciu_wdog.u64);
4c076fb4 397
948b9c60 398 return 0;
4c076fb4
DD
399}
400
3d588c93 401static int octeon_wdt_ping(struct watchdog_device __always_unused *wdog)
4c076fb4
DD
402{
403 int cpu;
404 int coreid;
1d1821b2 405 int node;
4c076fb4 406
381cec02
SH
407 if (disable)
408 return 0;
409
4c076fb4
DD
410 for_each_online_cpu(cpu) {
411 coreid = cpu2core(cpu);
1d1821b2
CM
412 node = cpu_to_node(cpu);
413 cvmx_write_csr_node(node, CVMX_CIU_PP_POKEX(coreid), 1);
4c076fb4 414 per_cpu_countdown[cpu] = countdown_reset;
381cec02 415 if ((countdown_reset || !do_countdown) &&
4c076fb4
DD
416 !cpumask_test_cpu(cpu, &irq_enabled_cpus)) {
417 /* We have to enable the irq */
1d1821b2 418 enable_irq(octeon_wdt_cpu_to_irq(cpu));
4c076fb4
DD
419 cpumask_set_cpu(cpu, &irq_enabled_cpus);
420 }
421 }
3d588c93 422 return 0;
4c076fb4
DD
423}
424
425static void octeon_wdt_calc_parameters(int t)
426{
427 unsigned int periods;
428
429 timeout_sec = max_timeout_sec;
430
431
432 /*
433 * Find the largest interrupt period, that can evenly divide
434 * the requested heartbeat time.
435 */
436 while ((t % timeout_sec) != 0)
437 timeout_sec--;
438
439 periods = t / timeout_sec;
440
441 /*
442 * The last two periods are after the irq is disabled, and
443 * then to the nmi, so we subtract them off.
444 */
445
446 countdown_reset = periods > 2 ? periods - 2 : 0;
447 heartbeat = t;
0cd4e7a9 448 timeout_cnt = ((octeon_get_io_clock_rate() / divisor) * timeout_sec) >> 8;
4c076fb4
DD
449}
450
3d588c93
AK
451static int octeon_wdt_set_timeout(struct watchdog_device *wdog,
452 unsigned int t)
4c076fb4
DD
453{
454 int cpu;
455 int coreid;
456 union cvmx_ciu_wdogx ciu_wdog;
1d1821b2 457 int node;
4c076fb4
DD
458
459 if (t <= 0)
460 return -1;
461
462 octeon_wdt_calc_parameters(t);
463
381cec02
SH
464 if (disable)
465 return 0;
466
4c076fb4
DD
467 for_each_online_cpu(cpu) {
468 coreid = cpu2core(cpu);
1d1821b2
CM
469 node = cpu_to_node(cpu);
470 cvmx_write_csr_node(node, CVMX_CIU_PP_POKEX(coreid), 1);
4c076fb4
DD
471 ciu_wdog.u64 = 0;
472 ciu_wdog.s.len = timeout_cnt;
473 ciu_wdog.s.mode = 3; /* 3 = Interrupt + NMI + Soft-Reset */
1d1821b2
CM
474 cvmx_write_csr_node(node, CVMX_CIU_WDOGX(coreid), ciu_wdog.u64);
475 cvmx_write_csr_node(node, CVMX_CIU_PP_POKEX(coreid), 1);
4c076fb4 476 }
3d588c93 477 octeon_wdt_ping(wdog); /* Get the irqs back on. */
4c076fb4
DD
478 return 0;
479}
480
3d588c93 481static int octeon_wdt_start(struct watchdog_device *wdog)
4c076fb4 482{
3d588c93 483 octeon_wdt_ping(wdog);
381cec02 484 do_countdown = 1;
3d588c93 485 return 0;
4c076fb4
DD
486}
487
3d588c93 488static int octeon_wdt_stop(struct watchdog_device *wdog)
4c076fb4 489{
381cec02 490 do_countdown = 0;
3d588c93 491 octeon_wdt_ping(wdog);
4c076fb4
DD
492 return 0;
493}
494
3d588c93
AK
495static const struct watchdog_info octeon_wdt_info = {
496 .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING,
497 .identity = "OCTEON",
4c076fb4
DD
498};
499
3d588c93
AK
500static const struct watchdog_ops octeon_wdt_ops = {
501 .owner = THIS_MODULE,
502 .start = octeon_wdt_start,
503 .stop = octeon_wdt_stop,
504 .ping = octeon_wdt_ping,
505 .set_timeout = octeon_wdt_set_timeout,
4c076fb4
DD
506};
507
3d588c93
AK
508static struct watchdog_device octeon_wdt = {
509 .info = &octeon_wdt_info,
510 .ops = &octeon_wdt_ops,
511};
4c076fb4 512
948b9c60 513static enum cpuhp_state octeon_wdt_online;
4c076fb4 514/**
4700df05 515 * octeon_wdt_init - Module/ driver initialization.
4c076fb4
DD
516 *
517 * Returns Zero on success
518 */
519static int __init octeon_wdt_init(void)
520{
4c076fb4 521 int ret;
4c076fb4 522
49d148b4
SH
523 octeon_wdt_bootvector = cvmx_boot_vector_get();
524 if (!octeon_wdt_bootvector) {
525 pr_err("Error: Cannot allocate boot vector.\n");
526 return -ENOMEM;
527 }
528
0cd4e7a9
DD
529 if (OCTEON_IS_MODEL(OCTEON_CN68XX))
530 divisor = 0x200;
1d1821b2
CM
531 else if (OCTEON_IS_MODEL(OCTEON_CN78XX))
532 divisor = 0x400;
0cd4e7a9
DD
533 else
534 divisor = 0x100;
535
4c076fb4
DD
536 /*
537 * Watchdog time expiration length = The 16 bits of LEN
538 * represent the most significant bits of a 24 bit decrementer
0cd4e7a9 539 * that decrements every divisor cycle.
4c076fb4
DD
540 *
541 * Try for a timeout of 5 sec, if that fails a smaller number
542 * of even seconds,
543 */
544 max_timeout_sec = 6;
545 do {
546 max_timeout_sec--;
0cd4e7a9 547 timeout_cnt = ((octeon_get_io_clock_rate() / divisor) * max_timeout_sec) >> 8;
4c076fb4
DD
548 } while (timeout_cnt > 65535);
549
550 BUG_ON(timeout_cnt == 0);
551
552 octeon_wdt_calc_parameters(heartbeat);
553
27c766aa 554 pr_info("Initial granularity %d Sec\n", timeout_sec);
4c076fb4 555
3d588c93
AK
556 octeon_wdt.timeout = timeout_sec;
557 octeon_wdt.max_timeout = UINT_MAX;
558
559 watchdog_set_nowayout(&octeon_wdt, nowayout);
560
561 ret = watchdog_register_device(&octeon_wdt);
4c076fb4 562 if (ret) {
3d588c93
AK
563 pr_err("watchdog_register_device() failed: %d\n", ret);
564 return ret;
4c076fb4
DD
565 }
566
381cec02
SH
567 if (disable) {
568 pr_notice("disabled\n");
569 return 0;
570 }
571
4c076fb4
DD
572 cpumask_clear(&irq_enabled_cpus);
573
948b9c60
SAS
574 ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "watchdog/octeon:online",
575 octeon_wdt_cpu_online, octeon_wdt_cpu_pre_down);
576 if (ret < 0)
577 goto err;
578 octeon_wdt_online = ret;
3d588c93 579 return 0;
948b9c60
SAS
580err:
581 cvmx_write_csr(CVMX_MIO_BOOT_LOC_CFGX(0), 0);
582 watchdog_unregister_device(&octeon_wdt);
583 return ret;
4c076fb4
DD
584}
585
586/**
4700df05 587 * octeon_wdt_cleanup - Module / driver shutdown
4c076fb4
DD
588 */
589static void __exit octeon_wdt_cleanup(void)
590{
3d588c93 591 watchdog_unregister_device(&octeon_wdt);
381cec02
SH
592
593 if (disable)
594 return;
595
948b9c60 596 cpuhp_remove_state(octeon_wdt_online);
99c3bf36 597
4c076fb4
DD
598 /*
599 * Disable the boot-bus memory, the code it points to is soon
600 * to go missing.
601 */
602 cvmx_write_csr(CVMX_MIO_BOOT_LOC_CFGX(0), 0);
603}
604
605MODULE_LICENSE("GPL");
381cec02
SH
606MODULE_AUTHOR("Cavium Inc. <support@cavium.com>");
607MODULE_DESCRIPTION("Cavium Inc. OCTEON Watchdog driver.");
4c076fb4
DD
608module_init(octeon_wdt_init);
609module_exit(octeon_wdt_cleanup);