octeon-wdt-main.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /*
  2. * Octeon Watchdog driver
  3. *
  4. * Copyright (C) 2007-2017 Cavium, Inc.
  5. *
  6. * Converted to use WATCHDOG_CORE by Aaro Koskinen <aaro.koskinen@iki.fi>.
  7. *
  8. * 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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  57. #include <linux/interrupt.h>
  58. #include <linux/watchdog.h>
  59. #include <linux/cpumask.h>
  60. #include <linux/module.h>
  61. #include <linux/delay.h>
  62. #include <linux/cpu.h>
  63. #include <linux/irq.h>
  64. #include <asm/mipsregs.h>
  65. #include <asm/uasm.h>
  66. #include <asm/octeon/octeon.h>
  67. #include <asm/octeon/cvmx-boot-vector.h>
  68. #include <asm/octeon/cvmx-ciu2-defs.h>
  69. #include <asm/octeon/cvmx-rst-defs.h>
  70. /* Watchdog interrupt major block number (8 MSBs of intsn) */
  71. #define WD_BLOCK_NUMBER 0x01
  72. static int divisor;
  73. /* The count needed to achieve timeout_sec. */
  74. static unsigned int timeout_cnt;
  75. /* The maximum period supported. */
  76. static unsigned int max_timeout_sec;
  77. /* The current period. */
  78. static unsigned int timeout_sec;
  79. /* Set to non-zero when userspace countdown mode active */
  80. static bool do_countdown;
  81. static unsigned int countdown_reset;
  82. static unsigned int per_cpu_countdown[NR_CPUS];
  83. static cpumask_t irq_enabled_cpus;
  84. #define WD_TIMO 60 /* Default heartbeat = 60 seconds */
  85. #define CVMX_GSERX_SCRATCH(offset) (CVMX_ADD_IO_SEG(0x0001180090000020ull) + ((offset) & 15) * 0x1000000ull)
  86. static int heartbeat = WD_TIMO;
  87. module_param(heartbeat, int, 0444);
  88. MODULE_PARM_DESC(heartbeat,
  89. "Watchdog heartbeat in seconds. (0 < heartbeat, default="
  90. __MODULE_STRING(WD_TIMO) ")");
  91. static bool nowayout = WATCHDOG_NOWAYOUT;
  92. module_param(nowayout, bool, 0444);
  93. MODULE_PARM_DESC(nowayout,
  94. "Watchdog cannot be stopped once started (default="
  95. __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  96. static int disable;
  97. module_param(disable, int, 0444);
  98. MODULE_PARM_DESC(disable,
  99. "Disable the watchdog entirely (default=0)");
  100. static struct cvmx_boot_vector_element *octeon_wdt_bootvector;
  101. void octeon_wdt_nmi_stage2(void);
  102. static int cpu2core(int cpu)
  103. {
  104. #ifdef CONFIG_SMP
  105. return cpu_logical_map(cpu) & 0x3f;
  106. #else
  107. return cvmx_get_core_num();
  108. #endif
  109. }
  110. /**
  111. * Poke the watchdog when an interrupt is received
  112. *
  113. * @cpl:
  114. * @dev_id:
  115. *
  116. * Returns
  117. */
  118. static irqreturn_t octeon_wdt_poke_irq(int cpl, void *dev_id)
  119. {
  120. int cpu = raw_smp_processor_id();
  121. unsigned int core = cpu2core(cpu);
  122. int node = cpu_to_node(cpu);
  123. if (do_countdown) {
  124. if (per_cpu_countdown[cpu] > 0) {
  125. /* We're alive, poke the watchdog */
  126. cvmx_write_csr_node(node, CVMX_CIU_PP_POKEX(core), 1);
  127. per_cpu_countdown[cpu]--;
  128. } else {
  129. /* Bad news, you are about to reboot. */
  130. disable_irq_nosync(cpl);
  131. cpumask_clear_cpu(cpu, &irq_enabled_cpus);
  132. }
  133. } else {
  134. /* Not open, just ping away... */
  135. cvmx_write_csr_node(node, CVMX_CIU_PP_POKEX(core), 1);
  136. }
  137. return IRQ_HANDLED;
  138. }
  139. /* From setup.c */
  140. extern int prom_putchar(char c);
  141. /**
  142. * Write a string to the uart
  143. *
  144. * @str: String to write
  145. */
  146. static void octeon_wdt_write_string(const char *str)
  147. {
  148. /* Just loop writing one byte at a time */
  149. while (*str)
  150. prom_putchar(*str++);
  151. }
  152. /**
  153. * Write a hex number out of the uart
  154. *
  155. * @value: Number to display
  156. * @digits: Number of digits to print (1 to 16)
  157. */
  158. static void octeon_wdt_write_hex(u64 value, int digits)
  159. {
  160. int d;
  161. int v;
  162. for (d = 0; d < digits; d++) {
  163. v = (value >> ((digits - d - 1) * 4)) & 0xf;
  164. if (v >= 10)
  165. prom_putchar('a' + v - 10);
  166. else
  167. prom_putchar('0' + v);
  168. }
  169. }
  170. static const char reg_name[][3] = {
  171. "$0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
  172. "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3",
  173. "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
  174. "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
  175. };
  176. /**
  177. * NMI stage 3 handler. NMIs are handled in the following manner:
  178. * 1) The first NMI handler enables CVMSEG and transfers from
  179. * the bootbus region into normal memory. It is careful to not
  180. * destroy any registers.
  181. * 2) The second stage handler uses CVMSEG to save the registers
  182. * and create a stack for C code. It then calls the third level
  183. * handler with one argument, a pointer to the register values.
  184. * 3) The third, and final, level handler is the following C
  185. * function that prints out some useful infomration.
  186. *
  187. * @reg: Pointer to register state before the NMI
  188. */
  189. void octeon_wdt_nmi_stage3(u64 reg[32])
  190. {
  191. u64 i;
  192. unsigned int coreid = cvmx_get_core_num();
  193. /*
  194. * Save status and cause early to get them before any changes
  195. * might happen.
  196. */
  197. u64 cp0_cause = read_c0_cause();
  198. u64 cp0_status = read_c0_status();
  199. u64 cp0_error_epc = read_c0_errorepc();
  200. u64 cp0_epc = read_c0_epc();
  201. /* Delay so output from all cores output is not jumbled together. */
  202. udelay(85000 * coreid);
  203. octeon_wdt_write_string("\r\n*** NMI Watchdog interrupt on Core 0x");
  204. octeon_wdt_write_hex(coreid, 2);
  205. octeon_wdt_write_string(" ***\r\n");
  206. for (i = 0; i < 32; i++) {
  207. octeon_wdt_write_string("\t");
  208. octeon_wdt_write_string(reg_name[i]);
  209. octeon_wdt_write_string("\t0x");
  210. octeon_wdt_write_hex(reg[i], 16);
  211. if (i & 1)
  212. octeon_wdt_write_string("\r\n");
  213. }
  214. octeon_wdt_write_string("\terr_epc\t0x");
  215. octeon_wdt_write_hex(cp0_error_epc, 16);
  216. octeon_wdt_write_string("\tepc\t0x");
  217. octeon_wdt_write_hex(cp0_epc, 16);
  218. octeon_wdt_write_string("\r\n");
  219. octeon_wdt_write_string("\tstatus\t0x");
  220. octeon_wdt_write_hex(cp0_status, 16);
  221. octeon_wdt_write_string("\tcause\t0x");
  222. octeon_wdt_write_hex(cp0_cause, 16);
  223. octeon_wdt_write_string("\r\n");
  224. /* The CIU register is different for each Octeon model. */
  225. if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
  226. octeon_wdt_write_string("\tsrc_wd\t0x");
  227. octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU2_SRC_PPX_IP2_WDOG(coreid)), 16);
  228. octeon_wdt_write_string("\ten_wd\t0x");
  229. octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU2_EN_PPX_IP2_WDOG(coreid)), 16);
  230. octeon_wdt_write_string("\r\n");
  231. octeon_wdt_write_string("\tsrc_rml\t0x");
  232. octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU2_SRC_PPX_IP2_RML(coreid)), 16);
  233. octeon_wdt_write_string("\ten_rml\t0x");
  234. octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU2_EN_PPX_IP2_RML(coreid)), 16);
  235. octeon_wdt_write_string("\r\n");
  236. octeon_wdt_write_string("\tsum\t0x");
  237. octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU2_SUM_PPX_IP2(coreid)), 16);
  238. octeon_wdt_write_string("\r\n");
  239. } else if (!octeon_has_feature(OCTEON_FEATURE_CIU3)) {
  240. octeon_wdt_write_string("\tsum0\t0x");
  241. octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU_INTX_SUM0(coreid * 2)), 16);
  242. octeon_wdt_write_string("\ten0\t0x");
  243. octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU_INTX_EN0(coreid * 2)), 16);
  244. octeon_wdt_write_string("\r\n");
  245. }
  246. octeon_wdt_write_string("*** Chip soft reset soon ***\r\n");
  247. /*
  248. * G-30204: We must trigger a soft reset before watchdog
  249. * does an incomplete job of doing it.
  250. */
  251. if (OCTEON_IS_OCTEON3() && !OCTEON_IS_MODEL(OCTEON_CN70XX)) {
  252. u64 scr;
  253. unsigned int node = cvmx_get_node_num();
  254. unsigned int lcore = cvmx_get_local_core_num();
  255. union cvmx_ciu_wdogx ciu_wdog;
  256. /*
  257. * Wait for other cores to print out information, but
  258. * not too long. Do the soft reset before watchdog
  259. * can trigger it.
  260. */
  261. do {
  262. ciu_wdog.u64 = cvmx_read_csr_node(node, CVMX_CIU_WDOGX(lcore));
  263. } while (ciu_wdog.s.cnt > 0x10000);
  264. scr = cvmx_read_csr_node(0, CVMX_GSERX_SCRATCH(0));
  265. scr |= 1 << 11; /* Indicate watchdog in bit 11 */
  266. cvmx_write_csr_node(0, CVMX_GSERX_SCRATCH(0), scr);
  267. cvmx_write_csr_node(0, CVMX_RST_SOFT_RST, 1);
  268. }
  269. }
  270. static int octeon_wdt_cpu_to_irq(int cpu)
  271. {
  272. unsigned int coreid;
  273. int node;
  274. int irq;
  275. coreid = cpu2core(cpu);
  276. node = cpu_to_node(cpu);
  277. if (octeon_has_feature(OCTEON_FEATURE_CIU3)) {
  278. struct irq_domain *domain;
  279. int hwirq;
  280. domain = octeon_irq_get_block_domain(node,
  281. WD_BLOCK_NUMBER);
  282. hwirq = WD_BLOCK_NUMBER << 12 | 0x200 | coreid;
  283. irq = irq_find_mapping(domain, hwirq);
  284. } else {
  285. irq = OCTEON_IRQ_WDOG0 + coreid;
  286. }
  287. return irq;
  288. }
  289. static int octeon_wdt_cpu_pre_down(unsigned int cpu)
  290. {
  291. unsigned int core;
  292. int node;
  293. union cvmx_ciu_wdogx ciu_wdog;
  294. core = cpu2core(cpu);
  295. node = cpu_to_node(cpu);
  296. /* Poke the watchdog to clear out its state */
  297. cvmx_write_csr_node(node, CVMX_CIU_PP_POKEX(core), 1);
  298. /* Disable the hardware. */
  299. ciu_wdog.u64 = 0;
  300. cvmx_write_csr_node(node, CVMX_CIU_WDOGX(core), ciu_wdog.u64);
  301. free_irq(octeon_wdt_cpu_to_irq(cpu), octeon_wdt_poke_irq);
  302. return 0;
  303. }
  304. static int octeon_wdt_cpu_online(unsigned int cpu)
  305. {
  306. unsigned int core;
  307. unsigned int irq;
  308. union cvmx_ciu_wdogx ciu_wdog;
  309. int node;
  310. struct irq_domain *domain;
  311. int hwirq;
  312. core = cpu2core(cpu);
  313. node = cpu_to_node(cpu);
  314. octeon_wdt_bootvector[core].target_ptr = (u64)octeon_wdt_nmi_stage2;
  315. /* Disable it before doing anything with the interrupts. */
  316. ciu_wdog.u64 = 0;
  317. cvmx_write_csr_node(node, CVMX_CIU_WDOGX(core), ciu_wdog.u64);
  318. per_cpu_countdown[cpu] = countdown_reset;
  319. if (octeon_has_feature(OCTEON_FEATURE_CIU3)) {
  320. /* Must get the domain for the watchdog block */
  321. domain = octeon_irq_get_block_domain(node, WD_BLOCK_NUMBER);
  322. /* Get a irq for the wd intsn (hardware interrupt) */
  323. hwirq = WD_BLOCK_NUMBER << 12 | 0x200 | core;
  324. irq = irq_create_mapping(domain, hwirq);
  325. irqd_set_trigger_type(irq_get_irq_data(irq),
  326. IRQ_TYPE_EDGE_RISING);
  327. } else
  328. irq = OCTEON_IRQ_WDOG0 + core;
  329. if (request_irq(irq, octeon_wdt_poke_irq,
  330. IRQF_NO_THREAD, "octeon_wdt", octeon_wdt_poke_irq))
  331. panic("octeon_wdt: Couldn't obtain irq %d", irq);
  332. /* Must set the irq affinity here */
  333. if (octeon_has_feature(OCTEON_FEATURE_CIU3)) {
  334. cpumask_t mask;
  335. cpumask_clear(&mask);
  336. cpumask_set_cpu(cpu, &mask);
  337. irq_set_affinity(irq, &mask);
  338. }
  339. cpumask_set_cpu(cpu, &irq_enabled_cpus);
  340. /* Poke the watchdog to clear out its state */
  341. cvmx_write_csr_node(node, CVMX_CIU_PP_POKEX(core), 1);
  342. /* Finally enable the watchdog now that all handlers are installed */
  343. ciu_wdog.u64 = 0;
  344. ciu_wdog.s.len = timeout_cnt;
  345. ciu_wdog.s.mode = 3; /* 3 = Interrupt + NMI + Soft-Reset */
  346. cvmx_write_csr_node(node, CVMX_CIU_WDOGX(core), ciu_wdog.u64);
  347. return 0;
  348. }
  349. static int octeon_wdt_ping(struct watchdog_device __always_unused *wdog)
  350. {
  351. int cpu;
  352. int coreid;
  353. int node;
  354. if (disable)
  355. return 0;
  356. for_each_online_cpu(cpu) {
  357. coreid = cpu2core(cpu);
  358. node = cpu_to_node(cpu);
  359. cvmx_write_csr_node(node, CVMX_CIU_PP_POKEX(coreid), 1);
  360. per_cpu_countdown[cpu] = countdown_reset;
  361. if ((countdown_reset || !do_countdown) &&
  362. !cpumask_test_cpu(cpu, &irq_enabled_cpus)) {
  363. /* We have to enable the irq */
  364. enable_irq(octeon_wdt_cpu_to_irq(cpu));
  365. cpumask_set_cpu(cpu, &irq_enabled_cpus);
  366. }
  367. }
  368. return 0;
  369. }
  370. static void octeon_wdt_calc_parameters(int t)
  371. {
  372. unsigned int periods;
  373. timeout_sec = max_timeout_sec;
  374. /*
  375. * Find the largest interrupt period, that can evenly divide
  376. * the requested heartbeat time.
  377. */
  378. while ((t % timeout_sec) != 0)
  379. timeout_sec--;
  380. periods = t / timeout_sec;
  381. /*
  382. * The last two periods are after the irq is disabled, and
  383. * then to the nmi, so we subtract them off.
  384. */
  385. countdown_reset = periods > 2 ? periods - 2 : 0;
  386. heartbeat = t;
  387. timeout_cnt = ((octeon_get_io_clock_rate() / divisor) * timeout_sec) >> 8;
  388. }
  389. static int octeon_wdt_set_timeout(struct watchdog_device *wdog,
  390. unsigned int t)
  391. {
  392. int cpu;
  393. int coreid;
  394. union cvmx_ciu_wdogx ciu_wdog;
  395. int node;
  396. if (t <= 0)
  397. return -1;
  398. octeon_wdt_calc_parameters(t);
  399. if (disable)
  400. return 0;
  401. for_each_online_cpu(cpu) {
  402. coreid = cpu2core(cpu);
  403. node = cpu_to_node(cpu);
  404. cvmx_write_csr_node(node, CVMX_CIU_PP_POKEX(coreid), 1);
  405. ciu_wdog.u64 = 0;
  406. ciu_wdog.s.len = timeout_cnt;
  407. ciu_wdog.s.mode = 3; /* 3 = Interrupt + NMI + Soft-Reset */
  408. cvmx_write_csr_node(node, CVMX_CIU_WDOGX(coreid), ciu_wdog.u64);
  409. cvmx_write_csr_node(node, CVMX_CIU_PP_POKEX(coreid), 1);
  410. }
  411. octeon_wdt_ping(wdog); /* Get the irqs back on. */
  412. return 0;
  413. }
  414. static int octeon_wdt_start(struct watchdog_device *wdog)
  415. {
  416. octeon_wdt_ping(wdog);
  417. do_countdown = 1;
  418. return 0;
  419. }
  420. static int octeon_wdt_stop(struct watchdog_device *wdog)
  421. {
  422. do_countdown = 0;
  423. octeon_wdt_ping(wdog);
  424. return 0;
  425. }
  426. static const struct watchdog_info octeon_wdt_info = {
  427. .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING,
  428. .identity = "OCTEON",
  429. };
  430. static const struct watchdog_ops octeon_wdt_ops = {
  431. .owner = THIS_MODULE,
  432. .start = octeon_wdt_start,
  433. .stop = octeon_wdt_stop,
  434. .ping = octeon_wdt_ping,
  435. .set_timeout = octeon_wdt_set_timeout,
  436. };
  437. static struct watchdog_device octeon_wdt = {
  438. .info = &octeon_wdt_info,
  439. .ops = &octeon_wdt_ops,
  440. };
  441. static enum cpuhp_state octeon_wdt_online;
  442. /**
  443. * Module/ driver initialization.
  444. *
  445. * Returns Zero on success
  446. */
  447. static int __init octeon_wdt_init(void)
  448. {
  449. int ret;
  450. octeon_wdt_bootvector = cvmx_boot_vector_get();
  451. if (!octeon_wdt_bootvector) {
  452. pr_err("Error: Cannot allocate boot vector.\n");
  453. return -ENOMEM;
  454. }
  455. if (OCTEON_IS_MODEL(OCTEON_CN68XX))
  456. divisor = 0x200;
  457. else if (OCTEON_IS_MODEL(OCTEON_CN78XX))
  458. divisor = 0x400;
  459. else
  460. divisor = 0x100;
  461. /*
  462. * Watchdog time expiration length = The 16 bits of LEN
  463. * represent the most significant bits of a 24 bit decrementer
  464. * that decrements every divisor cycle.
  465. *
  466. * Try for a timeout of 5 sec, if that fails a smaller number
  467. * of even seconds,
  468. */
  469. max_timeout_sec = 6;
  470. do {
  471. max_timeout_sec--;
  472. timeout_cnt = ((octeon_get_io_clock_rate() / divisor) * max_timeout_sec) >> 8;
  473. } while (timeout_cnt > 65535);
  474. BUG_ON(timeout_cnt == 0);
  475. octeon_wdt_calc_parameters(heartbeat);
  476. pr_info("Initial granularity %d Sec\n", timeout_sec);
  477. octeon_wdt.timeout = timeout_sec;
  478. octeon_wdt.max_timeout = UINT_MAX;
  479. watchdog_set_nowayout(&octeon_wdt, nowayout);
  480. ret = watchdog_register_device(&octeon_wdt);
  481. if (ret) {
  482. pr_err("watchdog_register_device() failed: %d\n", ret);
  483. return ret;
  484. }
  485. if (disable) {
  486. pr_notice("disabled\n");
  487. return 0;
  488. }
  489. cpumask_clear(&irq_enabled_cpus);
  490. ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "watchdog/octeon:online",
  491. octeon_wdt_cpu_online, octeon_wdt_cpu_pre_down);
  492. if (ret < 0)
  493. goto err;
  494. octeon_wdt_online = ret;
  495. return 0;
  496. err:
  497. cvmx_write_csr(CVMX_MIO_BOOT_LOC_CFGX(0), 0);
  498. watchdog_unregister_device(&octeon_wdt);
  499. return ret;
  500. }
  501. /**
  502. * Module / driver shutdown
  503. */
  504. static void __exit octeon_wdt_cleanup(void)
  505. {
  506. watchdog_unregister_device(&octeon_wdt);
  507. if (disable)
  508. return;
  509. cpuhp_remove_state(octeon_wdt_online);
  510. /*
  511. * Disable the boot-bus memory, the code it points to is soon
  512. * to go missing.
  513. */
  514. cvmx_write_csr(CVMX_MIO_BOOT_LOC_CFGX(0), 0);
  515. }
  516. MODULE_LICENSE("GPL");
  517. MODULE_AUTHOR("Cavium Inc. <support@cavium.com>");
  518. MODULE_DESCRIPTION("Cavium Inc. OCTEON Watchdog driver.");
  519. module_init(octeon_wdt_init);
  520. module_exit(octeon_wdt_cleanup);