diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchcat_core.c similarity index 56% rename from drivers/watchdog/watchdog_core.c rename to drivers/watchdog/watchcat_core.c index aff2c3912ead69..9f8922f54d8d4b 100644 --- a/drivers/watchdog/watchdog_core.c +++ b/drivers/watchdog/watchcat_core.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0+ /* - * watchdog_core.c + * watchcat_core.c * * (c) Copyright 2008-2011 Alan Cox , * All Rights Reserved. @@ -8,7 +8,7 @@ * (c) Copyright 2008-2011 Wim Van Sebroeck . * * This source code is part of the generic code that can be used - * by all the watchdog timer drivers. + * by all the watchcat timer drivers. * * Based on source code of the following authors: * Matt Domsch , @@ -29,54 +29,54 @@ #include /* For the -ENODEV/... values */ #include /* For printk/panic/... */ #include /* For restart handler */ -#include /* For watchdog specific items */ +#include /* For watchcat specific items */ #include /* For __init/__exit/... */ #include /* For ida_* macros */ #include /* For IS_ERR macros */ #include /* For of_get_timeout_sec */ #include -#include "watchdog_core.h" /* For watchdog_dev_register/... */ +#include "watchcat_core.h" /* For watchcat_dev_register/... */ #define CREATE_TRACE_POINTS -#include +#include -static DEFINE_IDA(watchdog_ida); +static DEFINE_IDA(watchcat_ida); static int stop_on_reboot = -1; module_param(stop_on_reboot, int, 0444); -MODULE_PARM_DESC(stop_on_reboot, "Stop watchdogs on reboot (0=keep watching, 1=stop)"); +MODULE_PARM_DESC(stop_on_reboot, "Stop watchcats on reboot (0=keep watching, 1=stop)"); /* * Deferred Registration infrastructure. * - * Sometimes watchdog drivers needs to be loaded as soon as possible, + * Sometimes watchcat drivers needs to be loaded as soon as possible, * for example when it's impossible to disable it. To do so, - * raising the initcall level of the watchdog driver is a solution. + * raising the initcall level of the watchcat driver is a solution. * But in such case, the miscdev is maybe not ready (subsys_initcall), and - * watchdog_core need miscdev to register the watchdog as a char device. + * watchcat_core need miscdev to register the watchcat as a char device. * - * The deferred registration infrastructure offer a way for the watchdog - * subsystem to register a watchdog properly, even before miscdev is ready. + * The deferred registration infrastructure offer a way for the watchcat + * subsystem to register a watchcat properly, even before miscdev is ready. */ static DEFINE_MUTEX(wtd_deferred_reg_mutex); static LIST_HEAD(wtd_deferred_reg_list); static bool wtd_deferred_reg_done; -static void watchdog_deferred_registration_add(struct watchdog_device *wdd) +static void watchcat_deferred_registration_add(struct watchcat_device *wdd) { list_add_tail(&wdd->deferred, &wtd_deferred_reg_list); } -static void watchdog_deferred_registration_del(struct watchdog_device *wdd) +static void watchcat_deferred_registration_del(struct watchcat_device *wdd) { struct list_head *p, *n; - struct watchdog_device *wdd_tmp; + struct watchcat_device *wdd_tmp; list_for_each_safe(p, n, &wtd_deferred_reg_list) { - wdd_tmp = list_entry(p, struct watchdog_device, + wdd_tmp = list_entry(p, struct watchcat_device, deferred); if (wdd_tmp == wdd) { list_del(&wdd_tmp->deferred); @@ -85,7 +85,7 @@ static void watchdog_deferred_registration_del(struct watchdog_device *wdd) } } -static void watchdog_check_min_max_timeout(struct watchdog_device *wdd) +static void watchcat_check_min_max_timeout(struct watchcat_device *wdd) { /* * Check that we have valid min and max timeout values, if @@ -99,12 +99,12 @@ static void watchdog_check_min_max_timeout(struct watchdog_device *wdd) } /** - * watchdog_init_timeout() - initialize the timeout field - * @wdd: watchdog device + * watchcat_init_timeout() - initialize the timeout field + * @wdd: watchcat device * @timeout_parm: timeout module parameter * @dev: Device that stores the timeout-sec property * - * Initialize the timeout field of the watchdog_device struct with either the + * Initialize the timeout field of the watchcat_device struct with either the * timeout module parameter (if it is valid value) or the timeout-sec property * (only if it is a valid value and the timeout_parm is out of bounds). * If none of them are valid then we keep the old value (which should normally @@ -115,7 +115,7 @@ static void watchdog_check_min_max_timeout(struct watchdog_device *wdd) * A zero is returned on success or -EINVAL if all provided values are out of * bounds. */ -int watchdog_init_timeout(struct watchdog_device *wdd, +int watchcat_init_timeout(struct watchcat_device *wdd, unsigned int timeout_parm, struct device *dev) { const char *dev_str = wdd->parent ? dev_name(wdd->parent) : @@ -123,11 +123,11 @@ int watchdog_init_timeout(struct watchdog_device *wdd, unsigned int t = 0; int ret = 0; - watchdog_check_min_max_timeout(wdd); + watchcat_check_min_max_timeout(wdd); /* check the driver supplied value (likely a module parameter) first */ if (timeout_parm) { - if (!watchdog_timeout_invalid(wdd, timeout_parm)) { + if (!watchcat_timeout_invalid(wdd, timeout_parm)) { wdd->timeout = timeout_parm; return 0; } @@ -139,7 +139,7 @@ int watchdog_init_timeout(struct watchdog_device *wdd, /* try to get the timeout_sec property */ if (dev && dev->of_node && of_property_read_u32(dev->of_node, "timeout-sec", &t) == 0) { - if (t && !watchdog_timeout_invalid(wdd, t)) { + if (t && !watchcat_timeout_invalid(wdd, t)) { wdd->timeout = t; return 0; } @@ -153,20 +153,20 @@ int watchdog_init_timeout(struct watchdog_device *wdd, return ret; } -EXPORT_SYMBOL_GPL(watchdog_init_timeout); +EXPORT_SYMBOL_GPL(watchcat_init_timeout); -static int watchdog_reboot_notifier(struct notifier_block *nb, +static int watchcat_reboot_notifier(struct notifier_block *nb, unsigned long code, void *data) { - struct watchdog_device *wdd; + struct watchcat_device *wdd; - wdd = container_of(nb, struct watchdog_device, reboot_nb); + wdd = container_of(nb, struct watchcat_device, reboot_nb); if (code == SYS_DOWN || code == SYS_HALT || code == SYS_POWER_OFF) { - if (watchdog_hw_running(wdd)) { + if (watchcat_hw_running(wdd)) { int ret; ret = wdd->ops->stop(wdd); - trace_watchdog_stop(wdd, ret); + trace_watchcat_stop(wdd, ret); if (ret) return NOTIFY_BAD; } @@ -175,10 +175,10 @@ static int watchdog_reboot_notifier(struct notifier_block *nb, return NOTIFY_DONE; } -static int watchdog_restart_notifier(struct notifier_block *nb, +static int watchcat_restart_notifier(struct notifier_block *nb, unsigned long action, void *data) { - struct watchdog_device *wdd = container_of(nb, struct watchdog_device, + struct watchcat_device *wdd = container_of(nb, struct watchcat_device, restart_nb); int ret; @@ -190,24 +190,24 @@ static int watchdog_restart_notifier(struct notifier_block *nb, return NOTIFY_DONE; } -static int watchdog_pm_notifier(struct notifier_block *nb, unsigned long mode, +static int watchcat_pm_notifier(struct notifier_block *nb, unsigned long mode, void *data) { - struct watchdog_device *wdd; + struct watchcat_device *wdd; int ret = 0; - wdd = container_of(nb, struct watchdog_device, pm_nb); + wdd = container_of(nb, struct watchcat_device, pm_nb); switch (mode) { case PM_HIBERNATION_PREPARE: case PM_RESTORE_PREPARE: case PM_SUSPEND_PREPARE: - ret = watchdog_dev_suspend(wdd); + ret = watchcat_dev_suspend(wdd); break; case PM_POST_HIBERNATION: case PM_POST_RESTORE: case PM_POST_SUSPEND: - ret = watchdog_dev_resume(wdd); + ret = watchcat_dev_resume(wdd); break; } @@ -218,26 +218,26 @@ static int watchdog_pm_notifier(struct notifier_block *nb, unsigned long mode, } /** - * watchdog_set_restart_priority - Change priority of restart handler - * @wdd: watchdog device + * watchcat_set_restart_priority - Change priority of restart handler + * @wdd: watchcat device * @priority: priority of the restart handler, should follow these guidelines: - * 0: use watchdog's restart function as last resort, has limited restart + * 0: use watchcat's restart function as last resort, has limited restart * capabilies * 128: default restart handler, use if no other handler is expected to be * available and/or if restart is sufficient to restart the entire system * 255: preempt all other handlers * - * If a wdd->ops->restart function is provided when watchdog_register_device is + * If a wdd->ops->restart function is provided when watchcat_register_device is * called, it will be registered as a restart handler with the priority given * here. */ -void watchdog_set_restart_priority(struct watchdog_device *wdd, int priority) +void watchcat_set_restart_priority(struct watchcat_device *wdd, int priority) { wdd->restart_nb.priority = priority; } -EXPORT_SYMBOL_GPL(watchdog_set_restart_priority); +EXPORT_SYMBOL_GPL(watchcat_set_restart_priority); -static int __watchdog_register_device(struct watchdog_device *wdd) +static int __watchcat_register_device(struct watchcat_device *wdd) { int ret, id = -1; @@ -248,89 +248,89 @@ static int __watchdog_register_device(struct watchdog_device *wdd) if (!wdd->ops->start || (!wdd->ops->stop && !wdd->max_hw_heartbeat_ms)) return -EINVAL; - watchdog_check_min_max_timeout(wdd); + watchcat_check_min_max_timeout(wdd); /* - * Note: now that all watchdog_device data has been verified, we + * Note: now that all watchcat_device data has been verified, we * will not check this anymore in other functions. If data gets * corrupted in a later stage then we expect a kernel panic! */ - /* Use alias for watchdog id if possible */ + /* Use alias for watchcat id if possible */ if (wdd->parent) { - ret = of_alias_get_id(wdd->parent->of_node, "watchdog"); + ret = of_alias_get_id(wdd->parent->of_node, "watchcat"); if (ret >= 0) - id = ida_alloc_range(&watchdog_ida, ret, ret, + id = ida_alloc_range(&watchcat_ida, ret, ret, GFP_KERNEL); } if (id < 0) - id = ida_alloc_max(&watchdog_ida, MAX_DOGS - 1, GFP_KERNEL); + id = ida_alloc_max(&watchcat_ida, MAX_catS - 1, GFP_KERNEL); if (id < 0) return id; wdd->id = id; - ret = watchdog_dev_register(wdd); + ret = watchcat_dev_register(wdd); if (ret) { - ida_free(&watchdog_ida, id); + ida_free(&watchcat_ida, id); if (!(id == 0 && ret == -EBUSY)) return ret; - /* Retry in case a legacy watchdog module exists */ - id = ida_alloc_range(&watchdog_ida, 1, MAX_DOGS - 1, + /* Retry in case a legacy watchcat module exists */ + id = ida_alloc_range(&watchcat_ida, 1, MAX_catS - 1, GFP_KERNEL); if (id < 0) return id; wdd->id = id; - ret = watchdog_dev_register(wdd); + ret = watchcat_dev_register(wdd); if (ret) { - ida_free(&watchdog_ida, id); + ida_free(&watchcat_ida, id); return ret; } } - /* Module parameter to force watchdog policy on reboot. */ + /* Module parameter to force watchcat policy on reboot. */ if (stop_on_reboot != -1) { if (stop_on_reboot) - set_bit(WDOG_STOP_ON_REBOOT, &wdd->status); + set_bit(Wcat_STOP_ON_REBOOT, &wdd->status); else - clear_bit(WDOG_STOP_ON_REBOOT, &wdd->status); + clear_bit(Wcat_STOP_ON_REBOOT, &wdd->status); } - if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) { + if (test_bit(Wcat_STOP_ON_REBOOT, &wdd->status)) { if (!wdd->ops->stop) - pr_warn("watchdog%d: stop_on_reboot not supported\n", wdd->id); + pr_warn("watchcat%d: stop_on_reboot not supported\n", wdd->id); else { - wdd->reboot_nb.notifier_call = watchdog_reboot_notifier; + wdd->reboot_nb.notifier_call = watchcat_reboot_notifier; ret = register_reboot_notifier(&wdd->reboot_nb); if (ret) { - pr_err("watchdog%d: Cannot register reboot notifier (%d)\n", + pr_err("watchcat%d: Cannot register reboot notifier (%d)\n", wdd->id, ret); - watchdog_dev_unregister(wdd); - ida_free(&watchdog_ida, id); + watchcat_dev_unregister(wdd); + ida_free(&watchcat_ida, id); return ret; } } } if (wdd->ops->restart) { - wdd->restart_nb.notifier_call = watchdog_restart_notifier; + wdd->restart_nb.notifier_call = watchcat_restart_notifier; ret = register_restart_handler(&wdd->restart_nb); if (ret) - pr_warn("watchdog%d: Cannot register restart handler (%d)\n", + pr_warn("watchcat%d: Cannot register restart handler (%d)\n", wdd->id, ret); } - if (test_bit(WDOG_NO_PING_ON_SUSPEND, &wdd->status)) { - wdd->pm_nb.notifier_call = watchdog_pm_notifier; + if (test_bit(Wcat_NO_PING_ON_SUSPEND, &wdd->status)) { + wdd->pm_nb.notifier_call = watchcat_pm_notifier; ret = register_pm_notifier(&wdd->pm_nb); if (ret) - pr_warn("watchdog%d: Cannot register pm handler (%d)\n", + pr_warn("watchcat%d: Cannot register pm handler (%d)\n", wdd->id, ret); } @@ -338,40 +338,40 @@ static int __watchdog_register_device(struct watchdog_device *wdd) } /** - * watchdog_register_device() - register a watchdog device - * @wdd: watchdog device + * watchcat_register_device() - register a watchcat device + * @wdd: watchcat device * - * Register a watchdog device with the kernel so that the - * watchdog timer can be accessed from userspace. + * Register a watchcat device with the kernel so that the + * watchcat timer can be accessed from userspace. * * A zero is returned on success and a negative errno code for * failure. */ -int watchdog_register_device(struct watchdog_device *wdd) +int watchcat_register_device(struct watchcat_device *wdd) { const char *dev_str; int ret = 0; mutex_lock(&wtd_deferred_reg_mutex); if (wtd_deferred_reg_done) - ret = __watchdog_register_device(wdd); + ret = __watchcat_register_device(wdd); else - watchdog_deferred_registration_add(wdd); + watchcat_deferred_registration_add(wdd); mutex_unlock(&wtd_deferred_reg_mutex); if (ret) { dev_str = wdd->parent ? dev_name(wdd->parent) : (const char *)wdd->info->identity; - pr_err("%s: failed to register watchdog device (err = %d)\n", + pr_err("%s: failed to register watchcat device (err = %d)\n", dev_str, ret); } return ret; } -EXPORT_SYMBOL_GPL(watchdog_register_device); +EXPORT_SYMBOL_GPL(watchcat_register_device); -static void __watchdog_unregister_device(struct watchdog_device *wdd) +static void __watchcat_unregister_device(struct watchcat_device *wdd) { if (wdd == NULL) return; @@ -379,59 +379,59 @@ static void __watchdog_unregister_device(struct watchdog_device *wdd) if (wdd->ops->restart) unregister_restart_handler(&wdd->restart_nb); - if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) + if (test_bit(Wcat_STOP_ON_REBOOT, &wdd->status)) unregister_reboot_notifier(&wdd->reboot_nb); - watchdog_dev_unregister(wdd); - ida_free(&watchdog_ida, wdd->id); + watchcat_dev_unregister(wdd); + ida_free(&watchcat_ida, wdd->id); } /** - * watchdog_unregister_device() - unregister a watchdog device - * @wdd: watchdog device to unregister + * watchcat_unregister_device() - unregister a watchcat device + * @wdd: watchcat device to unregister * - * Unregister a watchdog device that was previously successfully - * registered with watchdog_register_device(). + * Unregister a watchcat device that was previously successfully + * registered with watchcat_register_device(). */ -void watchdog_unregister_device(struct watchdog_device *wdd) +void watchcat_unregister_device(struct watchcat_device *wdd) { mutex_lock(&wtd_deferred_reg_mutex); if (wtd_deferred_reg_done) - __watchdog_unregister_device(wdd); + __watchcat_unregister_device(wdd); else - watchdog_deferred_registration_del(wdd); + watchcat_deferred_registration_del(wdd); mutex_unlock(&wtd_deferred_reg_mutex); } -EXPORT_SYMBOL_GPL(watchdog_unregister_device); +EXPORT_SYMBOL_GPL(watchcat_unregister_device); -static void devm_watchdog_unregister_device(struct device *dev, void *res) +static void devm_watchcat_unregister_device(struct device *dev, void *res) { - watchdog_unregister_device(*(struct watchdog_device **)res); + watchcat_unregister_device(*(struct watchcat_device **)res); } /** - * devm_watchdog_register_device() - resource managed watchdog_register_device() - * @dev: device that is registering this watchdog device - * @wdd: watchdog device + * devm_watchcat_register_device() - resource managed watchcat_register_device() + * @dev: device that is registering this watchcat device + * @wdd: watchcat device * - * Managed watchdog_register_device(). For watchdog device registered by this - * function, watchdog_unregister_device() is automatically called on driver - * detach. See watchdog_register_device() for more information. + * Managed watchcat_register_device(). For watchcat device registered by this + * function, watchcat_unregister_device() is automatically called on driver + * detach. See watchcat_register_device() for more information. */ -int devm_watchdog_register_device(struct device *dev, - struct watchdog_device *wdd) +int devm_watchcat_register_device(struct device *dev, + struct watchcat_device *wdd) { - struct watchdog_device **rcwdd; + struct watchcat_device **rcwdd; int ret; - rcwdd = devres_alloc(devm_watchdog_unregister_device, sizeof(*rcwdd), + rcwdd = devres_alloc(devm_watchcat_unregister_device, sizeof(*rcwdd), GFP_KERNEL); if (!rcwdd) return -ENOMEM; - ret = watchdog_register_device(wdd); + ret = watchcat_register_device(wdd); if (!ret) { *rcwdd = wdd; devres_add(dev, rcwdd); @@ -441,46 +441,46 @@ int devm_watchdog_register_device(struct device *dev, return ret; } -EXPORT_SYMBOL_GPL(devm_watchdog_register_device); +EXPORT_SYMBOL_GPL(devm_watchcat_register_device); -static int __init watchdog_deferred_registration(void) +static int __init watchcat_deferred_registration(void) { mutex_lock(&wtd_deferred_reg_mutex); wtd_deferred_reg_done = true; while (!list_empty(&wtd_deferred_reg_list)) { - struct watchdog_device *wdd; + struct watchcat_device *wdd; wdd = list_first_entry(&wtd_deferred_reg_list, - struct watchdog_device, deferred); + struct watchcat_device, deferred); list_del(&wdd->deferred); - __watchdog_register_device(wdd); + __watchcat_register_device(wdd); } mutex_unlock(&wtd_deferred_reg_mutex); return 0; } -static int __init watchdog_init(void) +static int __init watchcat_init(void) { int err; - err = watchdog_dev_init(); + err = watchcat_dev_init(); if (err < 0) return err; - watchdog_deferred_registration(); + watchcat_deferred_registration(); return 0; } -static void __exit watchdog_exit(void) +static void __exit watchcat_exit(void) { - watchdog_dev_exit(); - ida_destroy(&watchdog_ida); + watchcat_dev_exit(); + ida_destroy(&watchcat_ida); } -subsys_initcall_sync(watchdog_init); -module_exit(watchdog_exit); +subsys_initcall_sync(watchcat_init); +module_exit(watchcat_exit); MODULE_AUTHOR("Alan Cox "); MODULE_AUTHOR("Wim Van Sebroeck "); -MODULE_DESCRIPTION("WatchDog Timer Driver Core"); +MODULE_DESCRIPTION("Watchcat Timer Driver Core"); MODULE_LICENSE("GPL"); diff --git a/drivers/watchdog/watchcat_core.h b/drivers/watchdog/watchcat_core.h new file mode 100644 index 00000000000000..4eae538ce8574f --- /dev/null +++ b/drivers/watchdog/watchcat_core.h @@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * watchcat_core.h + * + * (c) Copyright 2008-2011 Alan Cox , + * All Rights Reserved. + * + * (c) Copyright 2008-2011 Wim Van Sebroeck . + * + * (c) Copyright 2021 Hewlett Packard Enterprise Development LP. + * + * This source code is part of the generic code that can be used + * by all the watchcat timer drivers. + * + * Based on source code of the following authors: + * Matt Domsch , + * Rob Radez , + * Rusty Lynch + * Satyam Sharma + * Randy Dunlap + * + * Neither Alan Cox, CymruNet Ltd., Wim Van Sebroeck nor Iguana vzw. + * admit liability nor provide warranty for any of this software. + * This material is provided "AS-IS" and at no charge. + */ + +#include +#include + +#define MAX_catS 32 /* Maximum number of watchcat devices */ + +/* + * struct watchcat_core_data - watchcat core internal data + * @dev: The watchcat's internal device + * @cdev: The watchcat's Character device. + * @wdd: Pointer to watchcat device. + * @lock: Lock for watchcat core. + * @status: Watchcat core internal status bits. + */ +struct watchcat_core_data { + struct device dev; + struct cdev cdev; + struct watchcat_device *wdd; + struct mutex lock; + ktime_t last_keepalive; + ktime_t last_hw_keepalive; + ktime_t open_deadline; + struct hrtimer timer; + struct kthread_work work; +#if IS_ENABLED(CONFIG_WATCHcat_HRTIMER_PRETIMEOUT) + struct hrtimer pretimeout_timer; +#endif + unsigned long status; /* Internal status bits */ +#define _Wcat_DEV_OPEN 0 /* Opened ? */ +#define _Wcat_ALLOW_RELEASE 1 /* Did we receive the magic char ? */ +#define _Wcat_KEEPALIVE 2 /* Did we receive a keepalive ? */ +}; + +/* + * Functions/procedures to be called by the core + */ +extern int watchcat_dev_register(struct watchcat_device *); +extern void watchcat_dev_unregister(struct watchcat_device *); +extern int __init watchcat_dev_init(void); +extern void __exit watchcat_dev_exit(void); + +static inline bool watchcat_have_pretimeout(struct watchcat_device *wdd) +{ + return wdd->info->options & WDIOF_PRETIMEOUT || + IS_ENABLED(CONFIG_WATCHcat_HRTIMER_PRETIMEOUT); +} + +#if IS_ENABLED(CONFIG_WATCHcat_HRTIMER_PRETIMEOUT) +void watchcat_hrtimer_pretimeout_init(struct watchcat_device *wdd); +void watchcat_hrtimer_pretimeout_start(struct watchcat_device *wdd); +void watchcat_hrtimer_pretimeout_stop(struct watchcat_device *wdd); +#else +static inline void watchcat_hrtimer_pretimeout_init(struct watchcat_device *wdd) {} +static inline void watchcat_hrtimer_pretimeout_start(struct watchcat_device *wdd) {} +static inline void watchcat_hrtimer_pretimeout_stop(struct watchcat_device *wdd) {} +#endif diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchcat_dev.c similarity index 57% rename from drivers/watchdog/watchdog_dev.c rename to drivers/watchdog/watchcat_dev.c index e2bd266b1b5b3d..d568018da764ee 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchcat_dev.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0+ /* - * watchdog_dev.c + * watchcat_dev.c * * (c) Copyright 2008-2011 Alan Cox , * All Rights Reserved. @@ -10,10 +10,10 @@ * (c) Copyright 2021 Hewlett Packard Enterprise Development LP. * * This source code is part of the generic code that can be used - * by all the watchdog timer drivers. + * by all the watchcat timer drivers. * * This part of the generic code takes care of the following - * misc device: /dev/watchdog. + * misc device: /dev/watchcat. * * Based on source code of the following authors: * Matt Domsch , @@ -42,38 +42,38 @@ #include /* For mutexes */ #include /* For memory functions */ #include /* For standard types (like size_t) */ -#include /* For watchdog specific items */ +#include /* For watchcat specific items */ #include /* For copy_to_user/put_user/... */ -#include "watchdog_core.h" -#include "watchdog_pretimeout.h" +#include "watchcat_core.h" +#include "watchcat_pretimeout.h" -#include +#include -/* the dev_t structure to store the dynamically allocated watchdog devices */ -static dev_t watchdog_devt; -/* Reference to watchdog device behind /dev/watchdog */ -static struct watchdog_core_data *old_wd_data; +/* the dev_t structure to store the dynamically allocated watchcat devices */ +static dev_t watchcat_devt; +/* Reference to watchcat device behind /dev/watchcat */ +static struct watchcat_core_data *old_wd_data; -static struct kthread_worker *watchdog_kworker; +static struct kthread_worker *watchcat_kworker; static bool handle_boot_enabled = - IS_ENABLED(CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED); + IS_ENABLED(CONFIG_watchcat_HANDLE_BOOT_ENABLED); -static unsigned open_timeout = CONFIG_WATCHDOG_OPEN_TIMEOUT; +static unsigned open_timeout = CONFIG_watchcat_OPEN_TIMEOUT; -static bool watchdog_past_open_deadline(struct watchdog_core_data *data) +static bool watchcat_past_open_deadline(struct watchcat_core_data *data) { return ktime_after(ktime_get(), data->open_deadline); } -static void watchdog_set_open_deadline(struct watchdog_core_data *data) +static void watchcat_set_open_deadline(struct watchcat_core_data *data) { data->open_deadline = open_timeout ? ktime_get() + ktime_set(open_timeout, 0) : KTIME_MAX; } -static inline bool watchdog_need_worker(struct watchdog_device *wdd) +static inline bool watchcat_need_worker(struct watchcat_device *wdd) { /* All variables in milli-seconds */ unsigned int hm = wdd->max_hw_heartbeat_ms; @@ -82,30 +82,30 @@ static inline bool watchdog_need_worker(struct watchdog_device *wdd) /* * A worker to generate heartbeat requests is needed if all of the * following conditions are true. - * - Userspace activated the watchdog. + * - Userspace activated the watchcat. * - The driver provided a value for the maximum hardware timeout, and * thus is aware that the framework supports generating heartbeat * requests. * - Userspace requests a longer timeout than the hardware can handle. * - * Alternatively, if userspace has not opened the watchdog - * device, we take care of feeding the watchdog if it is + * Alternatively, if userspace has not opened the watchcat + * device, we take care of feeding the watchcat if it is * running. */ - return (hm && watchdog_active(wdd) && t > hm) || - (t && !watchdog_active(wdd) && watchdog_hw_running(wdd)); + return (hm && watchcat_active(wdd) && t > hm) || + (t && !watchcat_active(wdd) && watchcat_hw_running(wdd)); } -static ktime_t watchdog_next_keepalive(struct watchdog_device *wdd) +static ktime_t watchcat_next_keepalive(struct watchcat_device *wdd) { - struct watchdog_core_data *wd_data = wdd->wd_data; + struct watchcat_core_data *wd_data = wdd->wd_data; unsigned int timeout_ms = wdd->timeout * 1000; ktime_t keepalive_interval; ktime_t last_heartbeat, latest_heartbeat; ktime_t virt_timeout; unsigned int hw_heartbeat_ms; - if (watchdog_active(wdd)) + if (watchcat_active(wdd)) virt_timeout = ktime_add(wd_data->last_keepalive, ms_to_ktime(timeout_ms)); else @@ -115,7 +115,7 @@ static ktime_t watchdog_next_keepalive(struct watchdog_device *wdd) keepalive_interval = ms_to_ktime(hw_heartbeat_ms / 2); /* - * To ensure that the watchdog times out wdd->timeout seconds + * To ensure that the watchcat times out wdd->timeout seconds * after the most recent ping from userspace, the last * worker ping has to come in hw_heartbeat_ms before this timeout. */ @@ -126,12 +126,12 @@ static ktime_t watchdog_next_keepalive(struct watchdog_device *wdd) return keepalive_interval; } -static inline void watchdog_update_worker(struct watchdog_device *wdd) +static inline void watchcat_update_worker(struct watchcat_device *wdd) { - struct watchdog_core_data *wd_data = wdd->wd_data; + struct watchcat_core_data *wd_data = wdd->wd_data; - if (watchdog_need_worker(wdd)) { - ktime_t t = watchdog_next_keepalive(wdd); + if (watchcat_need_worker(wdd)) { + ktime_t t = watchcat_next_keepalive(wdd); if (t > 0) hrtimer_start(&wd_data->timer, t, @@ -141,9 +141,9 @@ static inline void watchdog_update_worker(struct watchdog_device *wdd) } } -static int __watchdog_ping(struct watchdog_device *wdd) +static int __watchcat_ping(struct watchcat_device *wdd) { - struct watchdog_core_data *wd_data = wdd->wd_data; + struct watchcat_core_data *wd_data = wdd->wd_data; ktime_t earliest_keepalive, now; int err; @@ -161,118 +161,118 @@ static int __watchdog_ping(struct watchdog_device *wdd) wd_data->last_hw_keepalive = now; if (wdd->ops->ping) { - err = wdd->ops->ping(wdd); /* ping the watchdog */ - trace_watchdog_ping(wdd, err); + err = wdd->ops->ping(wdd); /* ping the watchcat */ + trace_watchcat_ping(wdd, err); } else { - err = wdd->ops->start(wdd); /* restart watchdog */ - trace_watchdog_start(wdd, err); + err = wdd->ops->start(wdd); /* restart watchcat */ + trace_watchcat_start(wdd, err); } if (err == 0) - watchdog_hrtimer_pretimeout_start(wdd); + watchcat_hrtimer_pretimeout_start(wdd); - watchdog_update_worker(wdd); + watchcat_update_worker(wdd); return err; } /* - * watchdog_ping - ping the watchdog - * @wdd: The watchdog device to ping + * watchcat_ping - ping the watchcat + * @wdd: The watchcat device to ping * - * If the watchdog has no own ping operation then it needs to be + * If the watchcat has no own ping operation then it needs to be * restarted via the start operation. This wrapper function does * exactly that. - * We only ping when the watchdog device is running. + * We only ping when the watchcat device is running. * The caller must hold wd_data->lock. * * Return: 0 on success, error otherwise. */ -static int watchdog_ping(struct watchdog_device *wdd) +static int watchcat_ping(struct watchcat_device *wdd) { - struct watchdog_core_data *wd_data = wdd->wd_data; + struct watchcat_core_data *wd_data = wdd->wd_data; - if (!watchdog_hw_running(wdd)) + if (!watchcat_hw_running(wdd)) return 0; set_bit(_WDOG_KEEPALIVE, &wd_data->status); wd_data->last_keepalive = ktime_get(); - return __watchdog_ping(wdd); + return __watchcat_ping(wdd); } -static bool watchdog_worker_should_ping(struct watchdog_core_data *wd_data) +static bool watchcat_worker_should_ping(struct watchcat_core_data *wd_data) { - struct watchdog_device *wdd = wd_data->wdd; + struct watchcat_device *wdd = wd_data->wdd; if (!wdd) return false; - if (watchdog_active(wdd)) + if (watchcat_active(wdd)) return true; - return watchdog_hw_running(wdd) && !watchdog_past_open_deadline(wd_data); + return watchcat_hw_running(wdd) && !watchcat_past_open_deadline(wd_data); } -static void watchdog_ping_work(struct kthread_work *work) +static void watchcat_ping_work(struct kthread_work *work) { - struct watchdog_core_data *wd_data; + struct watchcat_core_data *wd_data; - wd_data = container_of(work, struct watchdog_core_data, work); + wd_data = container_of(work, struct watchcat_core_data, work); mutex_lock(&wd_data->lock); - if (watchdog_worker_should_ping(wd_data)) - __watchdog_ping(wd_data->wdd); + if (watchcat_worker_should_ping(wd_data)) + __watchcat_ping(wd_data->wdd); mutex_unlock(&wd_data->lock); } -static enum hrtimer_restart watchdog_timer_expired(struct hrtimer *timer) +static enum hrtimer_restart watchcat_timer_expired(struct hrtimer *timer) { - struct watchdog_core_data *wd_data; + struct watchcat_core_data *wd_data; - wd_data = container_of(timer, struct watchdog_core_data, timer); + wd_data = container_of(timer, struct watchcat_core_data, timer); - kthread_queue_work(watchdog_kworker, &wd_data->work); + kthread_queue_work(watchcat_kworker, &wd_data->work); return HRTIMER_NORESTART; } /* - * watchdog_start - wrapper to start the watchdog - * @wdd: The watchdog device to start + * watchcat_start - wrapper to start the watchcat + * @wdd: The watchcat device to start * - * Start the watchdog if it is not active and mark it active. + * Start the watchcat if it is not active and mark it active. * The caller must hold wd_data->lock. * * Return: 0 on success or a negative errno code for failure. */ -static int watchdog_start(struct watchdog_device *wdd) +static int watchcat_start(struct watchcat_device *wdd) { - struct watchdog_core_data *wd_data = wdd->wd_data; + struct watchcat_core_data *wd_data = wdd->wd_data; ktime_t started_at; int err; - if (watchdog_active(wdd)) + if (watchcat_active(wdd)) return 0; set_bit(_WDOG_KEEPALIVE, &wd_data->status); started_at = ktime_get(); - if (watchdog_hw_running(wdd) && wdd->ops->ping) { - err = __watchdog_ping(wdd); + if (watchcat_hw_running(wdd) && wdd->ops->ping) { + err = __watchcat_ping(wdd); if (err == 0) { set_bit(WDOG_ACTIVE, &wdd->status); - watchdog_hrtimer_pretimeout_start(wdd); + watchcat_hrtimer_pretimeout_start(wdd); } } else { err = wdd->ops->start(wdd); - trace_watchdog_start(wdd, err); + trace_watchcat_start(wdd, err); if (err == 0) { set_bit(WDOG_ACTIVE, &wdd->status); set_bit(WDOG_HW_RUNNING, &wdd->status); wd_data->last_keepalive = started_at; wd_data->last_hw_keepalive = started_at; - watchdog_update_worker(wdd); - watchdog_hrtimer_pretimeout_start(wdd); + watchcat_update_worker(wdd); + watchcat_hrtimer_pretimeout_start(wdd); } } @@ -280,24 +280,24 @@ static int watchdog_start(struct watchdog_device *wdd) } /* - * watchdog_stop - wrapper to stop the watchdog - * @wdd: The watchdog device to stop + * watchcat_stop - wrapper to stop the watchcat + * @wdd: The watchcat device to stop * - * Stop the watchdog if it is still active and unmark it active. - * If the 'nowayout' feature was set, the watchdog cannot be stopped. + * Stop the watchcat if it is still active and unmark it active. + * If the 'nowayout' feature was set, the watchcat cannot be stopped. * The caller must hold wd_data->lock. * * Return: 0 on success or a negative errno code for failure. */ -static int watchdog_stop(struct watchdog_device *wdd) +static int watchcat_stop(struct watchcat_device *wdd) { int err = 0; - if (!watchdog_active(wdd)) + if (!watchcat_active(wdd)) return 0; if (test_bit(WDOG_NO_WAY_OUT, &wdd->status)) { - pr_info("watchdog%d: nowayout prevents watchdog being stopped!\n", + pr_info("watchcat%d: nowayout prevents watchcat being stopped!\n", wdd->id); return -EBUSY; } @@ -305,32 +305,32 @@ static int watchdog_stop(struct watchdog_device *wdd) if (wdd->ops->stop) { clear_bit(WDOG_HW_RUNNING, &wdd->status); err = wdd->ops->stop(wdd); - trace_watchdog_stop(wdd, err); + trace_watchcat_stop(wdd, err); } else { set_bit(WDOG_HW_RUNNING, &wdd->status); } if (err == 0) { clear_bit(WDOG_ACTIVE, &wdd->status); - watchdog_update_worker(wdd); - watchdog_hrtimer_pretimeout_stop(wdd); + watchcat_update_worker(wdd); + watchcat_hrtimer_pretimeout_stop(wdd); } return err; } /* - * watchdog_get_status - wrapper to get the watchdog status - * @wdd: The watchdog device to get the status from + * watchcat_get_status - wrapper to get the watchcat status + * @wdd: The watchcat device to get the status from * - * Get the watchdog's status flags. + * Get the watchcat's status flags. * The caller must hold wd_data->lock. * - * Return: watchdog's status flags. + * Return: watchcat's status flags. */ -static unsigned int watchdog_get_status(struct watchdog_device *wdd) +static unsigned int watchcat_get_status(struct watchcat_device *wdd) { - struct watchdog_core_data *wd_data = wdd->wd_data; + struct watchcat_core_data *wd_data = wdd->wd_data; unsigned int status; if (wdd->ops->status) @@ -350,22 +350,22 @@ static unsigned int watchdog_get_status(struct watchdog_device *wdd) if (test_and_clear_bit(_WDOG_KEEPALIVE, &wd_data->status)) status |= WDIOF_KEEPALIVEPING; - if (IS_ENABLED(CONFIG_WATCHDOG_HRTIMER_PRETIMEOUT)) + if (IS_ENABLED(CONFIG_watchcat_HRTIMER_PRETIMEOUT)) status |= WDIOF_PRETIMEOUT; return status; } /* - * watchdog_set_timeout - set the watchdog timer timeout - * @wdd: The watchdog device to set the timeout for + * watchcat_set_timeout - set the watchcat timer timeout + * @wdd: The watchcat device to set the timeout for * @timeout: Timeout to set in seconds * * The caller must hold wd_data->lock. * * Return: 0 if successful, error otherwise. */ -static int watchdog_set_timeout(struct watchdog_device *wdd, +static int watchcat_set_timeout(struct watchcat_device *wdd, unsigned int timeout) { int err = 0; @@ -373,12 +373,12 @@ static int watchdog_set_timeout(struct watchdog_device *wdd, if (!(wdd->info->options & WDIOF_SETTIMEOUT)) return -EOPNOTSUPP; - if (watchdog_timeout_invalid(wdd, timeout)) + if (watchcat_timeout_invalid(wdd, timeout)) return -EINVAL; if (wdd->ops->set_timeout) { err = wdd->ops->set_timeout(wdd, timeout); - trace_watchdog_set_timeout(wdd, timeout, err); + trace_watchcat_set_timeout(wdd, timeout, err); } else { wdd->timeout = timeout; /* Disable pretimeout if it doesn't fit the new timeout */ @@ -386,27 +386,27 @@ static int watchdog_set_timeout(struct watchdog_device *wdd, wdd->pretimeout = 0; } - watchdog_update_worker(wdd); + watchcat_update_worker(wdd); return err; } /* - * watchdog_set_pretimeout - set the watchdog timer pretimeout - * @wdd: The watchdog device to set the timeout for + * watchcat_set_pretimeout - set the watchcat timer pretimeout + * @wdd: The watchcat device to set the timeout for * @timeout: pretimeout to set in seconds * * Return: 0 if successful, error otherwise. */ -static int watchdog_set_pretimeout(struct watchdog_device *wdd, +static int watchcat_set_pretimeout(struct watchcat_device *wdd, unsigned int timeout) { int err = 0; - if (!watchdog_have_pretimeout(wdd)) + if (!watchcat_have_pretimeout(wdd)) return -EOPNOTSUPP; - if (watchdog_pretimeout_invalid(wdd, timeout)) + if (watchcat_pretimeout_invalid(wdd, timeout)) return -EINVAL; if (wdd->ops->set_pretimeout && (wdd->info->options & WDIOF_PRETIMEOUT)) @@ -418,16 +418,16 @@ static int watchdog_set_pretimeout(struct watchdog_device *wdd, } /* - * watchdog_get_timeleft - wrapper to get the time left before a reboot - * @wdd: The watchdog device to get the remaining time from + * watchcat_get_timeleft - wrapper to get the time left before a reboot + * @wdd: The watchcat device to get the remaining time from * @timeleft: The time that's left * - * Get the time before a watchdog will reboot (if not pinged). + * Get the time before a watchcat will reboot (if not pinged). * The caller must hold wd_data->lock. * * Return: 0 if successful, error otherwise. */ -static int watchdog_get_timeleft(struct watchdog_device *wdd, +static int watchcat_get_timeleft(struct watchcat_device *wdd, unsigned int *timeleft) { *timeleft = 0; @@ -440,11 +440,11 @@ static int watchdog_get_timeleft(struct watchdog_device *wdd, return 0; } -#ifdef CONFIG_WATCHDOG_SYSFS +#ifdef CONFIG_watchcat_SYSFS static ssize_t nowayout_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct watchdog_device *wdd = dev_get_drvdata(dev); + struct watchcat_device *wdd = dev_get_drvdata(dev); return sysfs_emit(buf, "%d\n", !!test_bit(WDOG_NO_WAY_OUT, &wdd->status)); @@ -453,7 +453,7 @@ static ssize_t nowayout_show(struct device *dev, struct device_attribute *attr, static ssize_t nowayout_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { - struct watchdog_device *wdd = dev_get_drvdata(dev); + struct watchcat_device *wdd = dev_get_drvdata(dev); unsigned int value; int ret; @@ -465,7 +465,7 @@ static ssize_t nowayout_store(struct device *dev, struct device_attribute *attr, /* nowayout cannot be disabled once set */ if (test_bit(WDOG_NO_WAY_OUT, &wdd->status) && !value) return -EPERM; - watchdog_set_nowayout(wdd, value); + watchcat_set_nowayout(wdd, value); return len; } static DEVICE_ATTR_RW(nowayout); @@ -473,12 +473,12 @@ static DEVICE_ATTR_RW(nowayout); static ssize_t status_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct watchdog_device *wdd = dev_get_drvdata(dev); - struct watchdog_core_data *wd_data = wdd->wd_data; + struct watchcat_device *wdd = dev_get_drvdata(dev); + struct watchcat_core_data *wd_data = wdd->wd_data; unsigned int status; mutex_lock(&wd_data->lock); - status = watchdog_get_status(wdd); + status = watchcat_get_status(wdd); mutex_unlock(&wd_data->lock); return sysfs_emit(buf, "0x%x\n", status); @@ -488,7 +488,7 @@ static DEVICE_ATTR_RO(status); static ssize_t bootstatus_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct watchdog_device *wdd = dev_get_drvdata(dev); + struct watchcat_device *wdd = dev_get_drvdata(dev); return sysfs_emit(buf, "%u\n", wdd->bootstatus); } @@ -497,13 +497,13 @@ static DEVICE_ATTR_RO(bootstatus); static ssize_t timeleft_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct watchdog_device *wdd = dev_get_drvdata(dev); - struct watchdog_core_data *wd_data = wdd->wd_data; + struct watchcat_device *wdd = dev_get_drvdata(dev); + struct watchcat_core_data *wd_data = wdd->wd_data; ssize_t status; unsigned int val; mutex_lock(&wd_data->lock); - status = watchdog_get_timeleft(wdd, &val); + status = watchcat_get_timeleft(wdd, &val); mutex_unlock(&wd_data->lock); if (!status) status = sysfs_emit(buf, "%u\n", val); @@ -515,7 +515,7 @@ static DEVICE_ATTR_RO(timeleft); static ssize_t timeout_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct watchdog_device *wdd = dev_get_drvdata(dev); + struct watchcat_device *wdd = dev_get_drvdata(dev); return sysfs_emit(buf, "%u\n", wdd->timeout); } @@ -524,7 +524,7 @@ static DEVICE_ATTR_RO(timeout); static ssize_t min_timeout_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct watchdog_device *wdd = dev_get_drvdata(dev); + struct watchcat_device *wdd = dev_get_drvdata(dev); return sysfs_emit(buf, "%u\n", wdd->min_timeout); } @@ -533,7 +533,7 @@ static DEVICE_ATTR_RO(min_timeout); static ssize_t max_timeout_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct watchdog_device *wdd = dev_get_drvdata(dev); + struct watchcat_device *wdd = dev_get_drvdata(dev); return sysfs_emit(buf, "%u\n", wdd->max_timeout); } @@ -542,7 +542,7 @@ static DEVICE_ATTR_RO(max_timeout); static ssize_t pretimeout_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct watchdog_device *wdd = dev_get_drvdata(dev); + struct watchcat_device *wdd = dev_get_drvdata(dev); return sysfs_emit(buf, "%u\n", wdd->pretimeout); } @@ -551,7 +551,7 @@ static DEVICE_ATTR_RO(pretimeout); static ssize_t options_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct watchdog_device *wdd = dev_get_drvdata(dev); + struct watchcat_device *wdd = dev_get_drvdata(dev); return sysfs_emit(buf, "0x%x\n", wdd->info->options); } @@ -560,7 +560,7 @@ static DEVICE_ATTR_RO(options); static ssize_t fw_version_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct watchdog_device *wdd = dev_get_drvdata(dev); + struct watchcat_device *wdd = dev_get_drvdata(dev); return sysfs_emit(buf, "%d\n", wdd->info->firmware_version); } @@ -569,7 +569,7 @@ static DEVICE_ATTR_RO(fw_version); static ssize_t identity_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct watchdog_device *wdd = dev_get_drvdata(dev); + struct watchcat_device *wdd = dev_get_drvdata(dev); return sysfs_emit(buf, "%s\n", wdd->info->identity); } @@ -578,9 +578,9 @@ static DEVICE_ATTR_RO(identity); static ssize_t state_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct watchdog_device *wdd = dev_get_drvdata(dev); + struct watchcat_device *wdd = dev_get_drvdata(dev); - if (watchdog_active(wdd)) + if (watchcat_active(wdd)) return sysfs_emit(buf, "active\n"); return sysfs_emit(buf, "inactive\n"); @@ -590,7 +590,7 @@ static DEVICE_ATTR_RO(state); static ssize_t pretimeout_available_governors_show(struct device *dev, struct device_attribute *attr, char *buf) { - return watchdog_pretimeout_available_governors_get(buf); + return watchcat_pretimeout_available_governors_get(buf); } static DEVICE_ATTR_RO(pretimeout_available_governors); @@ -598,17 +598,17 @@ static ssize_t pretimeout_governor_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct watchdog_device *wdd = dev_get_drvdata(dev); + struct watchcat_device *wdd = dev_get_drvdata(dev); - return watchdog_pretimeout_governor_get(wdd, buf); + return watchcat_pretimeout_governor_get(wdd, buf); } static ssize_t pretimeout_governor_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct watchdog_device *wdd = dev_get_drvdata(dev); - int ret = watchdog_pretimeout_governor_set(wdd, buf); + struct watchcat_device *wdd = dev_get_drvdata(dev); + int ret = watchcat_pretimeout_governor_set(wdd, buf); if (!ret) ret = count; @@ -621,16 +621,16 @@ static umode_t wdt_is_visible(struct kobject *kobj, struct attribute *attr, int n) { struct device *dev = kobj_to_dev(kobj); - struct watchdog_device *wdd = dev_get_drvdata(dev); + struct watchcat_device *wdd = dev_get_drvdata(dev); umode_t mode = attr->mode; if (attr == &dev_attr_timeleft.attr && !wdd->ops->get_timeleft) mode = 0; - else if (attr == &dev_attr_pretimeout.attr && !watchdog_have_pretimeout(wdd)) + else if (attr == &dev_attr_pretimeout.attr && !watchcat_have_pretimeout(wdd)) mode = 0; else if ((attr == &dev_attr_pretimeout_governor.attr || attr == &dev_attr_pretimeout_available_governors.attr) && - (!watchdog_have_pretimeout(wdd) || !IS_ENABLED(CONFIG_WATCHDOG_PRETIMEOUT_GOV))) + (!watchcat_have_pretimeout(wdd) || !IS_ENABLED(CONFIG_watchcat_PRETIMEOUT_GOV))) mode = 0; return mode; @@ -663,16 +663,16 @@ __ATTRIBUTE_GROUPS(wdt); #endif /* - * watchdog_ioctl_op - call the watchdog drivers ioctl op if defined - * @wdd: The watchdog device to do the ioctl on - * @cmd: Watchdog command + * watchcat_ioctl_op - call the watchcat drivers ioctl op if defined + * @wdd: The watchcat device to do the ioctl on + * @cmd: watchcat command * @arg: Argument pointer * * The caller must hold wd_data->lock. * * Return: 0 if successful, error otherwise. */ -static int watchdog_ioctl_op(struct watchdog_device *wdd, unsigned int cmd, +static int watchcat_ioctl_op(struct watchcat_device *wdd, unsigned int cmd, unsigned long arg) { if (!wdd->ops->ioctl) @@ -682,23 +682,23 @@ static int watchdog_ioctl_op(struct watchdog_device *wdd, unsigned int cmd, } /* - * watchdog_write - writes to the watchdog + * watchcat_write - writes to the watchcat * @file: File from VFS * @data: User address of data * @len: Length of data * @ppos: Pointer to the file offset * - * A write to a watchdog device is defined as a keepalive ping. + * A write to a watchcat device is defined as a keepalive ping. * Writing the magic 'V' sequence allows the next close to turn - * off the watchdog (if 'nowayout' is not set). + * off the watchcat (if 'nowayout' is not set). * * Return: @len if successful, error otherwise. */ -static ssize_t watchdog_write(struct file *file, const char __user *data, +static ssize_t watchcat_write(struct file *file, const char __user *data, size_t len, loff_t *ppos) { - struct watchdog_core_data *wd_data = file->private_data; - struct watchdog_device *wdd; + struct watchcat_core_data *wd_data = file->private_data; + struct watchcat_device *wdd; int err; size_t i; char c; @@ -720,13 +720,13 @@ static ssize_t watchdog_write(struct file *file, const char __user *data, set_bit(_WDOG_ALLOW_RELEASE, &wd_data->status); } - /* someone wrote to us, so we send the watchdog a keepalive ping */ + /* someone wrote to us, so we send the watchcat a keepalive ping */ err = -ENODEV; mutex_lock(&wd_data->lock); wdd = wd_data->wdd; if (wdd) - err = watchdog_ping(wdd); + err = watchcat_ping(wdd); mutex_unlock(&wd_data->lock); if (err < 0) @@ -736,23 +736,23 @@ static ssize_t watchdog_write(struct file *file, const char __user *data, } /* - * watchdog_ioctl - handle the different ioctl's for the watchdog device + * watchcat_ioctl - handle the different ioctl's for the watchcat device * @file: File handle to the device - * @cmd: Watchdog command + * @cmd: watchcat command * @arg: Argument pointer * - * The watchdog API defines a common set of functions for all watchdogs + * The watchcat API defines a common set of functions for all watchcats * according to their available features. * * Return: 0 if successful, error otherwise. */ -static long watchdog_ioctl(struct file *file, unsigned int cmd, +static long watchcat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - struct watchdog_core_data *wd_data = file->private_data; + struct watchcat_core_data *wd_data = file->private_data; void __user *argp = (void __user *)arg; - struct watchdog_device *wdd; + struct watchcat_device *wdd; int __user *p = argp; unsigned int val; int err; @@ -765,17 +765,17 @@ static long watchdog_ioctl(struct file *file, unsigned int cmd, goto out_ioctl; } - err = watchdog_ioctl_op(wdd, cmd, arg); + err = watchcat_ioctl_op(wdd, cmd, arg); if (err != -ENOIOCTLCMD) goto out_ioctl; switch (cmd) { case WDIOC_GETSUPPORT: err = copy_to_user(argp, wdd->info, - sizeof(struct watchdog_info)) ? -EFAULT : 0; + sizeof(struct watchcat_info)) ? -EFAULT : 0; break; case WDIOC_GETSTATUS: - val = watchdog_get_status(wdd); + val = watchcat_get_status(wdd); err = put_user(val, p); break; case WDIOC_GETBOOTSTATUS: @@ -787,32 +787,32 @@ static long watchdog_ioctl(struct file *file, unsigned int cmd, break; } if (val & WDIOS_DISABLECARD) { - err = watchdog_stop(wdd); + err = watchcat_stop(wdd); if (err < 0) break; } if (val & WDIOS_ENABLECARD) - err = watchdog_start(wdd); + err = watchcat_start(wdd); break; case WDIOC_KEEPALIVE: if (!(wdd->info->options & WDIOF_KEEPALIVEPING)) { err = -EOPNOTSUPP; break; } - err = watchdog_ping(wdd); + err = watchcat_ping(wdd); break; case WDIOC_SETTIMEOUT: if (get_user(val, p)) { err = -EFAULT; break; } - err = watchdog_set_timeout(wdd, val); + err = watchcat_set_timeout(wdd, val); if (err < 0) break; - /* If the watchdog is active then we send a keepalive ping - * to make sure that the watchdog keep's running (and if + /* If the watchcat is active then we send a keepalive ping + * to make sure that the watchcat keep's running (and if * possible that it takes the new timeout) */ - err = watchdog_ping(wdd); + err = watchcat_ping(wdd); if (err < 0) break; fallthrough; @@ -825,7 +825,7 @@ static long watchdog_ioctl(struct file *file, unsigned int cmd, err = put_user(wdd->timeout, p); break; case WDIOC_GETTIMELEFT: - err = watchdog_get_timeleft(wdd, &val); + err = watchcat_get_timeleft(wdd, &val); if (err < 0) break; err = put_user(val, p); @@ -835,7 +835,7 @@ static long watchdog_ioctl(struct file *file, unsigned int cmd, err = -EFAULT; break; } - err = watchdog_set_pretimeout(wdd, val); + err = watchcat_set_pretimeout(wdd, val); break; case WDIOC_GETPRETIMEOUT: err = put_user(wdd->pretimeout, p); @@ -851,47 +851,47 @@ static long watchdog_ioctl(struct file *file, unsigned int cmd, } /* - * watchdog_open - open the /dev/watchdog* devices + * watchcat_open - open the /dev/watchcat* devices * @inode: Inode of device * @file: File handle to device * - * When the /dev/watchdog* device gets opened, we start the watchdog. - * Watch out: the /dev/watchdog device is single open, so we make sure + * When the /dev/watchcat* device gets opened, we start the watchcat. + * Watch out: the /dev/watchcat device is single open, so we make sure * it can only be opened once. * * Return: 0 if successful, error otherwise. */ -static int watchdog_open(struct inode *inode, struct file *file) +static int watchcat_open(struct inode *inode, struct file *file) { - struct watchdog_core_data *wd_data; - struct watchdog_device *wdd; + struct watchcat_core_data *wd_data; + struct watchcat_device *wdd; bool hw_running; int err; - /* Get the corresponding watchdog device */ + /* Get the corresponding watchcat device */ if (imajor(inode) == MISC_MAJOR) wd_data = old_wd_data; else - wd_data = container_of(inode->i_cdev, struct watchdog_core_data, + wd_data = container_of(inode->i_cdev, struct watchcat_core_data, cdev); - /* the watchdog is single open! */ + /* the watchcat is single open! */ if (test_and_set_bit(_WDOG_DEV_OPEN, &wd_data->status)) return -EBUSY; wdd = wd_data->wdd; /* - * If the /dev/watchdog device is open, we don't want the module + * If the /dev/watchcat device is open, we don't want the module * to be unloaded. */ - hw_running = watchdog_hw_running(wdd); + hw_running = watchcat_hw_running(wdd); if (!hw_running && !try_module_get(wdd->ops->owner)) { err = -EBUSY; goto out_clear; } - err = watchdog_start(wdd); + err = watchcat_start(wdd); if (err < 0) goto out_mod; @@ -903,13 +903,13 @@ static int watchdog_open(struct inode *inode, struct file *file) /* * open_timeout only applies for the first open from * userspace. Set open_deadline to infinity so that the kernel - * will take care of an always-running hardware watchdog in + * will take care of an always-running hardware watchcat in * case the device gets magic-closed or WDIOS_DISABLECARD is * applied. */ wd_data->open_deadline = KTIME_MAX; - /* dev/watchdog is a virtual (and thus non-seekable) filesystem */ + /* dev/watchcat is a virtual (and thus non-seekable) filesystem */ return stream_open(inode, file); out_mod: @@ -919,30 +919,30 @@ static int watchdog_open(struct inode *inode, struct file *file) return err; } -static void watchdog_core_data_release(struct device *dev) +static void watchcat_core_data_release(struct device *dev) { - struct watchdog_core_data *wd_data; + struct watchcat_core_data *wd_data; - wd_data = container_of(dev, struct watchdog_core_data, dev); + wd_data = container_of(dev, struct watchcat_core_data, dev); kfree(wd_data); } /* - * watchdog_release - release the watchdog device + * watchcat_release - release the watchcat device * @inode: Inode of device * @file: File handle to device * - * This is the code for when /dev/watchdog gets closed. We will only - * stop the watchdog when we have received the magic char (and nowayout - * was not set), else the watchdog will keep running. + * This is the code for when /dev/watchcat gets closed. We will only + * stop the watchcat when we have received the magic char (and nowayout + * was not set), else the watchcat will keep running. * * Always returns 0. */ -static int watchdog_release(struct inode *inode, struct file *file) +static int watchcat_release(struct inode *inode, struct file *file) { - struct watchdog_core_data *wd_data = file->private_data; - struct watchdog_device *wdd; + struct watchcat_core_data *wd_data = file->private_data; + struct watchcat_device *wdd; int err = -EBUSY; bool running; @@ -953,33 +953,33 @@ static int watchdog_release(struct inode *inode, struct file *file) goto done; /* - * We only stop the watchdog if we received the magic character + * We only stop the watchcat if we received the magic character * or if WDIOF_MAGICCLOSE is not set. If nowayout was set then - * watchdog_stop will fail. + * watchcat_stop will fail. */ - if (!watchdog_active(wdd)) + if (!watchcat_active(wdd)) err = 0; else if (test_and_clear_bit(_WDOG_ALLOW_RELEASE, &wd_data->status) || !(wdd->info->options & WDIOF_MAGICCLOSE)) - err = watchdog_stop(wdd); + err = watchcat_stop(wdd); - /* If the watchdog was not stopped, send a keepalive ping */ + /* If the watchcat was not stopped, send a keepalive ping */ if (err < 0) { - pr_crit("watchdog%d: watchdog did not stop!\n", wdd->id); - watchdog_ping(wdd); + pr_crit("watchcat%d: watchcat did not stop!\n", wdd->id); + watchcat_ping(wdd); } - watchdog_update_worker(wdd); + watchcat_update_worker(wdd); - /* make sure that /dev/watchdog can be re-opened */ + /* make sure that /dev/watchcat can be re-opened */ clear_bit(_WDOG_DEV_OPEN, &wd_data->status); done: - running = wdd && watchdog_hw_running(wdd); + running = wdd && watchcat_hw_running(wdd); mutex_unlock(&wd_data->lock); /* - * Allow the owner module to be unloaded again unless the watchdog - * is still running. If the watchdog is still running, it can not + * Allow the owner module to be unloaded again unless the watchcat + * is still running. If the watchcat is still running, it can not * be stopped, and its driver must not be unloaded. */ if (!running) { @@ -989,42 +989,42 @@ static int watchdog_release(struct inode *inode, struct file *file) return 0; } -static const struct file_operations watchdog_fops = { +static const struct file_operations watchcat_fops = { .owner = THIS_MODULE, - .write = watchdog_write, - .unlocked_ioctl = watchdog_ioctl, + .write = watchcat_write, + .unlocked_ioctl = watchcat_ioctl, .compat_ioctl = compat_ptr_ioctl, - .open = watchdog_open, - .release = watchdog_release, + .open = watchcat_open, + .release = watchcat_release, }; -static struct miscdevice watchdog_miscdev = { - .minor = WATCHDOG_MINOR, - .name = "watchdog", - .fops = &watchdog_fops, +static struct miscdevice watchcat_miscdev = { + .minor = watchcat_MINOR, + .name = "watchcat", + .fops = &watchcat_fops, }; -static struct class watchdog_class = { - .name = "watchdog", +static struct class watchcat_class = { + .name = "watchcat", .dev_groups = wdt_groups, }; /* - * watchdog_cdev_register - register watchdog character device - * @wdd: Watchdog device + * watchcat_cdev_register - register watchcat character device + * @wdd: watchcat device * - * Register a watchdog character device including handling the legacy - * /dev/watchdog node. /dev/watchdog is actually a miscdevice and + * Register a watchcat character device including handling the legacy + * /dev/watchcat node. /dev/watchcat is actually a miscdevice and * thus we set it up like that. * * Return: 0 if successful, error otherwise. */ -static int watchdog_cdev_register(struct watchdog_device *wdd) +static int watchcat_cdev_register(struct watchcat_device *wdd) { - struct watchdog_core_data *wd_data; + struct watchcat_core_data *wd_data; int err; - wd_data = kzalloc(sizeof(struct watchdog_core_data), GFP_KERNEL); + wd_data = kzalloc(sizeof(struct watchcat_core_data), GFP_KERNEL); if (!wd_data) return -ENOMEM; mutex_init(&wd_data->lock); @@ -1032,38 +1032,38 @@ static int watchdog_cdev_register(struct watchdog_device *wdd) wd_data->wdd = wdd; wdd->wd_data = wd_data; - if (IS_ERR_OR_NULL(watchdog_kworker)) { + if (IS_ERR_OR_NULL(watchcat_kworker)) { kfree(wd_data); return -ENODEV; } device_initialize(&wd_data->dev); - wd_data->dev.devt = MKDEV(MAJOR(watchdog_devt), wdd->id); - wd_data->dev.class = &watchdog_class; + wd_data->dev.devt = MKDEV(MAJOR(watchcat_devt), wdd->id); + wd_data->dev.class = &watchcat_class; wd_data->dev.parent = wdd->parent; wd_data->dev.groups = wdd->groups; - wd_data->dev.release = watchdog_core_data_release; + wd_data->dev.release = watchcat_core_data_release; dev_set_drvdata(&wd_data->dev, wdd); - err = dev_set_name(&wd_data->dev, "watchdog%d", wdd->id); + err = dev_set_name(&wd_data->dev, "watchcat%d", wdd->id); if (err) { put_device(&wd_data->dev); return err; } - kthread_init_work(&wd_data->work, watchdog_ping_work); + kthread_init_work(&wd_data->work, watchcat_ping_work); hrtimer_init(&wd_data->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD); - wd_data->timer.function = watchdog_timer_expired; - watchdog_hrtimer_pretimeout_init(wdd); + wd_data->timer.function = watchcat_timer_expired; + watchcat_hrtimer_pretimeout_init(wdd); if (wdd->id == 0) { old_wd_data = wd_data; - watchdog_miscdev.parent = wdd->parent; - err = misc_register(&watchdog_miscdev); + watchcat_miscdev.parent = wdd->parent; + err = misc_register(&watchcat_miscdev); if (err != 0) { pr_err("%s: cannot register miscdev on minor=%d (err=%d).\n", - wdd->info->identity, WATCHDOG_MINOR, err); + wdd->info->identity, watchcat_MINOR, err); if (err == -EBUSY) - pr_err("%s: a legacy watchdog module is probably present.\n", + pr_err("%s: a legacy watchcat module is probably present.\n", wdd->info->identity); old_wd_data = NULL; put_device(&wd_data->dev); @@ -1072,16 +1072,16 @@ static int watchdog_cdev_register(struct watchdog_device *wdd) } /* Fill in the data structures */ - cdev_init(&wd_data->cdev, &watchdog_fops); + cdev_init(&wd_data->cdev, &watchcat_fops); wd_data->cdev.owner = wdd->ops->owner; /* Add the device */ err = cdev_device_add(&wd_data->cdev, &wd_data->dev); if (err) { - pr_err("watchdog%d unable to add device %d:%d\n", - wdd->id, MAJOR(watchdog_devt), wdd->id); + pr_err("watchcat%d unable to add device %d:%d\n", + wdd->id, MAJOR(watchcat_devt), wdd->id); if (wdd->id == 0) { - misc_deregister(&watchdog_miscdev); + misc_deregister(&watchcat_miscdev); old_wd_data = NULL; } put_device(&wd_data->dev); @@ -1090,20 +1090,20 @@ static int watchdog_cdev_register(struct watchdog_device *wdd) /* Record time of most recent heartbeat as 'just before now'. */ wd_data->last_hw_keepalive = ktime_sub(ktime_get(), 1); - watchdog_set_open_deadline(wd_data); + watchcat_set_open_deadline(wd_data); /* - * If the watchdog is running, prevent its driver from being unloaded, + * If the watchcat is running, prevent its driver from being unloaded, * and schedule an immediate ping. */ - if (watchdog_hw_running(wdd)) { + if (watchcat_hw_running(wdd)) { __module_get(wdd->ops->owner); get_device(&wd_data->dev); if (handle_boot_enabled) hrtimer_start(&wd_data->timer, 0, HRTIMER_MODE_REL_HARD); else - pr_info("watchdog%d running and kernel based pre-userspace handler disabled\n", + pr_info("watchcat%d running and kernel based pre-userspace handler disabled\n", wdd->id); } @@ -1111,28 +1111,28 @@ static int watchdog_cdev_register(struct watchdog_device *wdd) } /* - * watchdog_cdev_unregister - unregister watchdog character device - * @wdd: Watchdog device + * watchcat_cdev_unregister - unregister watchcat character device + * @wdd: watchcat device * - * Unregister watchdog character device and if needed the legacy - * /dev/watchdog device. + * Unregister watchcat character device and if needed the legacy + * /dev/watchcat device. */ -static void watchdog_cdev_unregister(struct watchdog_device *wdd) +static void watchcat_cdev_unregister(struct watchcat_device *wdd) { - struct watchdog_core_data *wd_data = wdd->wd_data; + struct watchcat_core_data *wd_data = wdd->wd_data; cdev_device_del(&wd_data->cdev, &wd_data->dev); if (wdd->id == 0) { - misc_deregister(&watchdog_miscdev); + misc_deregister(&watchcat_miscdev); old_wd_data = NULL; } - if (watchdog_active(wdd) && + if (watchcat_active(wdd) && test_bit(WDOG_STOP_ON_UNREGISTER, &wdd->status)) { - watchdog_stop(wdd); + watchcat_stop(wdd); } - watchdog_hrtimer_pretimeout_stop(wdd); + watchcat_hrtimer_pretimeout_stop(wdd); mutex_lock(&wd_data->lock); wd_data->wdd = NULL; @@ -1146,60 +1146,60 @@ static void watchdog_cdev_unregister(struct watchdog_device *wdd) } /** - * watchdog_dev_register - register a watchdog device - * @wdd: Watchdog device + * watchcat_dev_register - register a watchcat device + * @wdd: watchcat device * - * Register a watchdog device including handling the legacy - * /dev/watchdog node. /dev/watchdog is actually a miscdevice and + * Register a watchcat device including handling the legacy + * /dev/watchcat node. /dev/watchcat is actually a miscdevice and * thus we set it up like that. * * Return: 0 if successful, error otherwise. */ -int watchdog_dev_register(struct watchdog_device *wdd) +int watchcat_dev_register(struct watchcat_device *wdd) { int ret; - ret = watchdog_cdev_register(wdd); + ret = watchcat_cdev_register(wdd); if (ret) return ret; - ret = watchdog_register_pretimeout(wdd); + ret = watchcat_register_pretimeout(wdd); if (ret) - watchdog_cdev_unregister(wdd); + watchcat_cdev_unregister(wdd); return ret; } /** - * watchdog_dev_unregister - unregister a watchdog device - * @wdd: watchdog device + * watchcat_dev_unregister - unregister a watchcat device + * @wdd: watchcat device * - * Unregister watchdog device and if needed the legacy - * /dev/watchdog device. + * Unregister watchcat device and if needed the legacy + * /dev/watchcat device. */ -void watchdog_dev_unregister(struct watchdog_device *wdd) +void watchcat_dev_unregister(struct watchcat_device *wdd) { - watchdog_unregister_pretimeout(wdd); - watchdog_cdev_unregister(wdd); + watchcat_unregister_pretimeout(wdd); + watchcat_cdev_unregister(wdd); } /** - * watchdog_set_last_hw_keepalive - set last HW keepalive time for watchdog - * @wdd: Watchdog device + * watchcat_set_last_hw_keepalive - set last HW keepalive time for watchcat + * @wdd: watchcat device * @last_ping_ms: Time since last HW heartbeat * - * Adjusts the last known HW keepalive time for a watchdog timer. - * This is needed if the watchdog is already running when the probe + * Adjusts the last known HW keepalive time for a watchcat timer. + * This is needed if the watchcat is already running when the probe * function is called, and it can't be pinged immediately. This - * function must be called immediately after watchdog registration, + * function must be called immediately after watchcat registration, * and min_hw_heartbeat_ms must be set for this to be useful. * * Return: 0 if successful, error otherwise. */ -int watchdog_set_last_hw_keepalive(struct watchdog_device *wdd, +int watchcat_set_last_hw_keepalive(struct watchcat_device *wdd, unsigned int last_ping_ms) { - struct watchdog_core_data *wd_data; + struct watchcat_core_data *wd_data; ktime_t now; if (!wdd) @@ -1211,67 +1211,67 @@ int watchdog_set_last_hw_keepalive(struct watchdog_device *wdd, wd_data->last_hw_keepalive = ktime_sub(now, ms_to_ktime(last_ping_ms)); - if (watchdog_hw_running(wdd) && handle_boot_enabled) - return __watchdog_ping(wdd); + if (watchcat_hw_running(wdd) && handle_boot_enabled) + return __watchcat_ping(wdd); return 0; } -EXPORT_SYMBOL_GPL(watchdog_set_last_hw_keepalive); +EXPORT_SYMBOL_GPL(watchcat_set_last_hw_keepalive); /** - * watchdog_dev_init - init dev part of watchdog core + * watchcat_dev_init - init dev part of watchcat core * - * Allocate a range of chardev nodes to use for watchdog devices. + * Allocate a range of chardev nodes to use for watchcat devices. * * Return: 0 if successful, error otherwise. */ -int __init watchdog_dev_init(void) +int __init watchcat_dev_init(void) { int err; - watchdog_kworker = kthread_create_worker(0, "watchdogd"); - if (IS_ERR(watchdog_kworker)) { - pr_err("Failed to create watchdog kworker\n"); - return PTR_ERR(watchdog_kworker); + watchcat_kworker = kthread_create_worker(0, "watchcatd"); + if (IS_ERR(watchcat_kworker)) { + pr_err("Failed to create watchcat kworker\n"); + return PTR_ERR(watchcat_kworker); } - sched_set_fifo(watchdog_kworker->task); + sched_set_fifo(watchcat_kworker->task); - err = class_register(&watchdog_class); + err = class_register(&watchcat_class); if (err < 0) { pr_err("couldn't register class\n"); goto err_register; } - err = alloc_chrdev_region(&watchdog_devt, 0, MAX_DOGS, "watchdog"); + err = alloc_chrdev_region(&watchcat_devt, 0, MAX_DOGS, "watchcat"); if (err < 0) { - pr_err("watchdog: unable to allocate char dev region\n"); + pr_err("watchcat: unable to allocate char dev region\n"); goto err_alloc; } return 0; err_alloc: - class_unregister(&watchdog_class); + class_unregister(&watchcat_class); err_register: - kthread_destroy_worker(watchdog_kworker); + kthread_destroy_worker(watchcat_kworker); return err; } /** - * watchdog_dev_exit - exit dev part of watchdog core + * watchcat_dev_exit - exit dev part of watchcat core * - * Release the range of chardev nodes used for watchdog devices. + * Release the range of chardev nodes used for watchcat devices. */ -void __exit watchdog_dev_exit(void) +void __exit watchcat_dev_exit(void) { - unregister_chrdev_region(watchdog_devt, MAX_DOGS); - class_unregister(&watchdog_class); - kthread_destroy_worker(watchdog_kworker); + unregister_chrdev_region(watchcat_devt, MAX_DOGS); + class_unregister(&watchcat_class); + kthread_destroy_worker(watchcat_kworker); } -int watchdog_dev_suspend(struct watchdog_device *wdd) +int watchcat_dev_suspend(struct watchcat_device *wdd) { - struct watchdog_core_data *wd_data = wdd->wd_data; + struct watchcat_core_data *wd_data = wdd->wd_data; int ret = 0; if (!wdd->wd_data) @@ -1279,15 +1279,15 @@ int watchdog_dev_suspend(struct watchdog_device *wdd) /* ping for the last time before suspend */ mutex_lock(&wd_data->lock); - if (watchdog_worker_should_ping(wd_data)) - ret = __watchdog_ping(wd_data->wdd); + if (watchcat_worker_should_ping(wd_data)) + ret = __watchcat_ping(wd_data->wdd); mutex_unlock(&wd_data->lock); if (ret) return ret; /* - * make sure that watchdog worker will not kick in when the wdog is + * make sure that watchcat worker will not kick in when the wdog is * suspended */ hrtimer_cancel(&wd_data->timer); @@ -1296,21 +1296,21 @@ int watchdog_dev_suspend(struct watchdog_device *wdd) return 0; } -int watchdog_dev_resume(struct watchdog_device *wdd) +int watchcat_dev_resume(struct watchcat_device *wdd) { - struct watchdog_core_data *wd_data = wdd->wd_data; + struct watchcat_core_data *wd_data = wdd->wd_data; int ret = 0; if (!wdd->wd_data) return -ENODEV; /* - * __watchdog_ping will also retrigger hrtimer and therefore restore the + * __watchcat_ping will also retrigger hrtimer and therefore restore the * ping worker if needed. */ mutex_lock(&wd_data->lock); - if (watchdog_worker_should_ping(wd_data)) - ret = __watchdog_ping(wd_data->wdd); + if (watchcat_worker_should_ping(wd_data)) + ret = __watchcat_ping(wd_data->wdd); mutex_unlock(&wd_data->lock); return ret; @@ -1318,10 +1318,10 @@ int watchdog_dev_resume(struct watchdog_device *wdd) module_param(handle_boot_enabled, bool, 0444); MODULE_PARM_DESC(handle_boot_enabled, - "Watchdog core auto-updates boot enabled watchdogs before userspace takes over (default=" - __MODULE_STRING(IS_ENABLED(CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED)) ")"); + "watchcat core auto-updates boot enabled watchcats before userspace takes over (default=" + __MODULE_STRING(IS_ENABLED(CONFIG_watchcat_HANDLE_BOOT_ENABLED)) ")"); module_param(open_timeout, uint, 0644); MODULE_PARM_DESC(open_timeout, - "Maximum time (in seconds, 0 means infinity) for userspace to take over a running watchdog (default=" - __MODULE_STRING(CONFIG_WATCHDOG_OPEN_TIMEOUT) ")"); + "Maximum time (in seconds, 0 means infinity) for userspace to take over a running watchcat (default=" + __MODULE_STRING(CONFIG_watchcat_OPEN_TIMEOUT) ")"); diff --git a/drivers/watchdog/watchcat_hrtimer_pretimeout.c b/drivers/watchdog/watchcat_hrtimer_pretimeout.c new file mode 100644 index 00000000000000..d894a1304fb004 --- /dev/null +++ b/drivers/watchdog/watchcat_hrtimer_pretimeout.c @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * (c) Copyright 2021 Hewlett Packard Enterprise Development LP. + */ + +#include +#include + +#include "watchcat_core.h" +#include "watchcat_pretimeout.h" + +static enum hrtimer_restart watchcat_hrtimer_pretimeout(struct hrtimer *timer) +{ + struct watchcat_core_data *wd_data; + + wd_data = container_of(timer, struct watchcat_core_data, pretimeout_timer); + + watchcat_notify_pretimeout(wd_data->wdd); + return HRTIMER_NORESTART; +} + +void watchcat_hrtimer_pretimeout_init(struct watchcat_device *wdd) +{ + struct watchcat_core_data *wd_data = wdd->wd_data; + + hrtimer_init(&wd_data->pretimeout_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); + wd_data->pretimeout_timer.function = watchcat_hrtimer_pretimeout; +} + +void watchcat_hrtimer_pretimeout_start(struct watchcat_device *wdd) +{ + if (!(wdd->info->options & WDIOF_PRETIMEOUT) && + !watchcat_pretimeout_invalid(wdd, wdd->pretimeout)) + hrtimer_start(&wdd->wd_data->pretimeout_timer, + ktime_set(wdd->timeout - wdd->pretimeout, 0), + HRTIMER_MODE_REL); + else + hrtimer_cancel(&wdd->wd_data->pretimeout_timer); +} + +void watchcat_hrtimer_pretimeout_stop(struct watchcat_device *wdd) +{ + hrtimer_cancel(&wdd->wd_data->pretimeout_timer); +} diff --git a/drivers/watchdog/watchdog_pretimeout.c b/drivers/watchdog/watchcat_pretimeout.c similarity index 71% rename from drivers/watchdog/watchdog_pretimeout.c rename to drivers/watchdog/watchcat_pretimeout.c index e5295c990fa1b8..43f99a7fa76206 100644 --- a/drivers/watchdog/watchdog_pretimeout.c +++ b/drivers/watchdog/watchcat_pretimeout.c @@ -7,33 +7,33 @@ #include #include #include -#include +#include -#include "watchdog_core.h" -#include "watchdog_pretimeout.h" +#include "watchcat_core.h" +#include "watchcat_pretimeout.h" -/* Default watchdog pretimeout governor */ -static struct watchdog_governor *default_gov; +/* Default watchcat pretimeout governor */ +static struct watchcat_governor *default_gov; /* The spinlock protects default_gov, wdd->gov and pretimeout_list */ static DEFINE_SPINLOCK(pretimeout_lock); -/* List of watchdog devices, which can generate a pretimeout event */ +/* List of watchcat devices, which can generate a pretimeout event */ static LIST_HEAD(pretimeout_list); -struct watchdog_pretimeout { - struct watchdog_device *wdd; +struct watchcat_pretimeout { + struct watchcat_device *wdd; struct list_head entry; }; /* The mutex protects governor list and serializes external interfaces */ static DEFINE_MUTEX(governor_lock); -/* List of the registered watchdog pretimeout governors */ +/* List of the registered watchcat pretimeout governors */ static LIST_HEAD(governor_list); struct governor_priv { - struct watchdog_governor *gov; + struct watchcat_governor *gov; struct list_head entry; }; @@ -48,7 +48,7 @@ static struct governor_priv *find_governor_by_name(const char *gov_name) return NULL; } -int watchdog_pretimeout_available_governors_get(char *buf) +int watchcat_pretimeout_available_governors_get(char *buf) { struct governor_priv *priv; int count = 0; @@ -63,7 +63,7 @@ int watchdog_pretimeout_available_governors_get(char *buf) return count; } -int watchdog_pretimeout_governor_get(struct watchdog_device *wdd, char *buf) +int watchcat_pretimeout_governor_get(struct watchcat_device *wdd, char *buf) { int count = 0; @@ -75,7 +75,7 @@ int watchdog_pretimeout_governor_get(struct watchdog_device *wdd, char *buf) return count; } -int watchdog_pretimeout_governor_set(struct watchdog_device *wdd, +int watchcat_pretimeout_governor_set(struct watchcat_device *wdd, const char *buf) { struct governor_priv *priv; @@ -97,7 +97,7 @@ int watchdog_pretimeout_governor_set(struct watchdog_device *wdd, return 0; } -void watchdog_notify_pretimeout(struct watchdog_device *wdd) +void watchcat_notify_pretimeout(struct watchcat_device *wdd) { unsigned long flags; @@ -110,11 +110,11 @@ void watchdog_notify_pretimeout(struct watchdog_device *wdd) wdd->gov->pretimeout(wdd); spin_unlock_irqrestore(&pretimeout_lock, flags); } -EXPORT_SYMBOL_GPL(watchdog_notify_pretimeout); +EXPORT_SYMBOL_GPL(watchcat_notify_pretimeout); -int watchdog_register_governor(struct watchdog_governor *gov) +int watchcat_register_governor(struct watchcat_governor *gov) { - struct watchdog_pretimeout *p; + struct watchcat_pretimeout *p; struct governor_priv *priv; priv = kzalloc(sizeof(*priv), GFP_KERNEL); @@ -132,8 +132,8 @@ int watchdog_register_governor(struct watchdog_governor *gov) priv->gov = gov; list_add(&priv->entry, &governor_list); - if (!strncmp(gov->name, WATCHDOG_PRETIMEOUT_DEFAULT_GOV, - WATCHDOG_GOV_NAME_MAXLEN)) { + if (!strncmp(gov->name, watchcat_PRETIMEOUT_DEFAULT_GOV, + watchcat_GOV_NAME_MAXLEN)) { spin_lock_irq(&pretimeout_lock); default_gov = gov; @@ -147,11 +147,11 @@ int watchdog_register_governor(struct watchdog_governor *gov) return 0; } -EXPORT_SYMBOL(watchdog_register_governor); +EXPORT_SYMBOL(watchcat_register_governor); -void watchdog_unregister_governor(struct watchdog_governor *gov) +void watchcat_unregister_governor(struct watchcat_governor *gov) { - struct watchdog_pretimeout *p; + struct watchcat_pretimeout *p; struct governor_priv *priv, *t; mutex_lock(&governor_lock); @@ -172,13 +172,13 @@ void watchdog_unregister_governor(struct watchdog_governor *gov) mutex_unlock(&governor_lock); } -EXPORT_SYMBOL(watchdog_unregister_governor); +EXPORT_SYMBOL(watchcat_unregister_governor); -int watchdog_register_pretimeout(struct watchdog_device *wdd) +int watchcat_register_pretimeout(struct watchcat_device *wdd) { - struct watchdog_pretimeout *p; + struct watchcat_pretimeout *p; - if (!watchdog_have_pretimeout(wdd)) + if (!watchcat_have_pretimeout(wdd)) return 0; p = kzalloc(sizeof(*p), GFP_KERNEL); @@ -194,11 +194,11 @@ int watchdog_register_pretimeout(struct watchdog_device *wdd) return 0; } -void watchdog_unregister_pretimeout(struct watchdog_device *wdd) +void watchcat_unregister_pretimeout(struct watchcat_device *wdd) { - struct watchdog_pretimeout *p, *t; + struct watchcat_pretimeout *p, *t; - if (!watchdog_have_pretimeout(wdd)) + if (!watchcat_have_pretimeout(wdd)) return; spin_lock_irq(&pretimeout_lock); diff --git a/drivers/watchdog/watchcat_pretimeout.h b/drivers/watchdog/watchcat_pretimeout.h new file mode 100644 index 00000000000000..96394061118432 --- /dev/null +++ b/drivers/watchdog/watchcat_pretimeout.h @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __watchcat_PRETIMEOUT_H +#define __watchcat_PRETIMEOUT_H + +#define watchcat_GOV_NAME_MAXLEN 20 + +struct watchcat_device; + +struct watchcat_governor { + const char name[watchcat_GOV_NAME_MAXLEN]; + void (*pretimeout)(struct watchcat_device *wdd); +}; + +#if IS_ENABLED(CONFIG_watchcat_PRETIMEOUT_GOV) +/* Interfaces to watchcat pretimeout governors */ +int watchcat_register_governor(struct watchcat_governor *gov); +void watchcat_unregister_governor(struct watchcat_governor *gov); + +/* Interfaces to watchcat_dev.c */ +int watchcat_register_pretimeout(struct watchcat_device *wdd); +void watchcat_unregister_pretimeout(struct watchcat_device *wdd); +int watchcat_pretimeout_available_governors_get(char *buf); +int watchcat_pretimeout_governor_get(struct watchcat_device *wdd, char *buf); +int watchcat_pretimeout_governor_set(struct watchcat_device *wdd, + const char *buf); + +#if IS_ENABLED(CONFIG_watchcat_PRETIMEOUT_DEFAULT_GOV_NOOP) +#define watchcat_PRETIMEOUT_DEFAULT_GOV "noop" +#elif IS_ENABLED(CONFIG_watchcat_PRETIMEOUT_DEFAULT_GOV_PANIC) +#define watchcat_PRETIMEOUT_DEFAULT_GOV "panic" +#endif + +#else +static inline int watchcat_register_pretimeout(struct watchcat_device *wdd) +{ + return 0; +} + +static inline void watchcat_unregister_pretimeout(struct watchcat_device *wdd) +{ +} + +static inline int watchcat_pretimeout_available_governors_get(char *buf) +{ + return -EINVAL; +} + +static inline int watchcat_pretimeout_governor_get(struct watchcat_device *wdd, + char *buf) +{ + return -EINVAL; +} + +static inline int watchcat_pretimeout_governor_set(struct watchcat_device *wdd, + const char *buf) +{ + return -EINVAL; +} +#endif + +#endif diff --git a/drivers/watchdog/watchdog_core.h b/drivers/watchdog/watchdog_core.h deleted file mode 100644 index 5b35a8439e26f2..00000000000000 --- a/drivers/watchdog/watchdog_core.h +++ /dev/null @@ -1,81 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * watchdog_core.h - * - * (c) Copyright 2008-2011 Alan Cox , - * All Rights Reserved. - * - * (c) Copyright 2008-2011 Wim Van Sebroeck . - * - * (c) Copyright 2021 Hewlett Packard Enterprise Development LP. - * - * This source code is part of the generic code that can be used - * by all the watchdog timer drivers. - * - * Based on source code of the following authors: - * Matt Domsch , - * Rob Radez , - * Rusty Lynch - * Satyam Sharma - * Randy Dunlap - * - * Neither Alan Cox, CymruNet Ltd., Wim Van Sebroeck nor Iguana vzw. - * admit liability nor provide warranty for any of this software. - * This material is provided "AS-IS" and at no charge. - */ - -#include -#include - -#define MAX_DOGS 32 /* Maximum number of watchdog devices */ - -/* - * struct watchdog_core_data - watchdog core internal data - * @dev: The watchdog's internal device - * @cdev: The watchdog's Character device. - * @wdd: Pointer to watchdog device. - * @lock: Lock for watchdog core. - * @status: Watchdog core internal status bits. - */ -struct watchdog_core_data { - struct device dev; - struct cdev cdev; - struct watchdog_device *wdd; - struct mutex lock; - ktime_t last_keepalive; - ktime_t last_hw_keepalive; - ktime_t open_deadline; - struct hrtimer timer; - struct kthread_work work; -#if IS_ENABLED(CONFIG_WATCHDOG_HRTIMER_PRETIMEOUT) - struct hrtimer pretimeout_timer; -#endif - unsigned long status; /* Internal status bits */ -#define _WDOG_DEV_OPEN 0 /* Opened ? */ -#define _WDOG_ALLOW_RELEASE 1 /* Did we receive the magic char ? */ -#define _WDOG_KEEPALIVE 2 /* Did we receive a keepalive ? */ -}; - -/* - * Functions/procedures to be called by the core - */ -extern int watchdog_dev_register(struct watchdog_device *); -extern void watchdog_dev_unregister(struct watchdog_device *); -extern int __init watchdog_dev_init(void); -extern void __exit watchdog_dev_exit(void); - -static inline bool watchdog_have_pretimeout(struct watchdog_device *wdd) -{ - return wdd->info->options & WDIOF_PRETIMEOUT || - IS_ENABLED(CONFIG_WATCHDOG_HRTIMER_PRETIMEOUT); -} - -#if IS_ENABLED(CONFIG_WATCHDOG_HRTIMER_PRETIMEOUT) -void watchdog_hrtimer_pretimeout_init(struct watchdog_device *wdd); -void watchdog_hrtimer_pretimeout_start(struct watchdog_device *wdd); -void watchdog_hrtimer_pretimeout_stop(struct watchdog_device *wdd); -#else -static inline void watchdog_hrtimer_pretimeout_init(struct watchdog_device *wdd) {} -static inline void watchdog_hrtimer_pretimeout_start(struct watchdog_device *wdd) {} -static inline void watchdog_hrtimer_pretimeout_stop(struct watchdog_device *wdd) {} -#endif diff --git a/drivers/watchdog/watchdog_hrtimer_pretimeout.c b/drivers/watchdog/watchdog_hrtimer_pretimeout.c deleted file mode 100644 index 940b53718a91e7..00000000000000 --- a/drivers/watchdog/watchdog_hrtimer_pretimeout.c +++ /dev/null @@ -1,44 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * (c) Copyright 2021 Hewlett Packard Enterprise Development LP. - */ - -#include -#include - -#include "watchdog_core.h" -#include "watchdog_pretimeout.h" - -static enum hrtimer_restart watchdog_hrtimer_pretimeout(struct hrtimer *timer) -{ - struct watchdog_core_data *wd_data; - - wd_data = container_of(timer, struct watchdog_core_data, pretimeout_timer); - - watchdog_notify_pretimeout(wd_data->wdd); - return HRTIMER_NORESTART; -} - -void watchdog_hrtimer_pretimeout_init(struct watchdog_device *wdd) -{ - struct watchdog_core_data *wd_data = wdd->wd_data; - - hrtimer_init(&wd_data->pretimeout_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); - wd_data->pretimeout_timer.function = watchdog_hrtimer_pretimeout; -} - -void watchdog_hrtimer_pretimeout_start(struct watchdog_device *wdd) -{ - if (!(wdd->info->options & WDIOF_PRETIMEOUT) && - !watchdog_pretimeout_invalid(wdd, wdd->pretimeout)) - hrtimer_start(&wdd->wd_data->pretimeout_timer, - ktime_set(wdd->timeout - wdd->pretimeout, 0), - HRTIMER_MODE_REL); - else - hrtimer_cancel(&wdd->wd_data->pretimeout_timer); -} - -void watchdog_hrtimer_pretimeout_stop(struct watchdog_device *wdd) -{ - hrtimer_cancel(&wdd->wd_data->pretimeout_timer); -} diff --git a/drivers/watchdog/watchdog_pretimeout.h b/drivers/watchdog/watchdog_pretimeout.h deleted file mode 100644 index a3f1abc68839aa..00000000000000 --- a/drivers/watchdog/watchdog_pretimeout.h +++ /dev/null @@ -1,61 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __WATCHDOG_PRETIMEOUT_H -#define __WATCHDOG_PRETIMEOUT_H - -#define WATCHDOG_GOV_NAME_MAXLEN 20 - -struct watchdog_device; - -struct watchdog_governor { - const char name[WATCHDOG_GOV_NAME_MAXLEN]; - void (*pretimeout)(struct watchdog_device *wdd); -}; - -#if IS_ENABLED(CONFIG_WATCHDOG_PRETIMEOUT_GOV) -/* Interfaces to watchdog pretimeout governors */ -int watchdog_register_governor(struct watchdog_governor *gov); -void watchdog_unregister_governor(struct watchdog_governor *gov); - -/* Interfaces to watchdog_dev.c */ -int watchdog_register_pretimeout(struct watchdog_device *wdd); -void watchdog_unregister_pretimeout(struct watchdog_device *wdd); -int watchdog_pretimeout_available_governors_get(char *buf); -int watchdog_pretimeout_governor_get(struct watchdog_device *wdd, char *buf); -int watchdog_pretimeout_governor_set(struct watchdog_device *wdd, - const char *buf); - -#if IS_ENABLED(CONFIG_WATCHDOG_PRETIMEOUT_DEFAULT_GOV_NOOP) -#define WATCHDOG_PRETIMEOUT_DEFAULT_GOV "noop" -#elif IS_ENABLED(CONFIG_WATCHDOG_PRETIMEOUT_DEFAULT_GOV_PANIC) -#define WATCHDOG_PRETIMEOUT_DEFAULT_GOV "panic" -#endif - -#else -static inline int watchdog_register_pretimeout(struct watchdog_device *wdd) -{ - return 0; -} - -static inline void watchdog_unregister_pretimeout(struct watchdog_device *wdd) -{ -} - -static inline int watchdog_pretimeout_available_governors_get(char *buf) -{ - return -EINVAL; -} - -static inline int watchdog_pretimeout_governor_get(struct watchdog_device *wdd, - char *buf) -{ - return -EINVAL; -} - -static inline int watchdog_pretimeout_governor_set(struct watchdog_device *wdd, - const char *buf) -{ - return -EINVAL; -} -#endif - -#endif