0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LINUX_WATCHDOG_H
0010 #define _LINUX_WATCHDOG_H
0011
0012
0013 #include <linux/bitops.h>
0014 #include <linux/cdev.h>
0015 #include <linux/device.h>
0016 #include <linux/kernel.h>
0017 #include <linux/notifier.h>
0018 #include <uapi/linux/watchdog.h>
0019
0020 struct watchdog_ops;
0021 struct watchdog_device;
0022 struct watchdog_core_data;
0023 struct watchdog_governor;
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 struct watchdog_ops {
0044 struct module *owner;
0045
0046 int (*start)(struct watchdog_device *);
0047
0048 int (*stop)(struct watchdog_device *);
0049 int (*ping)(struct watchdog_device *);
0050 unsigned int (*status)(struct watchdog_device *);
0051 int (*set_timeout)(struct watchdog_device *, unsigned int);
0052 int (*set_pretimeout)(struct watchdog_device *, unsigned int);
0053 unsigned int (*get_timeleft)(struct watchdog_device *);
0054 int (*restart)(struct watchdog_device *, unsigned long, void *);
0055 long (*ioctl)(struct watchdog_device *, unsigned int, unsigned long);
0056 };
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094 struct watchdog_device {
0095 int id;
0096 struct device *parent;
0097 const struct attribute_group **groups;
0098 const struct watchdog_info *info;
0099 const struct watchdog_ops *ops;
0100 const struct watchdog_governor *gov;
0101 unsigned int bootstatus;
0102 unsigned int timeout;
0103 unsigned int pretimeout;
0104 unsigned int min_timeout;
0105 unsigned int max_timeout;
0106 unsigned int min_hw_heartbeat_ms;
0107 unsigned int max_hw_heartbeat_ms;
0108 struct notifier_block reboot_nb;
0109 struct notifier_block restart_nb;
0110 struct notifier_block pm_nb;
0111 void *driver_data;
0112 struct watchdog_core_data *wd_data;
0113 unsigned long status;
0114
0115 #define WDOG_ACTIVE 0
0116 #define WDOG_NO_WAY_OUT 1
0117 #define WDOG_STOP_ON_REBOOT 2
0118 #define WDOG_HW_RUNNING 3
0119 #define WDOG_STOP_ON_UNREGISTER 4
0120 #define WDOG_NO_PING_ON_SUSPEND 5
0121 struct list_head deferred;
0122 };
0123
0124 #define WATCHDOG_NOWAYOUT IS_BUILTIN(CONFIG_WATCHDOG_NOWAYOUT)
0125 #define WATCHDOG_NOWAYOUT_INIT_STATUS (WATCHDOG_NOWAYOUT << WDOG_NO_WAY_OUT)
0126
0127
0128 static inline bool watchdog_active(struct watchdog_device *wdd)
0129 {
0130 return test_bit(WDOG_ACTIVE, &wdd->status);
0131 }
0132
0133
0134
0135
0136
0137 static inline bool watchdog_hw_running(struct watchdog_device *wdd)
0138 {
0139 return test_bit(WDOG_HW_RUNNING, &wdd->status);
0140 }
0141
0142
0143 static inline void watchdog_set_nowayout(struct watchdog_device *wdd, bool nowayout)
0144 {
0145 if (nowayout)
0146 set_bit(WDOG_NO_WAY_OUT, &wdd->status);
0147 }
0148
0149
0150 static inline void watchdog_stop_on_reboot(struct watchdog_device *wdd)
0151 {
0152 set_bit(WDOG_STOP_ON_REBOOT, &wdd->status);
0153 }
0154
0155
0156 static inline void watchdog_stop_on_unregister(struct watchdog_device *wdd)
0157 {
0158 set_bit(WDOG_STOP_ON_UNREGISTER, &wdd->status);
0159 }
0160
0161
0162 static inline void watchdog_stop_ping_on_suspend(struct watchdog_device *wdd)
0163 {
0164 set_bit(WDOG_NO_PING_ON_SUSPEND, &wdd->status);
0165 }
0166
0167
0168 static inline bool watchdog_timeout_invalid(struct watchdog_device *wdd, unsigned int t)
0169 {
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181 return t > UINT_MAX / 1000 || t < wdd->min_timeout ||
0182 (!wdd->max_hw_heartbeat_ms && wdd->max_timeout &&
0183 t > wdd->max_timeout);
0184 }
0185
0186
0187 static inline bool watchdog_pretimeout_invalid(struct watchdog_device *wdd,
0188 unsigned int t)
0189 {
0190 return t && wdd->timeout && t >= wdd->timeout;
0191 }
0192
0193
0194 static inline void watchdog_set_drvdata(struct watchdog_device *wdd, void *data)
0195 {
0196 wdd->driver_data = data;
0197 }
0198
0199 static inline void *watchdog_get_drvdata(struct watchdog_device *wdd)
0200 {
0201 return wdd->driver_data;
0202 }
0203
0204
0205 #if IS_ENABLED(CONFIG_WATCHDOG_PRETIMEOUT_GOV)
0206 void watchdog_notify_pretimeout(struct watchdog_device *wdd);
0207 #else
0208 static inline void watchdog_notify_pretimeout(struct watchdog_device *wdd)
0209 {
0210 pr_alert("watchdog%d: pretimeout event\n", wdd->id);
0211 }
0212 #endif
0213
0214
0215 void watchdog_set_restart_priority(struct watchdog_device *wdd, int priority);
0216 extern int watchdog_init_timeout(struct watchdog_device *wdd,
0217 unsigned int timeout_parm, struct device *dev);
0218 extern int watchdog_register_device(struct watchdog_device *);
0219 extern void watchdog_unregister_device(struct watchdog_device *);
0220 int watchdog_dev_suspend(struct watchdog_device *wdd);
0221 int watchdog_dev_resume(struct watchdog_device *wdd);
0222
0223 int watchdog_set_last_hw_keepalive(struct watchdog_device *, unsigned int);
0224
0225
0226 int devm_watchdog_register_device(struct device *dev, struct watchdog_device *);
0227
0228 #endif