watchdog_core.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * watchdog_core.h
  4. *
  5. * (c) Copyright 2008-2011 Alan Cox <alan@lxorguk.ukuu.org.uk>,
  6. * All Rights Reserved.
  7. *
  8. * (c) Copyright 2008-2011 Wim Van Sebroeck <wim@iguana.be>.
  9. *
  10. * (c) Copyright 2021 Hewlett Packard Enterprise Development LP.
  11. *
  12. * This source code is part of the generic code that can be used
  13. * by all the watchdog timer drivers.
  14. *
  15. * Based on source code of the following authors:
  16. * Matt Domsch <Matt_Domsch@dell.com>,
  17. * Rob Radez <rob@osinvestor.com>,
  18. * Rusty Lynch <rusty@linux.co.intel.com>
  19. * Satyam Sharma <satyam@infradead.org>
  20. * Randy Dunlap <randy.dunlap@oracle.com>
  21. *
  22. * Neither Alan Cox, CymruNet Ltd., Wim Van Sebroeck nor Iguana vzw.
  23. * admit liability nor provide warranty for any of this software.
  24. * This material is provided "AS-IS" and at no charge.
  25. */
  26. #include <linux/cdev.h>
  27. #include <linux/device.h>
  28. #include <linux/hrtimer_types.h>
  29. #include <linux/init.h>
  30. #include <linux/kthread.h>
  31. #include <linux/mutex_types.h>
  32. #include <linux/types.h>
  33. #include <linux/watchdog.h>
  34. #define MAX_DOGS 32 /* Maximum number of watchdog devices */
  35. /*
  36. * struct watchdog_core_data - watchdog core internal data
  37. * @dev: The watchdog's internal device
  38. * @cdev: The watchdog's Character device.
  39. * @wdd: Pointer to watchdog device.
  40. * @lock: Lock for watchdog core.
  41. * @status: Watchdog core internal status bits.
  42. */
  43. struct watchdog_core_data {
  44. struct device dev;
  45. struct cdev cdev;
  46. struct watchdog_device *wdd;
  47. struct mutex lock;
  48. ktime_t last_keepalive;
  49. ktime_t last_hw_keepalive;
  50. ktime_t open_deadline;
  51. struct hrtimer timer;
  52. struct kthread_work work;
  53. #if IS_ENABLED(CONFIG_WATCHDOG_HRTIMER_PRETIMEOUT)
  54. struct hrtimer pretimeout_timer;
  55. #endif
  56. unsigned long status; /* Internal status bits */
  57. #define _WDOG_DEV_OPEN 0 /* Opened ? */
  58. #define _WDOG_ALLOW_RELEASE 1 /* Did we receive the magic char ? */
  59. #define _WDOG_KEEPALIVE 2 /* Did we receive a keepalive ? */
  60. };
  61. /*
  62. * Functions/procedures to be called by the core
  63. */
  64. extern int watchdog_dev_register(struct watchdog_device *);
  65. extern void watchdog_dev_unregister(struct watchdog_device *);
  66. extern int __init watchdog_dev_init(void);
  67. extern void __exit watchdog_dev_exit(void);
  68. static inline bool watchdog_have_pretimeout(struct watchdog_device *wdd)
  69. {
  70. return wdd->info->options & WDIOF_PRETIMEOUT ||
  71. IS_ENABLED(CONFIG_WATCHDOG_HRTIMER_PRETIMEOUT);
  72. }
  73. #if IS_ENABLED(CONFIG_WATCHDOG_HRTIMER_PRETIMEOUT)
  74. void watchdog_hrtimer_pretimeout_init(struct watchdog_device *wdd);
  75. void watchdog_hrtimer_pretimeout_start(struct watchdog_device *wdd);
  76. void watchdog_hrtimer_pretimeout_stop(struct watchdog_device *wdd);
  77. #else
  78. static inline void watchdog_hrtimer_pretimeout_init(struct watchdog_device *wdd) {}
  79. static inline void watchdog_hrtimer_pretimeout_start(struct watchdog_device *wdd) {}
  80. static inline void watchdog_hrtimer_pretimeout_stop(struct watchdog_device *wdd) {}
  81. #endif