Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /*
0003  *  watchdog_core.h
0004  *
0005  *  (c) Copyright 2008-2011 Alan Cox <alan@lxorguk.ukuu.org.uk>,
0006  *                      All Rights Reserved.
0007  *
0008  *  (c) Copyright 2008-2011 Wim Van Sebroeck <wim@iguana.be>.
0009  *
0010  *  (c) Copyright 2021 Hewlett Packard Enterprise Development LP.
0011  *
0012  *  This source code is part of the generic code that can be used
0013  *  by all the watchdog timer drivers.
0014  *
0015  *  Based on source code of the following authors:
0016  *    Matt Domsch <Matt_Domsch@dell.com>,
0017  *    Rob Radez <rob@osinvestor.com>,
0018  *    Rusty Lynch <rusty@linux.co.intel.com>
0019  *    Satyam Sharma <satyam@infradead.org>
0020  *    Randy Dunlap <randy.dunlap@oracle.com>
0021  *
0022  *  Neither Alan Cox, CymruNet Ltd., Wim Van Sebroeck nor Iguana vzw.
0023  *  admit liability nor provide warranty for any of this software.
0024  *  This material is provided "AS-IS" and at no charge.
0025  */
0026 
0027 #include <linux/hrtimer.h>
0028 #include <linux/kthread.h>
0029 
0030 #define MAX_DOGS    32  /* Maximum number of watchdog devices */
0031 
0032 /*
0033  * struct watchdog_core_data - watchdog core internal data
0034  * @dev:    The watchdog's internal device
0035  * @cdev:   The watchdog's Character device.
0036  * @wdd:    Pointer to watchdog device.
0037  * @lock:   Lock for watchdog core.
0038  * @status: Watchdog core internal status bits.
0039  */
0040 struct watchdog_core_data {
0041     struct device dev;
0042     struct cdev cdev;
0043     struct watchdog_device *wdd;
0044     struct mutex lock;
0045     ktime_t last_keepalive;
0046     ktime_t last_hw_keepalive;
0047     ktime_t open_deadline;
0048     struct hrtimer timer;
0049     struct kthread_work work;
0050 #if IS_ENABLED(CONFIG_WATCHDOG_HRTIMER_PRETIMEOUT)
0051     struct hrtimer pretimeout_timer;
0052 #endif
0053     unsigned long status;       /* Internal status bits */
0054 #define _WDOG_DEV_OPEN      0   /* Opened ? */
0055 #define _WDOG_ALLOW_RELEASE 1   /* Did we receive the magic char ? */
0056 #define _WDOG_KEEPALIVE     2   /* Did we receive a keepalive ? */
0057 };
0058 
0059 /*
0060  *  Functions/procedures to be called by the core
0061  */
0062 extern int watchdog_dev_register(struct watchdog_device *);
0063 extern void watchdog_dev_unregister(struct watchdog_device *);
0064 extern int __init watchdog_dev_init(void);
0065 extern void __exit watchdog_dev_exit(void);
0066 
0067 static inline bool watchdog_have_pretimeout(struct watchdog_device *wdd)
0068 {
0069     return wdd->info->options & WDIOF_PRETIMEOUT ||
0070            IS_ENABLED(CONFIG_WATCHDOG_HRTIMER_PRETIMEOUT);
0071 }
0072 
0073 #if IS_ENABLED(CONFIG_WATCHDOG_HRTIMER_PRETIMEOUT)
0074 void watchdog_hrtimer_pretimeout_init(struct watchdog_device *wdd);
0075 void watchdog_hrtimer_pretimeout_start(struct watchdog_device *wdd);
0076 void watchdog_hrtimer_pretimeout_stop(struct watchdog_device *wdd);
0077 #else
0078 static inline void watchdog_hrtimer_pretimeout_init(struct watchdog_device *wdd) {}
0079 static inline void watchdog_hrtimer_pretimeout_start(struct watchdog_device *wdd) {}
0080 static inline void watchdog_hrtimer_pretimeout_stop(struct watchdog_device *wdd) {}
0081 #endif