Blame view

include/linux/watchdog.h 7.5 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
  /*
   *	Generic watchdog defines. Derived from..
   *
   * Berkshire PC Watchdog Defines
   * by Ken Hollis <khollis@bitgate.com>
   *
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8
9
  #ifndef _LINUX_WATCHDOG_H
  #define _LINUX_WATCHDOG_H
4bfdf3783   Andrey Panin   [PATCH] consolida...
10

ff0b3cd4a   Wim Van Sebroeck   watchdog: add now...
11
  #include <linux/bitops.h>
45f5fed30   Alan Cox   watchdog: Add mul...
12
  #include <linux/cdev.h>
664a39236   Guenter Roeck   watchdog: Introdu...
13
14
  #include <linux/device.h>
  #include <linux/kernel.h>
2165bf524   Damien Riegel   watchdog: core: a...
15
  #include <linux/notifier.h>
607ca46e9   David Howells   UAPI: (Scripted) ...
16
  #include <uapi/linux/watchdog.h>
4bfdf3783   Andrey Panin   [PATCH] consolida...
17

43316044d   Wim Van Sebroeck   watchdog: WatchDo...
18
19
  struct watchdog_ops;
  struct watchdog_device;
b4ffb1909   Guenter Roeck   watchdog: Separat...
20
  struct watchdog_core_data;
ff84136cb   Vladimir Zapolskiy   watchdog: add wat...
21
  struct watchdog_governor;
43316044d   Wim Van Sebroeck   watchdog: WatchDo...
22
23
24
25
26
27
28
  
  /** struct watchdog_ops - The watchdog-devices operations
   *
   * @owner:	The module owner.
   * @start:	The routine for starting the watchdog device.
   * @stop:	The routine for stopping the watchdog device.
   * @ping:	The routine that sends a keepalive ping to the watchdog device.
2fa03560a   Wim Van Sebroeck   watchdog: WatchDo...
29
   * @status:	The routine that shows the status of the watchdog device.
760d28008   Wolfram Sang   watchdog: include...
30
   * @set_timeout:The routine for setting the watchdog devices timeout value (in seconds).
df044e022   Wolfram Sang   watchdog: add pre...
31
   * @set_pretimeout:The routine for setting the watchdog devices pretimeout.
760d28008   Wolfram Sang   watchdog: include...
32
   * @get_timeleft:The routine that gets the time left before a reset (in seconds).
2165bf524   Damien Riegel   watchdog: core: a...
33
   * @restart:	The routine for restarting the machine.
78d88fc01   Wim Van Sebroeck   watchdog: WatchDo...
34
   * @ioctl:	The routines that handles extra ioctl calls.
43316044d   Wim Van Sebroeck   watchdog: WatchDo...
35
36
37
38
   *
   * The watchdog_ops structure contains a list of low-level operations
   * that control a watchdog device. It also contains the module that owns
   * these operations. The start and stop function are mandatory, all other
80220fa72   Wolfram Sang   watchdog: include...
39
   * functions are optional.
43316044d   Wim Van Sebroeck   watchdog: WatchDo...
40
41
42
43
44
45
46
47
   */
  struct watchdog_ops {
  	struct module *owner;
  	/* mandatory operations */
  	int (*start)(struct watchdog_device *);
  	int (*stop)(struct watchdog_device *);
  	/* optional operations */
  	int (*ping)(struct watchdog_device *);
2fa03560a   Wim Van Sebroeck   watchdog: WatchDo...
48
  	unsigned int (*status)(struct watchdog_device *);
014d694e5   Wim Van Sebroeck   watchdog: WatchDo...
49
  	int (*set_timeout)(struct watchdog_device *, unsigned int);
df044e022   Wolfram Sang   watchdog: add pre...
50
  	int (*set_pretimeout)(struct watchdog_device *, unsigned int);
fd7b673c9   Viresh Kumar   watchdog: Add sup...
51
  	unsigned int (*get_timeleft)(struct watchdog_device *);
4d8b229d5   Guenter Roeck   watchdog: Add 'ac...
52
  	int (*restart)(struct watchdog_device *, unsigned long, void *);
78d88fc01   Wim Van Sebroeck   watchdog: WatchDo...
53
  	long (*ioctl)(struct watchdog_device *, unsigned int, unsigned long);
43316044d   Wim Van Sebroeck   watchdog: WatchDo...
54
55
56
57
  };
  
  /** struct watchdog_device - The structure that defines a watchdog device
   *
45f5fed30   Alan Cox   watchdog: Add mul...
58
   * @id:		The watchdog's ID. (Allocated by watchdog_register_device)
d6b469d91   Alan Cox   watchdog: create ...
59
   * @parent:	The parent bus device
faa584757   Guenter Roeck   watchdog: Add sup...
60
61
   * @groups:	List of sysfs attribute groups to create when creating the
   *		watchdog device.
43316044d   Wim Van Sebroeck   watchdog: WatchDo...
62
63
   * @info:	Pointer to a watchdog_info structure.
   * @ops:	Pointer to the list of watchdog operations.
ff84136cb   Vladimir Zapolskiy   watchdog: add wat...
64
   * @gov:	Pointer to watchdog pretimeout governor.
2fa03560a   Wim Van Sebroeck   watchdog: WatchDo...
65
   * @bootstatus:	Status of the watchdog device at boot.
760d28008   Wolfram Sang   watchdog: include...
66
   * @timeout:	The watchdog devices timeout value (in seconds).
df044e022   Wolfram Sang   watchdog: add pre...
67
   * @pretimeout: The watchdog devices pre_timeout value.
760d28008   Wolfram Sang   watchdog: include...
68
   * @min_timeout:The watchdog devices minimum timeout value (in seconds).
664a39236   Guenter Roeck   watchdog: Introdu...
69
70
71
   * @max_timeout:The watchdog devices maximum timeout value (in seconds)
   *		as configurable from user space. Only relevant if
   *		max_hw_heartbeat_ms is not provided.
15013ad81   Guenter Roeck   watchdog: Add sup...
72
   * @min_hw_heartbeat_ms:
f9f535c1b   Guenter Roeck   watchdog: Improve...
73
74
   *		Hardware limit for minimum time between heartbeats,
   *		in milli-seconds.
664a39236   Guenter Roeck   watchdog: Introdu...
75
76
77
   * @max_hw_heartbeat_ms:
   *		Hardware limit for maximum timeout, in milli-seconds.
   *		Replaces max_timeout if specified.
e13131966   Damien Riegel   watchdog: core: a...
78
   * @reboot_nb:	The notifier block to stop watchdog on reboot.
2165bf524   Damien Riegel   watchdog: core: a...
79
   * @restart_nb:	The notifier block to register a restart function.
b4ffb1909   Guenter Roeck   watchdog: Separat...
80
81
   * @driver_data:Pointer to the drivers private data.
   * @wd_data:	Pointer to watchdog core internal data.
43316044d   Wim Van Sebroeck   watchdog: WatchDo...
82
   * @status:	Field that contains the devices internal status bits.
664a39236   Guenter Roeck   watchdog: Introdu...
83
84
   * @deferred:	Entry in wtd_deferred_reg_list which is used to
   *		register early initialized watchdogs.
43316044d   Wim Van Sebroeck   watchdog: WatchDo...
85
86
87
88
89
90
   *
   * The watchdog_device structure contains all information about a
   * watchdog timer device.
   *
   * The driver-data field may not be accessed directly. It must be accessed
   * via the watchdog_set_drvdata and watchdog_get_drvdata helpers.
f4e9c82f6   Hans de Goede   watchdog: Add Loc...
91
92
93
   *
   * The lock field is for watchdog core internal use only and should not be
   * touched.
43316044d   Wim Van Sebroeck   watchdog: WatchDo...
94
95
   */
  struct watchdog_device {
45f5fed30   Alan Cox   watchdog: Add mul...
96
  	int id;
d6b469d91   Alan Cox   watchdog: create ...
97
  	struct device *parent;
faa584757   Guenter Roeck   watchdog: Add sup...
98
  	const struct attribute_group **groups;
43316044d   Wim Van Sebroeck   watchdog: WatchDo...
99
100
  	const struct watchdog_info *info;
  	const struct watchdog_ops *ops;
ff84136cb   Vladimir Zapolskiy   watchdog: add wat...
101
  	const struct watchdog_governor *gov;
2fa03560a   Wim Van Sebroeck   watchdog: WatchDo...
102
  	unsigned int bootstatus;
014d694e5   Wim Van Sebroeck   watchdog: WatchDo...
103
  	unsigned int timeout;
df044e022   Wolfram Sang   watchdog: add pre...
104
  	unsigned int pretimeout;
3f43f68e2   Wim Van Sebroeck   watchdog: WatchDo...
105
106
  	unsigned int min_timeout;
  	unsigned int max_timeout;
15013ad81   Guenter Roeck   watchdog: Add sup...
107
  	unsigned int min_hw_heartbeat_ms;
664a39236   Guenter Roeck   watchdog: Introdu...
108
  	unsigned int max_hw_heartbeat_ms;
e13131966   Damien Riegel   watchdog: core: a...
109
  	struct notifier_block reboot_nb;
2165bf524   Damien Riegel   watchdog: core: a...
110
  	struct notifier_block restart_nb;
43316044d   Wim Van Sebroeck   watchdog: WatchDo...
111
  	void *driver_data;
b4ffb1909   Guenter Roeck   watchdog: Separat...
112
  	struct watchdog_core_data *wd_data;
43316044d   Wim Van Sebroeck   watchdog: WatchDo...
113
114
  	unsigned long status;
  /* Bit numbers for status flags */
234445b4e   Wim Van Sebroeck   watchdog: WatchDo...
115
  #define WDOG_ACTIVE		0	/* Is the watchdog running/active */
b4ffb1909   Guenter Roeck   watchdog: Separat...
116
117
  #define WDOG_NO_WAY_OUT		1	/* Is 'nowayout' feature set ? */
  #define WDOG_STOP_ON_REBOOT	2	/* Should be stopped on reboot */
ee142889e   Guenter Roeck   watchdog: Introdu...
118
  #define WDOG_HW_RUNNING		3	/* True if HW watchdog running */
ef90174f8   Jean-Baptiste Theou   watchdog: watchdo...
119
  	struct list_head deferred;
43316044d   Wim Van Sebroeck   watchdog: WatchDo...
120
  };
4846e3784   Uwe Kleine-König   watchdog: simplif...
121
122
  #define WATCHDOG_NOWAYOUT		IS_BUILTIN(CONFIG_WATCHDOG_NOWAYOUT)
  #define WATCHDOG_NOWAYOUT_INIT_STATUS	(WATCHDOG_NOWAYOUT << WDOG_NO_WAY_OUT)
ff0b3cd4a   Wim Van Sebroeck   watchdog: add now...
123

48fc7f7e7   Adam Buchbinder   Fix misspellings ...
124
  /* Use the following function to check whether or not the watchdog is active */
257f8c4aa   Viresh Kumar   watchdog: Add wat...
125
126
127
128
  static inline bool watchdog_active(struct watchdog_device *wdd)
  {
  	return test_bit(WDOG_ACTIVE, &wdd->status);
  }
ee142889e   Guenter Roeck   watchdog: Introdu...
129
130
131
132
133
134
135
136
  /*
   * Use the following function to check whether or not the hardware watchdog
   * is running
   */
  static inline bool watchdog_hw_running(struct watchdog_device *wdd)
  {
  	return test_bit(WDOG_HW_RUNNING, &wdd->status);
  }
ff0b3cd4a   Wim Van Sebroeck   watchdog: add now...
137
  /* Use the following function to set the nowayout feature */
86a1e1896   Wim Van Sebroeck   watchdog: nowayou...
138
  static inline void watchdog_set_nowayout(struct watchdog_device *wdd, bool nowayout)
ff0b3cd4a   Wim Van Sebroeck   watchdog: add now...
139
140
141
142
  {
  	if (nowayout)
  		set_bit(WDOG_NO_WAY_OUT, &wdd->status);
  }
e13131966   Damien Riegel   watchdog: core: a...
143
144
145
146
147
  /* Use the following function to stop the watchdog on reboot */
  static inline void watchdog_stop_on_reboot(struct watchdog_device *wdd)
  {
  	set_bit(WDOG_STOP_ON_REBOOT, &wdd->status);
  }
3048253ed   Fabio Porcedda   watchdog: core: d...
148
149
150
  /* Use the following function to check if a timeout value is invalid */
  static inline bool watchdog_timeout_invalid(struct watchdog_device *wdd, unsigned int t)
  {
1e9359491   Guenter Roeck   watchdog: Always ...
151
152
  	/*
  	 * The timeout is invalid if
664a39236   Guenter Roeck   watchdog: Introdu...
153
154
155
  	 * - the requested value is larger than UINT_MAX / 1000
  	 *   (since internal calculations are done in milli-seconds),
  	 * or
1e9359491   Guenter Roeck   watchdog: Always ...
156
157
  	 * - the requested value is smaller than the configured minimum timeout,
  	 * or
664a39236   Guenter Roeck   watchdog: Introdu...
158
159
160
  	 * - a maximum hardware timeout is not configured, a maximum timeout
  	 *   is configured, and the requested value is larger than the
  	 *   configured maximum timeout.
1e9359491   Guenter Roeck   watchdog: Always ...
161
  	 */
664a39236   Guenter Roeck   watchdog: Introdu...
162
163
164
  	return t > UINT_MAX / 1000 || t < wdd->min_timeout ||
  		(!wdd->max_hw_heartbeat_ms && wdd->max_timeout &&
  		 t > wdd->max_timeout);
3048253ed   Fabio Porcedda   watchdog: core: d...
165
  }
df044e022   Wolfram Sang   watchdog: add pre...
166
167
168
169
170
171
  /* Use the following function to check if a pretimeout value is invalid */
  static inline bool watchdog_pretimeout_invalid(struct watchdog_device *wdd,
  					       unsigned int t)
  {
  	return t && wdd->timeout && t >= wdd->timeout;
  }
43316044d   Wim Van Sebroeck   watchdog: WatchDo...
172
173
174
175
176
177
178
179
180
181
  /* Use the following functions to manipulate watchdog driver specific data */
  static inline void watchdog_set_drvdata(struct watchdog_device *wdd, void *data)
  {
  	wdd->driver_data = data;
  }
  
  static inline void *watchdog_get_drvdata(struct watchdog_device *wdd)
  {
  	return wdd->driver_data;
  }
ff84136cb   Vladimir Zapolskiy   watchdog: add wat...
182
183
184
185
186
187
188
189
190
191
  /* Use the following functions to report watchdog pretimeout event */
  #if IS_ENABLED(CONFIG_WATCHDOG_PRETIMEOUT_GOV)
  void watchdog_notify_pretimeout(struct watchdog_device *wdd);
  #else
  static inline void watchdog_notify_pretimeout(struct watchdog_device *wdd)
  {
  	pr_alert("watchdog%d: pretimeout event
  ", wdd->id);
  }
  #endif
cf13a84d1   Fabio Porcedda   watchdog: WatchDo...
192
  /* drivers/watchdog/watchdog_core.c */
2165bf524   Damien Riegel   watchdog: core: a...
193
  void watchdog_set_restart_priority(struct watchdog_device *wdd, int priority);
3048253ed   Fabio Porcedda   watchdog: core: d...
194
195
  extern int watchdog_init_timeout(struct watchdog_device *wdd,
  				  unsigned int timeout_parm, struct device *dev);
43316044d   Wim Van Sebroeck   watchdog: WatchDo...
196
197
  extern int watchdog_register_device(struct watchdog_device *);
  extern void watchdog_unregister_device(struct watchdog_device *);
83fbae5a1   Neil Armstrong   watchdog: Add a d...
198
199
  /* devres register variant */
  int devm_watchdog_register_device(struct device *dev, struct watchdog_device *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
200
  #endif  /* ifndef _LINUX_WATCHDOG_H */