Watchdog: introdouce ARM SBSA watchdog driver
Subsystems (12)
Guenter Roeck
maintainerRe: [PATCH v3 4/6] Watchdog: introdouce "pretimeout" into framework
In reply to [email protected]Quoted 13 lines · On 05/25/2015 03:03 AM, [email protected] wrote:
From: Fu Wei <[email protected]>
Also update
Documentation/watchdog/watchdog-kernel-api.txtto introduce:
(1)the new elements in thewatchdog_deviceandwatchdog_opsstruct; (2)the new API "watchdog_init_timeouts"Reasons:
(1)kernel already has two watchdog drivers are using "pretimeout":
drivers/char/ipmi/ipmi_watchdog.cdrivers/watchdog/kempld_wdt.c(but the definition is different)
(2)some other drivers are going to use this: ARM SBSA Generic Watchdog
Quoted 4 lines
Acked-by Arnd Bergmann <[email protected]>Signed-off-by Fu Wei <[email protected]>---
Comments inline.
Thanks,
Guenter
Quoted 120 lines
Documentation/watchdog/watchdog-kernel-api.txt | 47 +++++++++++-- drivers/watchdog/watchdog_core.c | 95 +++++++++++++++++++------- drivers/watchdog/watchdog_dev.c | 50 ++++++++++++++ include/linux/watchdog.h | 33 ++++++++- 4 files changed, 192 insertions(+), 33 deletions(-)Documentation/watchdog/watchdog-kernel-api.txt +42
-5@@ -49,6 +49,9 @@ struct watchdog_device { unsigned int timeout; unsigned int min_timeout; unsigned int max_timeout; + unsigned int pretimeout; + unsigned int min_pretimeout; + unsigned int max_pretimeout; void *driver_data; struct mutex lock; unsigned long status;@@ -70,6 +73,9 @@ It contains following fields: * timeout: the watchdog timer's timeout value (in seconds). * min_timeout: the watchdog timer's minimum timeout value (in seconds). * max_timeout: the watchdog timer's maximum timeout value (in seconds). +* pretimeout: the watchdog timer's pretimeout value (in seconds). +* min_pretimeout: the watchdog timer's minimum pretimeout value (in seconds). +* max_pretimeout: the watchdog timer's maximum pretimeout value (in seconds). * bootstatus: status of the device after booting (reported with watchdog WDIOF_* status bits). * driver_data: a pointer to the drivers private data of a watchdog device.@@ -92,6 +98,7 @@ struct watchdog_ops { int (*ping)(struct watchdog_device *); unsigned int (*status)(struct watchdog_device *); int (*set_timeout)(struct watchdog_device *, unsigned int); + int (*set_pretimeout)(struct watchdog_device *, unsigned int); unsigned int (*get_timeleft)(struct watchdog_device *); void (*ref)(struct watchdog_device *); void (*unref)(struct watchdog_device *);@@ -153,9 +160,19 @@ they are supported. These optional routines/operations are: and -EIO for "could not write value to the watchdog". On success this routine should set the timeout value of the watchdog_device to the achieved timeout value (which may be different from the requested one - because the watchdog does not necessarily has a 1 second resolution). + because the watchdog does not necessarily has a 1 second resolution; + If the driver supports pretimeout, then the timeout value must be greater + than that). (Note: the WDIOF_SETTIMEOUT needs to be set in the options field of the watchdog's info structure). +* set_pretimeout: this routine checks and changes the pretimeout of the + watchdog timer device. It returns 0 on success, -EINVAL for "parameter out of + range" and -EIO for "could not write value to the watchdog". On success this + routine should set the pretimeout value of the watchdog_device to the + achieved pretimeout value (which may be different from the requested one + because the watchdog does not necessarily has a 1 second resolution). + (Note: the WDIOF_PRETIMEOUT needs to be set in the options field of the + watchdog's info structure). * get_timeleft: this routines returns the time that's left before a reset. * ref: the operation that calls kref_get on the kref of a dynamically allocated watchdog_device struct.@@ -219,8 +236,28 @@ extern int watchdog_init_timeout(struct watchdog_device *wdd, unsigned int timeout_parm, struct device *dev); The watchdog_init_timeout function allows you to initialize the timeout field -using the module timeout parameter or by retrieving the timeout-sec property from -the device tree (if the module timeout parameter is invalid). Best practice is -to set the default timeout value as timeout value in the watchdog_device and -then use this function to set the user "preferred" timeout value. +using the module timeout parameter or by retrieving the first element of +the timeout-sec property from the device tree (if the module timeout parameter +is invalid). Best practice is to set the default timeout value as timeout value +in the watchdog_device and then use this function to set the user "preferred" +timeout value. +This routine returns zero on success and a negative errno code for failure. + +Some watchdog timers have two stage of timeouts(timeout and pretimeout), +to initialize the timeout and pretimeout fields at the same time, the following +function can be used: + +extern int watchdog_init_timeouts(struct watchdog_device *wdd, + unsigned int pretimeout_parm, + unsigned int timeout_parm, + struct device *dev); + +The watchdog_init_timeouts function allows you to initialize the pretimeout and +timeout fields using the module pretimeout and timeout parameter or by +retrieving the elements in the timeout-sec property(the first element is for +timeout, the second one is for pretimeout) from the device tree(if the module +pretimeout and timeout parameter are invalid). +Best practice is to set the default pretimeout and timeout value as pretimeout +and timeout value in the watchdog_device and then use this function to set the +user "preferred" pretimeout value. This routine returns zero on success and a negative errno code for failure.drivers/watchdog/watchdog_core.c +9
-3@@ -43,60 +43,105 @@static DEFINE_IDA (watchdog_ida);static struct class *watchdog_class; -static void watchdog_check_min_max_timeout (struct watchdog_device *wdd) +static void watchdog_check_min_max_timeouts (struct watchdog_device *wdd) {/* -* Check that we have valid min and max timeout values, if -* not reset them both to 0 (=not used or unknown) +* Check that we have valid min and max pretimeout and timeout values, +* if not reset them both to 0 (=not used or unknown) */ +if (wdd->min_pretimeout > wdd->max_pretimeout) { +pr_info ("Invalid min and max pretimeout, resetting to 0\n" ); + wdd->min_pretimeout =0 ; + wdd->max_pretimeout =0 ; + }if (wdd->min_timeout > wdd->max_timeout) {pr_info ("Invalid min and max timeout values, resetting to 0!\n" ); wdd->min_timeout =0 ; wdd->max_timeout =0 ; } +/*
drivers/watchdog/watchdog_core.c line 72
Quoted 10 lines
drivers/watchdog/watchdog_core.c +10
-0+* Check that we have valid min and max timeout values, +* if not reset them both to pretimeout limits +*/ +if (wdd->min_pretimeout && wdd->min_timeout < wdd->min_pretimeout) { +pr_info ("Invalid min timeout, resetting to min pretimeout\n" ); + wdd->min_timeout = wdd->min_pretimeout; + } +if (wdd->max_pretimeout && wdd->max_timeout < wdd->max_pretimeout) { +pr_info ("Invalid max timeout, resetting to max pretimeout\n" ); + wdd->max_timeout = wdd->max_pretimeout;
I think you should rather update max_pretimeout in this case, to be < max_timeout.
Quoted 25 lines
drivers/watchdog/watchdog_core.c +9
-7+ } }/** -* watchdog_init_timeout() - initialize the timeout field +* watchdog_init_timeouts() - initialize the pretimeout and timeout field +* @pretimeout_parm: pretimeout module parameter * @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 -* 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 -* be the default timeout value. +* Initialize the pretimeout and timeout field of the watchdog_device struct +* with either the pretimeout and timeout module parameter (if it is valid +* value) or the timeout-sec property (only if it is a valid value and the +* pretimeout_parm and timeout_parm is out of bounds). If none of them are +* valid, then we keep the old value (which should normally be the default +* timeout value). * * A zero is returned on success and -EINVAL for failure. */ -int watchdog_init_timeout(struct watchdog_device *wdd,
drivers/watchdog/watchdog_core.c line 97
Quoted 10 lines
drivers/watchdog/watchdog_core.c +6
-3- unsigned int timeout_parm, struct device *dev) +int watchdog_init_timeouts (struct watchdog_device *wdd, +unsigned int pretimeout_parm, +unsigned int timeout_parm, +struct device *dev) { - unsigned int t = 0; -int ret =0 ; +u32 timeouts[2 ]; +int ret =0 , length =0 ;
Please keep the longest variable chain first.
Quoted 11 lines
drivers/watchdog/watchdog_core.c +4
-5-watchdog_check_min_max_timeout (wdd); +watchdog_check_min_max_timeouts (wdd); -/* try to get the timeout module parameter first */ -if (!watchdog_timeout_invalid (wdd, timeout_parm) && timeout_parm) { - wdd->timeout = timeout_parm; -return ret; +/* try to get the timeout and pretimeout module parameter first */ +if (pretimeout_parm) { +if (!watchdog_pretimeout_invalid (wdd, pretimeout_parm))
drivers/watchdog/watchdog_core.c line 112
Quoted 10 lines
drivers/watchdog/watchdog_core.c +8
-1+ wdd->pretimeout = pretimeout_parm; + else + ret = -EINVAL ; } -if (timeout_parm) + +if (timeout_parm) { +if (!watchdog_timeout_invalid (wdd, timeout_parm)) { + wdd->timeout = timeout_parm; +return ret;
This would return -EINVAL if timeout is correct but pretimeout isn't. How about this ?
if (!ret) return 0;
Quoted 11 lines
drivers/watchdog/watchdog_core.c +2
-4+ } ret = -EINVAL ; + }/* try to get the timeout_sec property */ if (dev ==NULL || dev->of_node ==NULL )return ret; -of_property_read_u32 (dev->of_node,"timeout-sec" , &t); -if (!watchdog_timeout_invalid (wdd, t) && t) - wdd->timeout = t; -else
drivers/watchdog/watchdog_core.c line 129
Quoted 10 lines
drivers/watchdog/watchdog_core.c +10
-0+ +of_find_property (dev->of_node,"timeout-sec" , &length); +if (length >0 && length <=sizeof (u32) *2 ) { +of_property_read_u32_array (dev->of_node, +"timeout-sec" , timeouts, + length /sizeof (u32)); +if (length ==2 ) { +if (!watchdog_pretimeout_invalid (wdd, timeouts[1 ]) && + timeouts[1 ]) + wdd->pretimeout = timeouts[1 ];
A pretimeout of 0 is a valid timeout, so why not use it ?
drivers/watchdog/watchdog_core.c line 130
Quoted 2 lines
drivers/watchdog/watchdog_core.c +2
-0+else + ret = -EINVAL ;
and why is pretimeout == 0 considered invalid here ?
Quoted 72 lines
drivers/watchdog/watchdog_core.c +10
-2+ } + +if (!watchdog_timeout_invalid (wdd, timeouts[0 ]) && timeouts[0 ]) + wdd->timeout = timeouts[0 ]; +else + ret = -EINVAL ; + }else { ret = -EINVAL ; + }return ret; } -EXPORT_SYMBOL_GPL (watchdog_init_timeout); +EXPORT_SYMBOL_GPL (watchdog_init_timeouts);/** * watchdog_register_device() - register a watchdog device @@ -119,7 +164,7 @@ int watchdog_register_device(struct watchdog_device *wdd)if (wdd->ops->start ==NULL || wdd->ops->stop ==NULL )return -EINVAL ; -watchdog_check_min_max_timeout (wdd); +watchdog_check_min_max_timeouts (wdd);/* * Note: now that all watchdog_device data has been verified, we drivers/watchdog/watchdog_dev.c +32
-0@@ -218,6 +218,38 @@ out_timeout: }/* +* watchdog_set_pretimeout: set the watchdog timer pretimeout +* @wddev: the watchdog device to set the timeout for +* @pretimeout: pretimeout to set in seconds +*/ + +static int watchdog_set_pretimeout (struct watchdog_device *wddev, +unsigned int pretimeout) +{ +int err; + +if (!wddev->ops->set_pretimeout || + !(wddev->info->options &WDIOF_PRETIMEOUT )) +return -EOPNOTSUPP ; + +if (watchdog_pretimeout_invalid (wddev, pretimeout)) +return -EINVAL ; + +mutex_lock (&wddev->lock); + +if (test_bit (WDOG_UNREGISTERED , &wddev->status)) { + err = -ENODEV ; + goto out_pretimeout; + } + + err = wddev->ops->set_pretimeout (wddev, pretimeout); + +out_pretimeout: +mutex_unlock (&wddev->lock); +return err; +} + +/* * watchdog_get_timeleft: wrapper to get the time left before a reboot * @wddev: the watchdog device to get the remaining time from * @timeleft: the time that's left @@ -388,6 +420,24 @@ static long watchdog_ioctl(struct file *file, unsigned int cmd,if (wdd->timeout ==0 )return -EOPNOTSUPP ;
drivers/watchdog/watchdog_dev.c static long watchdog_ioctl(struct file *file, unsigned int cmd, · line 431
Quoted 10 lines
drivers/watchdog/watchdog_dev.c +9
-0return put_user (wdd->timeout, p); +case WDIOC_SETPRETIMEOUT : +if (get_user (val, p)) +return -EFAULT ; + err =watchdog_set_pretimeout (wdd, val); +if (err <0 ) +return err; +/* +* If the watchdog is active then we send a keepalive ping +* to make sure that the watchdog keep's running (and if
s/keep's/keeps/
drivers/watchdog/watchdog_dev.c static long watchdog_ioctl(struct file *file, unsigned int cmd, · line 432
Quoted 1 line
drivers/watchdog/watchdog_dev.c +1
-0+* possible that it takes the new timeout)
new pretimeout
drivers/watchdog/watchdog_dev.c static long watchdog_ioctl(struct file *file, unsigned int cmd, · line 439
Quoted 7 lines
drivers/watchdog/watchdog_dev.c +7
-0+*/ +watchdog_ping (wdd); +/* Fall */ +case WDIOC_GETPRETIMEOUT : +/* pretimeout == 0 means that we don't know the pretimeout */ +if (wdd->pretimeout ==0 ) +return -EOPNOTSUPP ;
pretimeout == 0 is a valid parameter, though, and means that it is disabled. So we can not return -EOPNOTSUPP here.
Either this code needs to explicitly check for pretimeout support, or just return 0 if it is disabled / not supported.
Quoted 45 lines
drivers/watchdog/watchdog_dev.c +1
-0+return put_user (wdd->pretimeout, p);case WDIOC_GETTIMELEFT : err =watchdog_get_timeleft (wdd, &val);if (err)include/linux/watchdog.h +8
-0@@ -25,6 +25,7 @@ struct watchdog_device;* @ping: The routine that sends a keepalive ping to the watchdog device. * @status: The routine that shows the status of the watchdog device. * @set_timeout:The routine for setting the watchdog devices timeout value. +* @set_pretimeout:The routine for setting the watchdog devices pretimeout value * @get_timeleft:The routine that get's the time that's left before a reset. * @ref: The ref operation for dyn. allocated watchdog_device structs * @unref: The unref operation for dyn. allocated watchdog_device structs @@ -44,6 +45,7 @@ struct watchdog_ops {int (*ping)(struct watchdog_device *);unsigned int (*status)(struct watchdog_device *);int (*set_timeout)(struct watchdog_device *,unsigned int ); +int (*set_pretimeout)(struct watchdog_device *,unsigned int );unsigned int (*get_timeleft)(struct watchdog_device *);void (*ref)(struct watchdog_device *);void (*unref)(struct watchdog_device *);@@ -62,6 +64,9 @@ struct watchdog_ops {* @timeout: The watchdog devices timeout value. * @min_timeout:The watchdog devices minimum timeout value. * @max_timeout:The watchdog devices maximum timeout value. +* @pretimeout: The watchdog devices pretimeout value. +* @min_pretimeout:The watchdog devices minimum pretimeout value. +* @max_pretimeout:The watchdog devices maximum pretimeout value. * @driver-data:Pointer to the drivers private data. * @lock: Lock for watchdog core internal use only. * @status: Field that contains the devices internal status bits. @@ -86,6 +91,9 @@ struct watchdog_device {unsigned int timeout;unsigned int min_timeout;unsigned int max_timeout; +unsigned int pretimeout; +unsigned int min_pretimeout; +unsigned int max_pretimeout;void *driver_data;struct mutex lock;unsigned long status;
include/linux/watchdog.h static inline void watchdog_set_nowayout(struct watchdog_device *wdd, bool noway · line 129
Quoted 6 lines
include/linux/watchdog.h +2
-1@@ -117,7 +125,17 @@ static inline void watchdog_set_nowayout(struct watchdog_device *wdd, bool nowaystatic inline bool watchdog_timeout_invalid (struct watchdog_device *wdd,unsigned int t) {return ((wdd->max_timeout !=0 ) && - (t < wdd->min_timeout || t > wdd->max_timeout)); + (t < wdd->min_timeout || t > wdd->max_timeout || + t < wdd->pretimeout));
< or <= ?
timeout == pretimeout implies that the pretimeout would expire immediately, which doesn't seem to make much sense.
include/linux/watchdog.h static inline void watchdog_set_nowayout(struct watchdog_device *wdd, bool noway · line 138
Quoted 9 lines
include/linux/watchdog.h +9
-0+} + +/* 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 (wdd->max_pretimeout !=0 && + (t < wdd->min_pretimeout || t > wdd->max_pretimeout || + (wdd->timeout !=0 && t > wdd->timeout)));
> or >= ?
Quoted 17 lines
include/linux/watchdog.h +4
-2}/* Use the following functions to manipulate watchdog driver specific data */ @@ -132,11 +150,20 @@ static inline void *watchdog_get_drvdata(struct watchdog_device *wdd) }/* drivers/watchdog/watchdog_core.c */ -extern int watchdog_init_timeout (struct watchdog_device *wdd, -unsigned int timeout_parm,struct device *dev); +extern int watchdog_init_timeouts (struct watchdog_device *wdd, +unsigned int pretimeout_parm, +unsigned int timeout_parm, +struct device *dev);extern int watchdog_register_device (struct watchdog_device *);extern void watchdog_unregister_device (struct watchdog_device *);
include/linux/watchdog.h static inline void *watchdog_get_drvdata(struct watchdog_device *wdd) · line 169
Quoted 10 lines
include/linux/watchdog.h +7
-0+static inline int watchdog_init_timeout (struct watchdog_device *wdd, +unsigned int timeout_parm, +struct device *dev) +{ +return watchdog_init_timeouts (wdd,0 , timeout_parm, dev); +} +#ifdef CONFIG_HARDLOCKUP_DETECTOR void watchdog_nmi_disable_all (void );void watchdog_nmi_enable_all (void );
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Guenter Roeck
maintainerRe: [PATCH v3 5/6] Watchdog: introduce ARM SBSA watchdog driver
In reply to [email protected]Quoted 8 lines · On 05/25/2015 03:03 AM, [email protected] wrote:
From: Fu Wei <[email protected]>
This driver bases on linux kernel watchdog framework, and use "pretimeout" in the framework. It supports getting timeout and pretimeout from parameter and FDT at the driver init stage. In first timeout, the interrupt routine run panic to save system context.
Quoted 4 lines
Acked-by Arnd Bergmann <[email protected]>Signed-off-by Fu Wei <[email protected]>---
Comments inline.
Thanks,
Guenter
Quoted 118 lines
drivers/watchdog/Kconfig | 11 + drivers/watchdog/Makefile | 1 + drivers/watchdog/sbsa_gwdt.c | 474 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 486 insertions(+)create mode 100644
drivers/watchdog/sbsa_gwdt.cdrivers/watchdog/Kconfig +11
-0@@ -152,6 +152,17 @@ config ARM_SP805_WATCHDOG ARM Primecell SP805 Watchdog timer. This will reboot your system when the timeout is reached. +config ARM_SBSA_WATCHDOG + tristate "ARM SBSA Generic Watchdog" + depends on ARM64 + depends on ARM_ARCH_TIMER + select WATCHDOG_CORE + help + ARM SBSA Generic Watchdog. This watchdog has two Watchdog timeouts. + The first timeout will trigger a panic; the second timeout will + trigger a system reset. + More details: ARM DEN0029B - Server Base System Architecture (SBSA) + config AT91RM9200_WATCHDOG tristate "AT91RM9200 watchdog" depends on SOC_AT91RM9200 && MFD_SYSCONdrivers/watchdog/Makefile +1
-0@@ -30,6 +30,7 @@ obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o # ARM Architecture obj-$(CONFIG_ARM_SP805_WATCHDOG) += sp805_wdt.o +obj-$(CONFIG_ARM_SBSA_WATCHDOG) += sbsa_gwdt.o obj-$(CONFIG_AT91RM9200_WATCHDOG) += at91rm9200_wdt.o obj-$(CONFIG_AT91SAM9X_WATCHDOG) += at91sam9_wdt.o obj-$(CONFIG_CADENCE_WATCHDOG) += cadence_wdt.odrivers/watchdog/sbsa_gwdt.c new file +72
-0@@ -0,0 +1,474 @@ +/* +* SBSA(Server Base System Architecture) Generic Watchdog driver +* +* Copyright (c) 2015, Linaro Ltd. +* Author: Fu Wei <[email protected]> +* Suravee Suthikulpanit <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License 2 as published +* by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* Note: This SBSA Generic watchdog driver is compatible with +* the pretimeout concept of Linux kernel. +* The timeout and pretimeout are set by the different REGs. +* The first watch period is set by writing WCV directly, +* that can support more than 10s timeout at the maximum +* system counter frequency. +* The second watch period is set by WOR(32bit) which will be loaded +* automatically by hardware, when WS0 is triggered. +* This gives a maximum watch period of around 10s at the maximum +* system counter frequency. +* The System Counter shall run at maximum of 400MHz. +* More details: ARM DEN0029B - Server Base System Architecture (SBSA) +* +* Kernel/API: P---------| pretimeout +* |-------------------------------T timeout +* SBSA GWDT: P--WOR---WS1 pretimeout +* |-------WCV----------WS0~~~~~~~~T timeout +*/ + +#include <linux/io.h> +#include <linux/interrupt.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/of.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/uaccess.h> +#include <linux/watchdog.h> +#include <asm/arch_timer.h> + +/* SBSA Generic Watchdog register definitions */ +/* refresh frame */ +#define SBSA_GWDT_WRR 0x000 + +/* control frame */ +#define SBSA_GWDT_WCS 0x000 +#define SBSA_GWDT_WOR 0x008 +#define SBSA_GWDT_WCV_LO 0x010 +#define SBSA_GWDT_WCV_HI 0x014 + +/* refresh/control frame */ +#define SBSA_GWDT_W_IIDR 0xfcc +#define SBSA_GWDT_IDR 0xfd0 + +/* Watchdog Control and Status Register */ +#define SBSA_GWDT_WCS_EN BIT(0) +#define SBSA_GWDT_WCS_WS0 BIT(1) +#define SBSA_GWDT_WCS_WS1 BIT(2) + +/** +* struct sbsa_gwdt - Internal representation of the SBSA GWDT +* @wdd: kernel watchdog_device structure +* @clk: store the System Counter clock frequency, in Hz. +* @refresh_base: Virtual address of the watchdog refresh frame +* @control_base: Virtual address of the watchdog control frame +*/
drivers/watchdog/sbsa_gwdt.c line 82
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+struct sbsa_gwdt { +struct watchdog_device wdd; +u32 clk; +void __iomem *refresh_base; +void __iomem *control_base; +}; + +#define to_sbsa_gwdt (e) container_of(e, struct sbsa_gwdt, wdd) + +#define DEFAULT_TIMEOUT 10/* seconds, the 1st + 2nd watch periods*/
That is a bit low for a default. Is that on purpose ? Most drivers use 30 or 60 seconds.
drivers/watchdog/sbsa_gwdt.c line 90
Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c new file +8
-0+#define DEFAULT_PRETIMEOUT 5/* seconds, the 2nd watch period*/ + +static unsigned int timeout_param; +module_param (timeout_param, uint,0 ); +MODULE_PARM_DESC (timeout_param, + "Watchdog timeout in seconds. (>=0, default=" + __MODULE_STRING(DEFAULT_TIMEOUT) ")"); +
Why _param in the module parameter names ? Seems to be redundant.
drivers/watchdog/sbsa_gwdt.c line 96
Quoted 6 lines
drivers/watchdog/sbsa_gwdt.c new file +6
-0+static unsigned int max_timeout_param =UINT_MAX ; +module_param (max_timeout_param, uint,0 ); +MODULE_PARM_DESC (max_timeout_param, + "Watchdog max timeout in seconds. (>=0, default=" + __MODULE_STRING(UINT_MAX) ")"); +
Why do we want or need this parameter and max_pretimeout ? Those are determined by the hardware.
Quoted 87 lines
drivers/watchdog/sbsa_gwdt.c new file +87
-0+static unsigned int pretimeout_param; +module_param (pretimeout_param, uint,0 ); +MODULE_PARM_DESC (pretimeout_param, + "Watchdog pretimeout in seconds. (>=0, default=" + __MODULE_STRING(DEFAULT_PRETIMEOUT) ")"); + +static unsigned int max_pretimeout_param =U32_MAX ; +module_param (max_pretimeout_param, uint,0 ); +MODULE_PARM_DESC (max_pretimeout_param, + "Watchdog max pretimeout in seconds. (>=0, default=" + __MODULE_STRING(U32_MAX) ")"); + +static bool nowayout =WATCHDOG_NOWAYOUT ; +module_param (nowayout, bool,S_IRUGO ); +MODULE_PARM_DESC (nowayout, + "Watchdog cannot be stopped once started (default=" + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +/* +* help functions for accessing 32bit registers of SBSA Generic Watchdog +*/ +static void sbsa_gwdt_cf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (val, gwdt->control_base + reg); +} + +static void sbsa_gwdt_rf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (val, gwdt->refresh_base + reg); +} + +static u32 sbsa_gwdt_cf_read (unsigned int reg,struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +return readl_relaxed (gwdt->control_base + reg); +} + +/* +* help functions for accessing 64bit WCV register +*/ +static u64 sbsa_gwdt_get_wcv (struct watchdog_device *wdd) +{ +u32 wcv_lo, wcv_hi; + +do { + wcv_hi =sbsa_gwdt_cf_read (SBSA_GWDT_WCV_HI , wdd); + wcv_lo =sbsa_gwdt_cf_read (SBSA_GWDT_WCV_LO , wdd); + }while (wcv_hi !=sbsa_gwdt_cf_read (SBSA_GWDT_WCV_HI , wdd)); + +return (((u64 )wcv_hi <<32 ) | wcv_lo); +} + +static void sbsa_gwdt_set_wcv (struct watchdog_device *wdd,u64 value) +{ +u32 wcv_lo, wcv_hi; + + wcv_lo = value &U32_MAX ; + wcv_hi = (value >>32 ) &U32_MAX ; + +sbsa_gwdt_cf_write (SBSA_GWDT_WCV_HI , wcv_hi, wdd); +sbsa_gwdt_cf_write (SBSA_GWDT_WCV_LO , wcv_lo, wdd); +} + +static void reload_timeout_to_wcv (struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); +u64 wcv; + + wcv =arch_counter_get_cntvct () + + (u64)(wdd->timeout - wdd->pretimeout) * gwdt->clk; + +sbsa_gwdt_set_wcv (wdd, wcv); +} + +/* +* Use the following function to update the timeout limits +* after updating pretimeout +*/ +static void sbsa_gwdt_update_limits (struct watchdog_device *wdd) +{
drivers/watchdog/sbsa_gwdt.c line 193
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); +u64 first_period_max =U64_MAX ; + +do_div (first_period_max, gwdt->clk); + + wdd->min_timeout = wdd->pretimeout +1 ; + wdd->max_timeout =min ((uint)(wdd->pretimeout + first_period_max), + wdd->max_timeout); +} +
After understanding the watchdog a bit better now, I think you should drop those updates and set
min_timeout = 1
max_timeout = min(UINT_MAX, U64_MAX / clk) min_pretimeout = 0
max_pretimeout = U32_MAX / clk
and then ensure that pretimeout < timeout at runtime (if possible in the infrastructure code).
Even at maximum clock rate, max_timeout is so large that anything else is really overkill.
Quoted 13 lines
drivers/watchdog/sbsa_gwdt.c new file +13
-0+static int sbsa_gwdt_set_timeout (struct watchdog_device *wdd, +unsigned int timeout) +{ + wdd->timeout = timeout; + +return 0 ; +} + +static int sbsa_gwdt_set_pretimeout (struct watchdog_device *wdd, +unsigned int pretimeout) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); +u32 wor;
drivers/watchdog/sbsa_gwdt.c line 216
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+ + wdd->pretimeout = pretimeout; +sbsa_gwdt_update_limits (wdd); + +if (!pretimeout) +/* gives sbsa_gwdt_start a chance to setup timeout */ + wor = gwdt->clk; +else + wor = pretimeout * gwdt->clk; +
So in practice you always have a pretimeout of at least one second, correct ? That kind of violates the ABI, which says that the pretimeout should be disabled if set to 0. Is there anything we can do about that ?
What exactly happens if WOR = 0 ? Doesn't that just mean that the second timeout will happen immediately, and isn't that what we would want if pretimeout = 0 ?
drivers/watchdog/sbsa_gwdt.c line 217
Quoted 1 line
drivers/watchdog/sbsa_gwdt.c new file +1
-0+/* refresh the WOR, that will cause an explicit watchdog refresh */
Except that we use wcv which needs a manual refresh, so this is a bit misleading, isn't it ?
Quoted 34 lines
drivers/watchdog/sbsa_gwdt.c new file +34
-0+sbsa_gwdt_cf_write (SBSA_GWDT_WOR , wor, wdd); + +return 0 ; +} + +static unsigned int sbsa_gwdt_get_timeleft (struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); +u64 timeleft =sbsa_gwdt_get_wcv (wdd) -arch_counter_get_cntvct (); + +do_div (timeleft, gwdt->clk); + +return timeleft; +} + +static int sbsa_gwdt_start (struct watchdog_device *wdd) +{ +/* Force refresh */ +sbsa_gwdt_rf_write (SBSA_GWDT_WRR ,0xc0ffee , wdd); +/* writing WCS will cause an explicit watchdog refresh */ +sbsa_gwdt_cf_write (SBSA_GWDT_WCS ,SBSA_GWDT_WCS_EN , wdd); + +reload_timeout_to_wcv (wdd); + +return 0 ; +} + +static int sbsa_gwdt_stop (struct watchdog_device *wdd) +{ +/* Force refresh */ +sbsa_gwdt_rf_write (SBSA_GWDT_WRR ,0xc0ffee , wdd); +/* writing WCS will cause an explicit watchdog refresh */ +sbsa_gwdt_cf_write (SBSA_GWDT_WCS ,0 , wdd); +
drivers/watchdog/sbsa_gwdt.c line 261
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+return 0 ; +} + +static int sbsa_gwdt_keepalive (struct watchdog_device *wdd) +{ +/* +* Writing WRR for an explicit watchdog refresh +* You can write anyting(like 0xc0ffee) +*/ +sbsa_gwdt_rf_write (SBSA_GWDT_WRR ,0xc0ffee , wdd);
Should that happen after writing wcv ?
Quoted 46 lines
drivers/watchdog/sbsa_gwdt.c new file +46
-0+ +reload_timeout_to_wcv (wdd); + +return 0 ; +} + +static irqreturn_t sbsa_gwdt_interrupt (int irq,void *dev_id) +{ +struct sbsa_gwdt *gwdt = (struct sbsa_gwdt *)dev_id; +struct watchdog_device *wdd = &gwdt->wdd; +u32 status; + + status =sbsa_gwdt_cf_read (SBSA_GWDT_WCS , wdd); + +if (status &SBSA_GWDT_WCS_WS0 ) +panic ("SBSA Watchdog pre-timeout" ); + +return IRQ_HANDLED ; +} + +static struct watchdog_info sbsa_gwdt_info = { + .identity ="SBSA Generic Watchdog" , + .options =WDIOF_SETTIMEOUT | +WDIOF_KEEPALIVEPING | +WDIOF_MAGICCLOSE | +WDIOF_PRETIMEOUT | +WDIOF_CARDRESET , +}; + +static struct watchdog_ops sbsa_gwdt_ops = { + .owner =THIS_MODULE , + .start = sbsa_gwdt_start, + .stop = sbsa_gwdt_stop, + .ping = sbsa_gwdt_keepalive, + .set_timeout = sbsa_gwdt_set_timeout, + .set_pretimeout = sbsa_gwdt_set_pretimeout, + .get_timeleft = sbsa_gwdt_get_timeleft, +}; + +static int sbsa_gwdt_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct sbsa_gwdt *gwdt; +struct watchdog_device *wdd; +struct resource *res; +void *rf_base, *cf_base;
drivers/watchdog/sbsa_gwdt.c line 317
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+int irq; +u32 clk, status; +int ret =0 ; +u64 first_period_max =U64_MAX ; + +/* +* Get the frequency of system counter from +* the cp15 interface of ARM Generic timer +*/ + clk =arch_timer_get_cntfrq ();
That can not return 0, presumably, from looking into its implementation. And the system should panic if it is ever 0.
drivers/watchdog/sbsa_gwdt.c line 318
Quoted 1 line
drivers/watchdog/sbsa_gwdt.c new file +1
-0+if (!clk) {
Given that, I don't think this check is necessary.
Quoted 31 lines
drivers/watchdog/sbsa_gwdt.c new file +31
-0+dev_err (dev,"System Counter frequency not available\n" ); +return -EINVAL ; + } + + gwdt =devm_kzalloc (dev,sizeof (*gwdt),GFP_KERNEL ); +if (!gwdt) +return -ENOMEM ; + + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"refresh" ); + rf_base =devm_ioremap_resource (dev, res); +if (IS_ERR (rf_base)) +return PTR_ERR (rf_base); + + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"control" ); + cf_base =devm_ioremap_resource (dev, res); +if (IS_ERR (cf_base)) +return PTR_ERR (cf_base); + + irq =platform_get_irq_byname (pdev,"ws0" ); +if (irq <0 ) { +dev_err (dev,"unable to get ws0 interrupt.\n" ); +return irq; + } + + gwdt->refresh_base = rf_base; + gwdt->control_base = cf_base; + gwdt->clk = clk; + +platform_set_drvdata (pdev, gwdt); + + wdd = &gwdt->wdd;
drivers/watchdog/sbsa_gwdt.c line 359
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+ wdd->parent = dev; + wdd->info = &sbsa_gwdt_info; + wdd->ops = &sbsa_gwdt_ops; +watchdog_set_drvdata (wdd, gwdt); +watchdog_set_nowayout (wdd, nowayout); + + status =sbsa_gwdt_cf_read (SBSA_GWDT_WCS , wdd); +if (status &SBSA_GWDT_WCS_WS1 ) { +dev_warn (dev,"System reset by WDT(WCS: %x, WCV: %llx)\n" , + status,sbsa_gwdt_get_wcv (wdd));
Does this message (specifically the WCS / WCV values) have any useful meaning for the user ?
drivers/watchdog/sbsa_gwdt.c line 365
Quoted 6 lines
drivers/watchdog/sbsa_gwdt.c new file +6
-0+ wdd->bootstatus |=WDIOF_CARDRESET ; + } +/* Check if watchdog is already enabled */ +if (status &SBSA_GWDT_WCS_EN ) { +dev_warn (dev,"already enabled! WCS:0x%x\n" , status); +sbsa_gwdt_keepalive (wdd);
You have not configured wdd->timeout and wdd->pretimeout here, yet the function calls reload_timeout_to_wcv which needs it.
Quoted 4 lines
drivers/watchdog/sbsa_gwdt.c new file +4
-0+ } + + wdd->min_pretimeout =0 ; + wdd->max_pretimeout =min (U32_MAX / clk, max_pretimeout_param);
drivers/watchdog/sbsa_gwdt.c line 379
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+ wdd->min_timeout =1 ; +do_div (first_period_max, clk); + wdd->max_timeout =min ((uint)(wdd->pretimeout + first_period_max), + max_timeout_param); + + wdd->pretimeout =DEFAULT_PRETIMEOUT ; + wdd->timeout =DEFAULT_TIMEOUT ; +watchdog_init_timeouts (wdd, pretimeout_param, timeout_param, dev); +/* update pretimeout to WOR */ +sbsa_gwdt_cf_write (SBSA_GWDT_WOR , wdd->pretimeout * clk, wdd);
This is interesting because you set WOR to 0 here if pretimeout is 0. Yet, when pretimeout is updated later on, you always set it to at least one second. Any reason for doing this differently ?
If the above works, and presumably you have tested it, I don't see why it would be necessary to set WOR to a value larger than 0 when updating pretimeout.
Quoted 4 lines
drivers/watchdog/sbsa_gwdt.c new file +4
-0+ + ret =devm_request_irq (dev, irq, sbsa_gwdt_interrupt,IRQF_TIMER , + pdev->name, gwdt); +if (ret) {
drivers/watchdog/sbsa_gwdt.c line 393
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+dev_err (dev,"unable to request IRQ %d\n" , irq); +return ret; + } + + ret =watchdog_register_device (wdd); +if (ret) +return ret; + +dev_info (dev,"Initialized with %ds timeout, %ds pretimeout @ %uHz\n" , + wdd->timeout, wdd->pretimeout, gwdt->clk);
400000Hz reads a bit odd. How about a space between the number and Hz ?
Quoted 9 lines
drivers/watchdog/sbsa_gwdt.c new file +9
-0+ +return 0 ; +} + +static void sbsa_gwdt_shutdown (struct platform_device *pdev) +{ +struct sbsa_gwdt *gwdt =platform_get_drvdata (pdev); + +sbsa_gwdt_stop (&gwdt->wdd);
drivers/watchdog/sbsa_gwdt.c line 412
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+} + +static int sbsa_gwdt_remove (struct platform_device *pdev) +{ +struct sbsa_gwdt *gwdt =platform_get_drvdata (pdev); +int ret =0 ; + +if (!nowayout) + ret =sbsa_gwdt_stop (&gwdt->wdd); +
I don't think you should do anything here. The driver can only be removed if closed, and it that case the watchdog will already have been stopped, or if nowayout was set it won't be stopped. Either case it is already in the state we want it to be in.
Quoted 53 lines
drivers/watchdog/sbsa_gwdt.c new file +52
-0+watchdog_unregister_device (&gwdt->wdd); + +return ret; +} + +/* Disable watchdog if it is active during suspend */ +static int __maybe_unused sbsa_gwdt_suspend (struct device *dev) +{ +struct sbsa_gwdt *gwdt =dev_get_drvdata (dev); + +if (watchdog_active (&gwdt->wdd)) +sbsa_gwdt_stop (&gwdt->wdd); + +return 0 ; +} + +/* Enable watchdog and configure it if necessary */ +static int __maybe_unused sbsa_gwdt_resume (struct device *dev) +{ +struct sbsa_gwdt *gwdt =dev_get_drvdata (dev); + +if (watchdog_active (&gwdt->wdd)) +sbsa_gwdt_start (&gwdt->wdd); + +return 0 ; +} + +static const struct dev_pm_ops sbsa_gwdt_pm_ops = { +SET_SYSTEM_SLEEP_PM_OPS (sbsa_gwdt_suspend, sbsa_gwdt_resume) +}; + +static const struct of_device_id sbsa_gwdt_of_match[] = { + { .compatible ="arm,sbsa-gwdt" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, sbsa_gwdt_of_match); + +static const struct platform_device_id sbsa_gwdt_pdev_match[] = { + { .name ="sbsa-gwdt" , }, + {}, +}; +MODULE_DEVICE_TABLE (platform, sbsa_gwdt_pdev_match); + +static struct platform_driver sbsa_gwdt_driver = { + .driver = { + .name ="sbsa-gwdt" , + .pm = &sbsa_gwdt_pm_ops, + .of_match_table = sbsa_gwdt_of_match, + }, + .probe = sbsa_gwdt_probe, + .remove = sbsa_gwdt_remove, + .shutdown = sbsa_gwdt_shutdown,
drivers/watchdog/sbsa_gwdt.c line 474
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+ .id_table = sbsa_gwdt_pdev_match, +}; + +module_platform_driver (sbsa_gwdt_driver); + +MODULE_DESCRIPTION ("SBSA Generic Watchdog Driver" ); +MODULE_VERSION ("v1.0" ); +MODULE_AUTHOR ("Fu Wei <[email protected]>" ); +MODULE_AUTHOR ("Suravee Suthikulpanit <[email protected]>" ); +MODULE_LICENSE ("GPL v2" );
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 6/6] ACPI: import watchdog info of GTDT into platform device
In reply to [email protected]Hi Fu Wei,
Some minor comments inline.
Quoted 27 lines · On 2015年05月25日 18:03, [email protected] wrote:
From: Fu Wei <[email protected]>
Parse SBSA Generic Watchdog Structure in GTDT table of ACPI, and create a platform device with that information. This platform device can be used by the ARM SBSA Generic Watchdog driver.
Tested-by Timur Tabi <[email protected]>Signed-off-by Fu Wei <[email protected]>--- arch/arm64/kernel/acpi.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+)arch/arm64/kernel/acpi.c +1
-0@@ -23,6 +23,7 @@#include <linux/irqdomain.h> #include <linux/memblock.h> #include <linux/of_fdt.h> +#include <linux/platform_device.h> #include <linux/smp.h> #include <asm/cputype.h>
arch/arm64/kernel/acpi.c void __init acpi_gic_init(void) · line 346
Quoted 3 lines
arch/arm64/kernel/acpi.c +0
-0@@ -343,3 +344,147 @@ void __init acpi_gic_init(void)early_acpi_os_unmap_memory ((char *)table, tbl_size); }
please add
#ifdef CONFIG_ARM_SBSA_WATCHDOG
(acpi gtdt code)
#endif
Quoted 32 lines
arch/arm64/kernel/acpi.c +32
-0+ +static int __init acpi_gtdt_import_sbsa_gwdt (struct acpi_gtdt_watchdog *wd, +int index) +{ +struct platform_device *pdev; +struct resource *res; +u32 gsi, flags; +int irq, trigger, polarity; +resource_size_t rf_base_phy, cf_base_phy; +int err = -ENOMEM ; + +/* +* Get SBSA Generic Watchdog info +* from a Watchdog GT type structure in GTDT +*/ + rf_base_phy = (resource_size_t )wd->refresh_frame_address; + cf_base_phy = (resource_size_t )wd->control_frame_address; + gsi = wd->timer_interrupt; + flags = wd->timer_flags; + +pr_debug ("GTDT: a Watchdog GT structure(0x%llx/0x%llx gsi:%u flags:0x%x)\n" , + rf_base_phy, cf_base_phy, gsi, flags); + +if (!(rf_base_phy && cf_base_phy && gsi)) { +pr_err ("GTDT: failed geting the device info.\n" ); +return -EINVAL ; + } + + trigger = (flags &ACPI_GTDT_INTERRUPT_MODE ) ?ACPI_EDGE_SENSITIVE + :ACPI_LEVEL_SENSITIVE ; + polarity = (flags &ACPI_GTDT_INTERRUPT_POLARITY ) ?ACPI_ACTIVE_LOW + :ACPI_ACTIVE_HIGH ;
arch/arm64/kernel/acpi.c void __init acpi_gic_init(void) · line 388
Quoted 10 lines
arch/arm64/kernel/acpi.c +10
-0+ irq =acpi_register_gsi (NULL , gsi, trigger, polarity); +if (irq <0 ) { +pr_err ("GTDT: failed to register GSI of the Watchdog GT.\n" ); +return -EINVAL ; + } + +/* +* Add a platform device named "sbsa-gwdt" to match the platform driver. +* "sbsa-gwdt": SBSA(Server Base System Architecture) Generic Watchdog +* The platform driver can get device info below by matching this name.
* The platform driver (drivers/watchdog/sbsa_gwdt.c) can get device info below by matching this name.
Adding the file name which will help for review and maintain in my opinion.
Quoted 33 lines
arch/arm64/kernel/acpi.c +33
-0+*/ + pdev =platform_device_alloc ("sbsa-gwdt" , index); +if (!pdev) + goto err_unregister_gsi; + + res =kcalloc (3 ,sizeof (*res),GFP_KERNEL ); +if (!res) + goto err_device_put; + +/* +* According to SBSA specification the size of refresh and control +* frames of SBSA Generic Watchdog is SZ_4K(Offset 0x000 – 0xFFF). +*/ + res[0 ].start = rf_base_phy; + res[0 ].end = rf_base_phy +SZ_4K -1 ; + res[0 ].name ="refresh" ; + res[0 ].flags =IORESOURCE_MEM ; + + res[1 ].start = cf_base_phy; + res[1 ].end = cf_base_phy +SZ_4K -1 ; + res[1 ].name ="control" ; + res[1 ].flags =IORESOURCE_MEM ; + + res[2 ].start = irq; + res[2 ].end = res[2 ].start; + res[2 ].name ="ws0" ; + res[2 ].flags =IORESOURCE_IRQ ; + + err =platform_device_add_resources (pdev, res,3 ); +if (err) + goto err_free_res; + + err =platform_device_add (pdev);
...
arch/arm64/kernel/acpi.c void __init acpi_gic_init(void) · line 425
Quoted 4 lines
arch/arm64/kernel/acpi.c +4
-0+if (err) + goto err_free_res; + +return 0 ;
How about
if (!err)
return 0;
then no need for goto err_free_res and save two lines of codes.
Other than that,
Thanks
Hanjun
Re: [PATCH v3 6/6] ACPI: import watchdog info of GTDT into platform device
In reply to [email protected]Quoted 7 lines · On Mon, May 25, 2015 at 11:03:13AM +0100…
From: Fu Wei <[email protected]>
Parse SBSA Generic Watchdog Structure in GTDT table of ACPI, and create a platform device with that information. This platform device can be used by the ARM SBSA Generic Watchdog driver.
Quoted 6 lines
Tested-by Timur Tabi <[email protected]>Signed-off-by Fu Wei <[email protected]>--- arch/arm64/kernel/acpi.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+)
Why does this all need to be under arch/arm64? The GTDT really isn't architecture-specific, so I'd *much* rather it was parsed in the driver code itself, like we already do for the architected timer. The GIC is an exception because it's in the MADT, which we need to parse in the arch code to configure SMP properly.
Will
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 6/6] ACPI: import watchdog info of GTDT into platform device
Hi Will,
Quoted 15 lines · Will Deacon
Quoted 7 lines · On Mon, May 25, 2015 at 11:03:13AM +0100, [email protected] wrote:
From: Fu Wei <[email protected]>
Parse SBSA Generic Watchdog Structure in GTDT table of ACPI, and create a platform device with that information. This platform device can be used by the ARM SBSA Generic Watchdog driver.
Quoted 6 lines
Tested-by Timur Tabi <[email protected]>Signed-off-by Fu Wei <[email protected]>--- arch/arm64/kernel/acpi.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+)
Quoted 5 lines
Why does this all need to be under
arch/arm64? The GTDT really isn't architecture-specific, so I'd *much* rather it was parsed in the driver code itself, like we already do for the architected timer. The GIC is an exception because it's in the MADT, which we need to parse in the arch code to configure SMP properly.
I'm not really against refactoring the code. But the GTDT looks quite specific to ARM..
---8<----
5.2.24 Generic Timer Description Table (GTDT)
This section describes the format of the Generic Timer Description Table (GTDT), which provides
OSPM with information about a system’s Generic Timers configuration. The Generic Timer (GT) is
a standard timer interface implemented on ARM processor-based systems. The GT hardware
specification can be found at Links to ACPI-Related Documents
(http://uefi.org/acpi) under the
heading ARM Architecture. The GTDT provides OSPM with information about a system's GT
interrupt configurations, for both per-processor timers, and platform (memory-mapped) timers.
The GT specification defines the following per-processor timers:
• Secure privilege level 1 (EL1) timer,
• Non-Secure EL1 timer,
• Non-Secure privilege level 2 (EL2) timer,
• Virtual timer,
and the following Platform (memory-mapped) timers.
• GT Block
• Server Base System Architecture (SBSA) Generic Watchdog ---8<----
Thanks,
Ashwin.
Re: [PATCH v3 6/6] ACPI: import watchdog info of GTDT into platform device
Quoted 40 lines · Ashwin Chaugule
Quoted 15 lines · Will Deacon
Quoted 7 lines · On Mon, May 25, 2015 at 11:03:13AM +0100, [email protected] wrote:
From: Fu Wei <[email protected]>
Parse SBSA Generic Watchdog Structure in GTDT table of ACPI, and create a platform device with that information. This platform device can be used by the ARM SBSA Generic Watchdog driver.
Quoted 6 lines
Tested-by Timur Tabi <[email protected]>Signed-off-by Fu Wei <[email protected]>--- arch/arm64/kernel/acpi.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+)Quoted 5 lines
Why does this all need to be under
arch/arm64? The GTDT really isn't architecture-specific, so I'd *much* rather it was parsed in the driver code itself, like we already do for the architected timer. The GIC is an exception because it's in the MADT, which we need to parse in the arch code to configure SMP properly.I'm not really against refactoring the code. But the GTDT looks quite specific to ARM..
---8<----
5.2.24 Generic Timer Description Table (GTDT)
This section describes the format of the Generic Timer Description Table (GTDT), which provides
OSPM with information about a system’s Generic Timers configuration. The Generic Timer (GT) is
a standard timer interface implemented on ARM processor-based systems. The GT hardware
specification can be found at Links to ACPI-Related Documents
(http://uefi.org/acpi) under the
heading ARM Architecture. The GTDT provides OSPM with information about a system's GT
interrupt configurations, for both per-processor timers, and platform (memory-mapped) timers.
The GT specification defines the following per-processor timers:
Quoted 8 lines
• Secure privilege level 1 (EL1) timer,
• Non-Secure EL1 timer,
• Non-Secure privilege level 2 (EL2) timer,
• Virtual timer,
and the following Platform (memory-mapped) timers.
• GT Block
• Server Base System Architecture (SBSA) Generic Watchdog ---8<----
Sure, the device it describes may only ever exist on ARM systems, but by that logic then we should be moving lots of drivers back under arch/arm[64].
The ARM architecture says precisely *nothing* about ACPI, so we should try to keep arch/arm64/kernel/acpi.c to a minimum and not shovel all sorts of table conversion code in there for random peripherals.
Will
Re: [PATCH v3 6/6] ACPI: import watchdog info of GTDT into platform device
Quoted 50 lines · Will Deacon
Quoted 40 lines · Ashwin Chaugule
Quoted 15 lines · Will Deacon
Quoted 7 lines · On Mon, May 25, 2015 at 11:03:13AM +0100, [email protected] wrote:
From: Fu Wei <[email protected]>
Parse SBSA Generic Watchdog Structure in GTDT table of ACPI, and create a platform device with that information. This platform device can be used by the ARM SBSA Generic Watchdog driver.
Quoted 6 lines
Tested-by Timur Tabi <[email protected]>Signed-off-by Fu Wei <[email protected]>--- arch/arm64/kernel/acpi.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+)Quoted 5 lines
Why does this all need to be under
arch/arm64? The GTDT really isn't architecture-specific, so I'd *much* rather it was parsed in the driver code itself, like we already do for the architected timer. The GIC is an exception because it's in the MADT, which we need to parse in the arch code to configure SMP properly.I'm not really against refactoring the code. But the GTDT looks quite specific to ARM..
---8<----
5.2.24 Generic Timer Description Table (GTDT)
This section describes the format of the Generic Timer Description Table (GTDT), which provides
OSPM with information about a system’s Generic Timers configuration. The Generic Timer (GT) is
a standard timer interface implemented on ARM processor-based systems. The GT hardware
specification can be found at Links to ACPI-Related Documents
(http://uefi.org/acpi) under the
heading ARM Architecture. The GTDT provides OSPM with information about a system's GT
interrupt configurations, for both per-processor timers, and platform (memory-mapped) timers.
The GT specification defines the following per-processor timers:Quoted 8 lines
• Secure privilege level 1 (EL1) timer,
• Non-Secure EL1 timer,
• Non-Secure privilege level 2 (EL2) timer,
• Virtual timer,
and the following Platform (memory-mapped) timers.
• GT Block
• Server Base System Architecture (SBSA) Generic Watchdog ---8<----
Quoted 2 lines
Sure, the device it describes may only ever exist on ARM systems, but by that logic then we should be moving lots of drivers back under arch/arm[64].
Sure. Not arguing about that. :) You said the GTDT isn't really arch specific. That was a bit confusing.
Quoted 6 lines
The ARM architecture says precisely *nothing* about ACPI, so we should try to keep
arch/arm64/kernel/acpi.cto a minimum and not shovel all sorts of table conversion code in there for random peripherals.Will
Guenter Roeck
maintainerRe: [PATCH v3 6/6] ACPI: import watchdog info of GTDT into platform device
In reply to Will DeaconQuoted 50 lines · Will Deacon
Quoted 40 lines · Ashwin Chaugule
Quoted 15 lines · Will Deacon
Quoted 7 lines · On Mon, May 25, 2015 at 11:03:13AM +0100, [email protected] wrote:
From: Fu Wei <[email protected]>
Parse SBSA Generic Watchdog Structure in GTDT table of ACPI, and create a platform device with that information. This platform device can be used by the ARM SBSA Generic Watchdog driver.
Quoted 6 lines
Tested-by Timur Tabi <[email protected]>Signed-off-by Fu Wei <[email protected]>--- arch/arm64/kernel/acpi.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+)Quoted 5 lines
Why does this all need to be under
arch/arm64? The GTDT really isn't architecture-specific, so I'd *much* rather it was parsed in the driver code itself, like we already do for the architected timer. The GIC is an exception because it's in the MADT, which we need to parse in the arch code to configure SMP properly.I'm not really against refactoring the code. But the GTDT looks quite specific to ARM..
---8<----
5.2.24 Generic Timer Description Table (GTDT)
This section describes the format of the Generic Timer Description Table (GTDT), which provides
OSPM with information about a system’s Generic Timers configuration. The Generic Timer (GT) is
a standard timer interface implemented on ARM processor-based systems. The GT hardware
specification can be found at Links to ACPI-Related Documents
(http://uefi.org/acpi) under the
heading ARM Architecture. The GTDT provides OSPM with information about a system's GT
interrupt configurations, for both per-processor timers, and platform (memory-mapped) timers.
The GT specification defines the following per-processor timers:Quoted 8 lines
• Secure privilege level 1 (EL1) timer,
• Non-Secure EL1 timer,
• Non-Secure privilege level 2 (EL2) timer,
• Virtual timer,
and the following Platform (memory-mapped) timers.
• GT Block
• Server Base System Architecture (SBSA) Generic Watchdog ---8<----
Quoted 3 lines
Sure, the device it describes may only ever exist on ARM systems, but by that logic then we should be moving lots of drivers back under arch/arm[64].
It is nt the driver, but its instantiation. The question here would be how and where to instantiate the driver, not where the driver itself is located. The driver itself is ACPI agnostic.
What you are really saying is that you want the driver instantiation to be moved into the driver.
Guenter
Re: [PATCH v3 6/6] ACPI: import watchdog info of GTDT into platform device
Quoted 51 lines · Guenter Roeck
Quoted 50 lines · Will Deacon
Quoted 48 lines · Ashwin Chaugule
Quoted 15 lines · Will Deacon
Quoted 7 lines · On Mon, May 25, 2015 at 11:03:13AM +0100…
From: Fu Wei <[email protected]>
Parse SBSA Generic Watchdog Structure in GTDT table of ACPI, and create a platform device with that information. This platform device can be used by the ARM SBSA Generic Watchdog driver.
Quoted 6 lines
Tested-by Timur Tabi <[email protected]>Signed-off-by Fu Wei <[email protected]>--- arch/arm64/kernel/acpi.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+)Quoted 5 lines
Why does this all need to be under
arch/arm64? The GTDT really isn't architecture-specific, so I'd *much* rather it was parsed in the driver code itself, like we already do for the architected timer. The GIC is an exception because it's in the MADT, which we need to parse in the arch code to configure SMP properly.I'm not really against refactoring the code. But the GTDT looks quite specific to ARM..
---8<----
5.2.24 Generic Timer Description Table (GTDT)
This section describes the format of the Generic Timer Description Table (GTDT), which provides
OSPM with information about a system’s Generic Timers configuration. The Generic Timer (GT) is
a standard timer interface implemented on ARM processor-based systems. The GT hardware
specification can be found at Links to ACPI-Related Documents
(http://uefi.org/acpi) under the
heading ARM Architecture. The GTDT provides OSPM with information about a system's GT
interrupt configurations, for both per-processor timers, and platform (memory-mapped) timers.
The GT specification defines the following per-processor timers:
• Secure privilege level 1 (EL1) timer,
• Non-Secure EL1 timer,
• Non-Secure privilege level 2 (EL2) timer,
• Virtual timer,
and the following Platform (memory-mapped) timers.
• GT Block
• Server Base System Architecture (SBSA) Generic Watchdog ---8<----
Quoted 6 lines
Quoted 3 lines
Sure, the device it describes may only ever exist on ARM systems, but by that logic then we should be moving lots of drivers back under arch/arm[64].
It is nt the driver, but its instantiation. The question here would be how and where to instantiate the driver, not where the driver itself is located. The driver itself is ACPI agnostic.
Hi Will,
I really don't mind to refactor the code, If we can make this patch better.
But for now, I can't see the good reason to move ACPI-relevant code into a watchdog driver.
The reasons I put the code here are
(1)SBSA watchdog only for ARM64
(2)GTDT only for ARM, design for ARM,
(3)For ARM Architecture, only ARM64 support ACPI.
For minimizing arch/arm64/kernel/acpi.c, we can't put the code here, and we had better keep these code outside the driver,
So do you have any suggestion for the better location of the GTDT code?
Great thanks for your help.
Quoted 5 lines
What you are really saying is that you want the driver instantiation to be moved into the driver.
Guenter
Signature · 14 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 6/6] ACPI: import watchdog info of GTDT into platform device
In reply to Hanjun GuoQuoted 8 lines · Hanjun Guo
Quoted 2 lines
early_acpi_os_unmap_memory((char *)table, tbl_size);}
please add
#ifdef
CONFIG_ARM_SBSA_WATCHDOG
(acpi gtdt code)
#endif
I don't agree with this. The GTDT should be parsed even if there's no watchdog driver compiled for this kernel. There are no other #ifdefs in this file.
Quoted 7 lines
Quoted 6 lines
+ * Add a platform device named "sbsa-gwdt" to match the platform
driver.
+ * "sbsa-gwdt": SBSA(Server Base System Architecture) Generic
Watchdog
+ * The platform driver can get device info below by matching this
name.
Quoted 5 lines
* The platform driver (
drivers/watchdog/sbsa_gwdt.c) can get device info below by matching this name.Adding the file name which will help for review and maintain in my opinion.
Except it will cause problems if the driver is renamed or moved. I don't think this is a good idea, either (sorry!)
Signature · 3 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [PATCH v3 5/6] Watchdog: introduce ARM SBSA watchdog driver
In reply to [email protected]Quoted 15 lines · On 05/25/2015 05:03 AM, [email protected] wrote:
drivers/watchdog/sbsa_gwdt.c new file +15
-0+/* +* help functions for accessing 32bit registers of SBSA Generic Watchdog +*/ +static void sbsa_gwdt_cf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (val, gwdt->control_base + reg); +} + +static void sbsa_gwdt_rf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd);
drivers/watchdog/sbsa_gwdt.c line 139
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+ +writel_relaxed (val, gwdt->refresh_base + reg); +} + +static u32 sbsa_gwdt_cf_read (unsigned int reg,struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +return readl_relaxed (gwdt->control_base + reg); +}
I don't understand the value of these functions. You're just adding overhead to each read and write by dereferencing wdd every time. I would get rid of them and just call readl_relaxed() and writel_relaxed() directly.
drivers/watchdog/sbsa_gwdt.c line 151
Quoted 11 lines
drivers/watchdog/sbsa_gwdt.c new file +11
-0+/* +* help functions for accessing 64bit WCV register +*/ +static u64 sbsa_gwdt_get_wcv (struct watchdog_device *wdd) +{ +u32 wcv_lo, wcv_hi; + +do { + wcv_hi =sbsa_gwdt_cf_read (SBSA_GWDT_WCV_HI , wdd); + wcv_lo =sbsa_gwdt_cf_read (SBSA_GWDT_WCV_LO , wdd); + }while (wcv_hi !=sbsa_gwdt_cf_read (SBSA_GWDT_WCV_HI , wdd));
Please add a comment indicating that you're trying to read WCV atomically.
drivers/watchdog/sbsa_gwdt.c line 154
Quoted 3 lines
drivers/watchdog/sbsa_gwdt.c new file +3
-0+ +return (((u64 )wcv_hi <<32 ) | wcv_lo); +}
How about defining this macro:
#define make64(high, low) (((u64)(high) << 32) | (low))
and using it instead? That makes the code easier to read.
drivers/watchdog/sbsa_gwdt.c line 161
Quoted 7 lines
drivers/watchdog/sbsa_gwdt.c new file +7
-0+ +static void sbsa_gwdt_set_wcv (struct watchdog_device *wdd,u64 value) +{ +u32 wcv_lo, wcv_hi; + + wcv_lo = value &U32_MAX ; + wcv_hi = (value >>32 ) &U32_MAX ;
Use upper_32_bits() and lower_32_bits() instead.
drivers/watchdog/sbsa_gwdt.c line 167
Quoted 6 lines
drivers/watchdog/sbsa_gwdt.c new file +6
-0+ +sbsa_gwdt_cf_write (SBSA_GWDT_WCV_HI , wcv_hi, wdd); +sbsa_gwdt_cf_write (SBSA_GWDT_WCV_LO , wcv_lo, wdd); +} + +static void reload_timeout_to_wcv (struct watchdog_device *wdd)
This should be sbsa_gwdt_reload_timeout_to_wcv()
drivers/watchdog/sbsa_gwdt.c line 175
Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c new file +8
-0+{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); +u64 wcv; + + wcv =arch_counter_get_cntvct () + + (u64)(wdd->timeout - wdd->pretimeout) * gwdt->clk; + +sbsa_gwdt_set_wcv (wdd, wcv);
Shouldn't you program WCV and WOR together?
Quoted 7 lines
drivers/watchdog/sbsa_gwdt.c new file +7
-0+static int sbsa_gwdt_set_pretimeout (struct watchdog_device *wdd, +unsigned int pretimeout) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); +u32 wor; + + wdd->pretimeout = pretimeout;
drivers/watchdog/sbsa_gwdt.c line 218
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+sbsa_gwdt_update_limits (wdd); + +if (!pretimeout) +/* gives sbsa_gwdt_start a chance to setup timeout */ + wor = gwdt->clk; +else + wor = pretimeout * gwdt->clk; + +/* refresh the WOR, that will cause an explicit watchdog refresh */ +sbsa_gwdt_cf_write (SBSA_GWDT_WOR , wor, wdd);
Why not just ping the watchdog explicitely?
drivers/watchdog/sbsa_gwdt.c line 276
Quoted 9 lines
drivers/watchdog/sbsa_gwdt.c new file +9
-0+static irqreturn_t sbsa_gwdt_interrupt (int irq,void *dev_id) +{ +struct sbsa_gwdt *gwdt = (struct sbsa_gwdt *)dev_id; +struct watchdog_device *wdd = &gwdt->wdd; +u32 status; + + status =sbsa_gwdt_cf_read (SBSA_GWDT_WCS , wdd); + +if (status &SBSA_GWDT_WCS_WS0 )
This should always be true. Instead of reading WCS, I think you should just panic().
Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c new file +8
-0+static int sbsa_gwdt_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct sbsa_gwdt *gwdt; +struct watchdog_device *wdd; +struct resource *res; +void *rf_base, *cf_base; +int irq;
drivers/watchdog/sbsa_gwdt.c line 318
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+u32 clk, status; +int ret =0 ; +u64 first_period_max =U64_MAX ; + +/* +* Get the frequency of system counter from +* the cp15 interface of ARM Generic timer +*/ + clk =arch_timer_get_cntfrq (); +if (!clk) {
You have
depends on ARM_ARCH_TIMER
in your Kconfig, so you don't need to check the return of arch_timer_get_cntfrq(). It can never be zero.
Also, I would not use the variable name 'clk', because that's usually used for a "struct clk" object. I would call this "freq" instead.
Signature · 3 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Guenter Roeck
maintainerRe: [PATCH v3 6/6] ACPI: import watchdog info of GTDT into platform device
In reply to Timur TabiQuoted 7 lines · Timur Tabi
Quoted 5 lines · Hanjun Guo
Quoted 2 lines
early_acpi_os_unmap_memory((char *)table, tbl_size);}
please add
Quoted 8 lines
Quoted 3 lines
#ifdef
CONFIG_ARM_SBSA_WATCHDOG
(acpi gtdt code)
#endifI don't agree with this. The GTDT should be parsed even if there's no watchdog driver compiled for this kernel. There are no other #ifdefs in this file.
Me not either, but then I thought this is really a maintainer question. If the maintainers want out-of-subsystem #ifdefs in the code, who am I to complain.
Should be "#if IS_ENABLED(CONFIG_ARM_SBSA_WATCHDOG)", though, if we go along that route.
Guenter
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 6/6] ACPI: import watchdog info of GTDT into platform device
In reply to Timur TabiQuoted 7 lines · Timur Tabi
Quoted 5 lines · Hanjun Guo
Quoted 2 lines
early_acpi_os_unmap_memory((char *)table, tbl_size);}
please add
Quoted 7 lines
Quoted 3 lines
#ifdef
CONFIG_ARM_SBSA_WATCHDOG
(acpi gtdt code)
#endifI don't agree with this. The GTDT should be parsed even if there's no watchdog driver compiled for this kernel. There are no other #ifdefs in this file.
So what's the point of parse GTDT and alloc memories for it if there is no watchdog driver compiled for the kernel? will the module insmod later even if the CONFIG_ARM_SBSA_WATCHDOG=n?
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
+ * Add a platform device named "sbsa-gwdt" to match the platform
driver.
+ * "sbsa-gwdt": SBSA(Server Base System Architecture) Generic
Watchdog
+ * The platform driver can get device info below by matching this
name.
Quoted 8 lines
Quoted 5 lines
* The platform driver (
drivers/watchdog/sbsa_gwdt.c) can get device info below by matching this name.Adding the file name which will help for review and maintain in my opinion.
Except it will cause problems if the driver is renamed or moved. I don't think this is a good idea, either (sorry!)
OK, that's good point. but what I proposed is some hint to which driver will use the data prepared in this file, we can easily understand it in this patchset, but if just review the code in this fiel, I think people will be confused without detail comments.
Thanks
Hanjun
Re: [PATCH v3 6/6] ACPI: import watchdog info of GTDT into platform device
Quoted 6 lines · Hanjun Guo
Quoted 3 lines
I don't agree with this. The GTDT should be parsed even if there's no watchdog driver compiled for this kernel. There are no other #ifdefs in this file.
So what's the point of parse GTDT and alloc memories for it if there is no watchdog driver compiled for the kernel?
I don't think it's normal policy to generate a platform only if one specific driver is enabled.
Quoted 2 lines
will the module insmod
later even if theCONFIG_ARM_SBSA_WATCHDOG=n?
I think that actually can work, but it's not a good reason by itself.
Quoted 4 lines
OK, that's good point. but what I proposed is some hint to which driver will use the data prepared in this file, we can easily understand it in this patchset, but if just review the code in this fiel, I think people will be confused without detail comments.
All anyone needs to is
git grep "sbsa-gwdt"
And you'll find the driver.
Signature · 7 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation. -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 6/6] ACPI: import watchdog info of GTDT into platform device
In reply to Fu WeiQuoted 5 lines · Fu Wei
Quoted 4 lines · Guenter Roeck
Quoted 3 lines · Will Deacon
Sure, the device it describes may only ever exist on ARM systems, but by that logic then we should be moving lots of drivers back under arch/arm[64].
Quoted 8 lines
Quoted 3 lines
It is nt the driver, but its instantiation. The question here would be how and where to instantiate the driver, not where the driver itself is located. The driver itself is ACPI agnostic.
I really don't mind to refactor the code, If we can make this patch better.
But for now, I can't see the good reason to move ACPI-relevant code into a watchdog driver.
I don't really mind where you move it, just as long as it's outside of arch/arm64.
Quoted 9 lines
The reasons I put the code here are
(1)SBSA watchdog only for ARM64
(2)GTDT only for ARM, design for ARM,
(3)For ARM Architecture, only ARM64 support ACPI.For minimizing
arch/arm64/kernel/acpi.c, we can't put the code here, and we had better keep these code outside the driver,So do you have any suggestion for the better location of the GTDT code?
I don't understand why you can't do the same as drivers/clocksource/arm_arch_timer.c and parse the table directly in the driver. If there are objections from the driver/subsystem maintainers then it sounds like we need a mechanical ACPI table -> platform device conversion in the core, like we have for device-tree.
Will
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 5/6] Watchdog: introduce ARM SBSA watchdog driver
In reply to Guenter RoeckHi Guenter,
Great thanks, feedback inline
Quoted 153 lines · Guenter Roeck
Quoted 9 lines · On 05/25/2015 03:03 AM, [email protected] wrote:
From: Fu Wei <[email protected]>
This driver bases on linux kernel watchdog framework, and use "pretimeout" in the framework. It supports getting timeout and pretimeout from parameter and FDT at the driver init stage. In first timeout, the interrupt routine run panic to save system context.
Quoted 4 lines
Acked-by Arnd Bergmann <[email protected]>Signed-off-by Fu Wei <[email protected]>---
Comments inline.
Thanks,
GuenterQuoted 131 lines
drivers/watchdog/Kconfig | 11 + drivers/watchdog/Makefile | 1 + drivers/watchdog/sbsa_gwdt.c | 474 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 486 insertions(+)create mode 100644
drivers/watchdog/sbsa_gwdt.cdrivers/watchdog/Kconfig +0
-0@@ -152,6 +152,17 @@ config ARM_SP805_WATCHDOG ARM Primecell SP805 Watchdog timer. This will reboot your systemwhen
the timeout is reached.drivers/watchdog/Kconfig +7
-0+config ARM_SBSA_WATCHDOG + tristate "ARM SBSA Generic Watchdog" + depends on ARM64 + depends on ARM_ARCH_TIMER + select WATCHDOG_CORE + help + ARM SBSA Generic Watchdog. This watchdog has two Watchdogtimeouts.
drivers/watchdog/Kconfig +3
-0+ The first timeout will trigger a panic; the second timeout will + trigger a system reset. + More details: ARM DEN0029B - Server Base System Architecture(SBSA)
drivers/watchdog/Kconfig +1
-0+ config AT91RM9200_WATCHDOG tristate "AT91RM9200 watchdog" depends on SOC_AT91RM9200 && MFD_SYSCONdrivers/watchdog/Makefile +1
-0@@ -30,6 +30,7 @@ obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o # ARM Architecture obj-$(CONFIG_ARM_SP805_WATCHDOG) += sp805_wdt.o +obj-$(CONFIG_ARM_SBSA_WATCHDOG) += sbsa_gwdt.o obj-$(CONFIG_AT91RM9200_WATCHDOG) += at91rm9200_wdt.o obj-$(CONFIG_AT91SAM9X_WATCHDOG) += at91sam9_wdt.o obj-$(CONFIG_CADENCE_WATCHDOG) += cadence_wdt.odrivers/watchdog/sbsa_gwdt.c new file +23
-0@@ -0,0 +1,474 @@ +/* +* SBSA(Server Base System Architecture) Generic Watchdog driver +* +* Copyright (c) 2015, Linaro Ltd. +* Author: Fu Wei <[email protected]> +* Suravee Suthikulpanit <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License 2 as published +* by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* Note: This SBSA Generic watchdog driver is compatible with +* the pretimeout concept of Linux kernel. +* The timeout and pretimeout are set by the different REGs. +* The first watch period is set by writing WCV directly, +* that can support more than 10s timeout at the maximum +* system counter frequency. +* The second watch period is set by WOR(32bit) which will be loaded
+ * automatically by hardware, when WS0 is triggered. + * This gives a maximum watch period of around 10s at the maximum + * system counter frequency. + * The System Counter shall run at maximum of 400MHz. + * More details: ARM DEN0029B - Server Base System Architecture(SBSA)
+ *
+ * Kernel/API: P---------| pretimeout
+ * |-------------------------------T timeout
+ * SBSA GWDT: P--WOR---WS1 pretimeout
+ * |-------WCV----------WS0~~~~~~~~T timeout
+ */drivers/watchdog/sbsa_gwdt.c new file +45
-0+ +#include <linux/io.h> +#include <linux/interrupt.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/of.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/uaccess.h> +#include <linux/watchdog.h> +#include <asm/arch_timer.h> + +/* SBSA Generic Watchdog register definitions */ +/* refresh frame */ +#define SBSA_GWDT_WRR 0x000 + +/* control frame */ +#define SBSA_GWDT_WCS 0x000 +#define SBSA_GWDT_WOR 0x008 +#define SBSA_GWDT_WCV_LO 0x010 +#define SBSA_GWDT_WCV_HI 0x014 + +/* refresh/control frame */ +#define SBSA_GWDT_W_IIDR 0xfcc +#define SBSA_GWDT_IDR 0xfd0 + +/* Watchdog Control and Status Register */ +#define SBSA_GWDT_WCS_EN BIT(0) +#define SBSA_GWDT_WCS_WS0 BIT(1) +#define SBSA_GWDT_WCS_WS1 BIT(2) + +/** +* struct sbsa_gwdt - Internal representation of the SBSA GWDT +* @wdd: kernel watchdog_device structure +* @clk: store the System Counter clock frequency, in Hz. +* @refresh_base: Virtual address of the watchdog refresh frame +* @control_base: Virtual address of the watchdog control frame +*/ +struct sbsa_gwdt { +struct watchdog_device wdd; +u32 clk; +void __iomem *refresh_base; +void __iomem *control_base; +}; +
Quoted 8 lines
Quoted 4 lines
drivers/watchdog/sbsa_gwdt.c new file +3
-0+#define to_sbsa_gwdt (e) container_of(e, struct sbsa_gwdt, wdd) + +#define DEFAULT_TIMEOUT 10/* seconds, the 1st + 2nd watch periods*/
That is a bit low for a default. Is that on purpose ? Most drivers use 30 or 60 seconds.
That is not on purpose. will fixed them :
#define DEFAULT_TIMEOUT 30 /* seconds, the 1st + 2nd watch periods*/ #define DEFAULT_PRETIMEOUT 10 /* seconds, the 2nd watch period*/
Quoted 11 lines
drivers/watchdog/sbsa_gwdt.c line 90
Quoted 9 lines
drivers/watchdog/sbsa_gwdt.c new file +8
-0+#define DEFAULT_PRETIMEOUT 5/* seconds, the 2nd watch period*/ + +static unsigned int timeout_param; +module_param (timeout_param, uint,0 ); +MODULE_PARM_DESC (timeout_param, + "Watchdog timeout in seconds. (>=0, default=" + __MODULE_STRING(DEFAULT_TIMEOUT) ")"); +Why
_paramin the module parameter names ? Seems to be redundant.
sorry, I shouldn't add _param , fixed it
Quoted 11 lines
drivers/watchdog/sbsa_gwdt.c line 96
Quoted 7 lines
drivers/watchdog/sbsa_gwdt.c new file +6
-0+static unsigned int max_timeout_param =UINT_MAX ; +module_param (max_timeout_param, uint,0 ); +MODULE_PARM_DESC (max_timeout_param, + "Watchdog max timeout in seconds. (>=0, default=" + __MODULE_STRING(UINT_MAX) ")"); +Why do we want or need this parameter and
max_pretimeout? Those are determined by the hardware.
Sorry, I thought we can also allow user setup a max value when insmod the module or by boot cmdline. but I was wrong, have deleted them.
Quoted 109 lines
Quoted 90 lines
drivers/watchdog/sbsa_gwdt.c new file +38
-0+static unsigned int pretimeout_param; +module_param (pretimeout_param, uint,0 ); +MODULE_PARM_DESC (pretimeout_param, + "Watchdog pretimeout in seconds. (>=0, default=" + __MODULE_STRING(DEFAULT_PRETIMEOUT) ")"); + +static unsigned int max_pretimeout_param =U32_MAX ; +module_param (max_pretimeout_param, uint,0 ); +MODULE_PARM_DESC (max_pretimeout_param, + "Watchdog max pretimeout in seconds. (>=0, default=" + __MODULE_STRING(U32_MAX) ")"); + +static bool nowayout =WATCHDOG_NOWAYOUT ; +module_param (nowayout, bool,S_IRUGO ); +MODULE_PARM_DESC (nowayout, + "Watchdog cannot be stopped once started (default=" + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +/* +* help functions for accessing 32bit registers of SBSA Generic Watchdog +*/ +static void sbsa_gwdt_cf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (val, gwdt->control_base + reg); +} + +static void sbsa_gwdt_rf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (val, gwdt->refresh_base + reg); +} + +static u32 sbsa_gwdt_cf_read(unsigned int reg, struct watchdog_device*wdd)
drivers/watchdog/sbsa_gwdt.c new file +49
-0+{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +return readl_relaxed (gwdt->control_base + reg); +} + +/* +* help functions for accessing 64bit WCV register +*/ +static u64 sbsa_gwdt_get_wcv (struct watchdog_device *wdd) +{ +u32 wcv_lo, wcv_hi; + +do { + wcv_hi =sbsa_gwdt_cf_read (SBSA_GWDT_WCV_HI , wdd); + wcv_lo =sbsa_gwdt_cf_read (SBSA_GWDT_WCV_LO , wdd); + }while (wcv_hi !=sbsa_gwdt_cf_read (SBSA_GWDT_WCV_HI , wdd)); + +return (((u64 )wcv_hi <<32 ) | wcv_lo); +} + +static void sbsa_gwdt_set_wcv (struct watchdog_device *wdd,u64 value) +{ +u32 wcv_lo, wcv_hi; + + wcv_lo = value &U32_MAX ; + wcv_hi = (value >>32 ) &U32_MAX ; + +sbsa_gwdt_cf_write (SBSA_GWDT_WCV_HI , wcv_hi, wdd); +sbsa_gwdt_cf_write (SBSA_GWDT_WCV_LO , wcv_lo, wdd); +} + +static void reload_timeout_to_wcv (struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); +u64 wcv; + + wcv =arch_counter_get_cntvct () + + (u64)(wdd->timeout - wdd->pretimeout) * gwdt->clk; + +sbsa_gwdt_set_wcv (wdd, wcv); +} + +/* +* Use the following function to update the timeout limits +* after updating pretimeout +*/ +static void sbsa_gwdt_update_limits (struct watchdog_device *wdd) +{drivers/watchdog/sbsa_gwdt.c line 193
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); +u64 first_period_max =U64_MAX ; + +do_div (first_period_max, gwdt->clk); + + wdd->min_timeout = wdd->pretimeout +1 ; + wdd->max_timeout =min ((uint)(wdd->pretimeout + first_period_max), + wdd->max_timeout); +} +After understanding the watchdog a bit better now, I think you should drop those updates and set
min_timeout= 1
max_timeout=min(UINT_MAX, U64_MAX / clk)min_pretimeout= 0
max_pretimeout=U32_MAX/ clk
Quoted 5 lines
and then ensure that pretimeout < timeout at runtime (if possible in the infrastructure code).
Even at maximum clock rate,
max_timeoutis so large that anything else is really overkill.
you are right, fixed it, thanks
Quoted 30 lines
Quoted 14 lines
drivers/watchdog/sbsa_gwdt.c new file +13
-0+static int sbsa_gwdt_set_timeout (struct watchdog_device *wdd, +unsigned int timeout) +{ + wdd->timeout = timeout; + +return 0 ; +} + +static int sbsa_gwdt_set_pretimeout (struct watchdog_device *wdd, +unsigned int pretimeout) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); +u32 wor;drivers/watchdog/sbsa_gwdt.c line 216
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+ + wdd->pretimeout = pretimeout; +sbsa_gwdt_update_limits (wdd); + +if (!pretimeout) +/* gives sbsa_gwdt_start a chance to setup timeout */ + wor = gwdt->clk; +else + wor = pretimeout * gwdt->clk; +So in practice you always have a pretimeout of at least one second, correct ? That kind of violates the ABI, which says that the pretimeout should be disabled if set to 0. Is there anything we can do about that ?
Quoted 3 lines
What exactly happens if WOR = 0 ? Doesn't that just mean that the second timeout will happen immediately, and isn't that what we would want if pretimeout = 0
Accroding to SBSA, in theory,
if WOR == 0, once we write WRR(refresh), we will get WS0 and WS1 immediately . that means timeout == 0.
So I will add more comment here to explain this.
Quoted 7 lines
Quoted 3 lines
+ /* refresh the WOR, that will cause an explicit watchdog refresh
*/Except that we use wcv which needs a manual refresh, so this is a bit misleading, isn't it ?
if we setup wcv manually, we maybe don't need a manual refresh. I will test it later.
Quoted 41 lines
Quoted 41 lines
drivers/watchdog/sbsa_gwdt.c new file +39
-0+sbsa_gwdt_cf_write (SBSA_GWDT_WOR , wor, wdd); + +return 0 ; +} + +static unsigned int sbsa_gwdt_get_timeleft (struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); +u64 timeleft =sbsa_gwdt_get_wcv (wdd) -arch_counter_get_cntvct (); + +do_div (timeleft, gwdt->clk); + +return timeleft; +} + +static int sbsa_gwdt_start (struct watchdog_device *wdd) +{ +/* Force refresh */ +sbsa_gwdt_rf_write (SBSA_GWDT_WRR ,0xc0ffee , wdd); +/* writing WCS will cause an explicit watchdog refresh */ +sbsa_gwdt_cf_write (SBSA_GWDT_WCS ,SBSA_GWDT_WCS_EN , wdd); + +reload_timeout_to_wcv (wdd); + +return 0 ; +} + +static int sbsa_gwdt_stop (struct watchdog_device *wdd) +{ +/* Force refresh */ +sbsa_gwdt_rf_write (SBSA_GWDT_WRR ,0xc0ffee , wdd); +/* writing WCS will cause an explicit watchdog refresh */ +sbsa_gwdt_cf_write (SBSA_GWDT_WCS ,0 , wdd); + +return 0 ; +} + +static int sbsa_gwdt_keepalive (struct watchdog_device *wdd) +{
Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c line 261
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +5
-0+/* +* Writing WRR for an explicit watchdog refresh +* You can write anyting(like 0xc0ffee) +*/ +sbsa_gwdt_rf_write (SBSA_GWDT_WRR ,0xc0ffee , wdd);Should that happen after writing wcv ?
no, if so, WOR + current_time will be loaded into wcv. I put this before writing wcv on purpose.
maybe we can just update wcv without a force refresh.
will test it later
Quoted 63 lines
Quoted 48 lines
drivers/watchdog/sbsa_gwdt.c new file +46
-0+ +reload_timeout_to_wcv (wdd); + +return 0 ; +} + +static irqreturn_t sbsa_gwdt_interrupt (int irq,void *dev_id) +{ +struct sbsa_gwdt *gwdt = (struct sbsa_gwdt *)dev_id; +struct watchdog_device *wdd = &gwdt->wdd; +u32 status; + + status =sbsa_gwdt_cf_read (SBSA_GWDT_WCS , wdd); + +if (status &SBSA_GWDT_WCS_WS0 ) +panic ("SBSA Watchdog pre-timeout" ); + +return IRQ_HANDLED ; +} + +static struct watchdog_info sbsa_gwdt_info = { + .identity ="SBSA Generic Watchdog" , + .options =WDIOF_SETTIMEOUT | +WDIOF_KEEPALIVEPING | +WDIOF_MAGICCLOSE | +WDIOF_PRETIMEOUT | +WDIOF_CARDRESET , +}; + +static struct watchdog_ops sbsa_gwdt_ops = { + .owner =THIS_MODULE , + .start = sbsa_gwdt_start, + .stop = sbsa_gwdt_stop, + .ping = sbsa_gwdt_keepalive, + .set_timeout = sbsa_gwdt_set_timeout, + .set_pretimeout = sbsa_gwdt_set_pretimeout, + .get_timeleft = sbsa_gwdt_get_timeleft, +}; + +static int sbsa_gwdt_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct sbsa_gwdt *gwdt; +struct watchdog_device *wdd; +struct resource *res; +void *rf_base, *cf_base;drivers/watchdog/sbsa_gwdt.c line 317
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+int irq; +u32 clk, status; +int ret =0 ; +u64 first_period_max =U64_MAX ; + +/* +* Get the frequency of system counter from +* the cp15 interface of ARM Generic timer +*/ + clk =arch_timer_get_cntfrq ();That can not return 0, presumably, from looking into its implementation. And the system should panic if it is ever 0.
Quoted 4 lines
Quoted 1 line
+ if (!clk) {
Given that, I don't think this check is necessary.
yes, you are right , I have got your point, and improved it .
Quoted 41 lines
Quoted 41 lines
drivers/watchdog/sbsa_gwdt.c new file +9
-0+dev_err (dev,"System Counter frequency not available\n" ); +return -EINVAL ; + } + + gwdt =devm_kzalloc (dev,sizeof (*gwdt),GFP_KERNEL ); +if (!gwdt) +return -ENOMEM ; + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM,"refresh");
drivers/watchdog/sbsa_gwdt.c new file +5
-0+ rf_base =devm_ioremap_resource (dev, res); +if (IS_ERR (rf_base)) +return PTR_ERR (rf_base); + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM,"control");
drivers/watchdog/sbsa_gwdt.c new file +23
-0+ cf_base =devm_ioremap_resource (dev, res); +if (IS_ERR (cf_base)) +return PTR_ERR (cf_base); + + irq =platform_get_irq_byname (pdev,"ws0" ); +if (irq <0 ) { +dev_err (dev,"unable to get ws0 interrupt.\n" ); +return irq; + } + + gwdt->refresh_base = rf_base; + gwdt->control_base = cf_base; + gwdt->clk = clk; + +platform_set_drvdata (pdev, gwdt); + + wdd = &gwdt->wdd; + wdd->parent = dev; + wdd->info = &sbsa_gwdt_info; + wdd->ops = &sbsa_gwdt_ops; +watchdog_set_drvdata (wdd, gwdt); +watchdog_set_nowayout (wdd, nowayout); +
Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c line 359
Quoted 4 lines
drivers/watchdog/sbsa_gwdt.c new file +4
-0+ status =sbsa_gwdt_cf_read (SBSA_GWDT_WCS , wdd); +if (status &SBSA_GWDT_WCS_WS1 ) { +dev_warn (dev,"System reset by WDT(WCS: %x, WCV: %llx)\n" , + status,sbsa_gwdt_get_wcv (wdd));Does this message (specifically the WCS / WCV values) have any useful meaning for the user ?
I think so, according to SBSA spec:
If WS0 is asserted and a timeout refresh occurs then the following must occur:
If the system is compliant to SBSA level 2 or higher the compare
value must retain its current value. This means that the compare value records the time that WS1 is asserted.
So, I think WCV can log the time when system reset by WDT, that may help user figure out the problem. but WCS can be delete I think.
Quoted 11 lines
drivers/watchdog/sbsa_gwdt.c line 365
Quoted 7 lines
drivers/watchdog/sbsa_gwdt.c new file +6
-0+ wdd->bootstatus |=WDIOF_CARDRESET ; + } +/* Check if watchdog is already enabled */ +if (status &SBSA_GWDT_WCS_EN ) { +dev_warn (dev,"already enabled! WCS:0x%x\n" , status); +sbsa_gwdt_keepalive (wdd);You have not configured
wdd->timeoutandwdd->pretimeouthere, yet the function callsreload_timeout_to_wcvwhich needs it.
Ah, sorry, that is a bug, have reordered the code, Thanks
Quoted 21 lines
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +4
-0+ } + + wdd->min_pretimeout =0 ; + wdd->max_pretimeout =min (U32_MAX / clk, max_pretimeout_param);drivers/watchdog/sbsa_gwdt.c line 379
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+ wdd->min_timeout =1 ; +do_div (first_period_max, clk); + wdd->max_timeout =min ((uint)(wdd->pretimeout + first_period_max), + max_timeout_param); + + wdd->pretimeout =DEFAULT_PRETIMEOUT ; + wdd->timeout =DEFAULT_TIMEOUT ; +watchdog_init_timeouts (wdd, pretimeout_param, timeout_param, dev); +/* update pretimeout to WOR */ +sbsa_gwdt_cf_write (SBSA_GWDT_WOR , wdd->pretimeout * clk, wdd);This is interesting because you set WOR to 0 here if pretimeout is 0. Yet, when pretimeout is updated later on, you always set it to at least one second. Any reason for doing this differently ?
Quoted 3 lines
If the above works, and presumably you have tested it, I don't see why it would be necessary to set WOR to a value larger than 0 when updating pretimeout.
Ah I should tested more in extreme case, but here, I can use sbsa_gwdt_set_pretimeout directly.
Quoted 11 lines
Quoted 11 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+ + ret =devm_request_irq (dev, irq, sbsa_gwdt_interrupt,IRQF_TIMER , + pdev->name, gwdt); +if (ret) { +dev_err (dev,"unable to request IRQ %d\n" , irq); +return ret; + } + + ret =watchdog_register_device (wdd); +if (ret)
Quoted 8 lines
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +3
-0+return ret; + + dev_info(dev, "Initialized with %ds timeout, %ds pretimeout @%uHz\n",
+wdd->timeout,wdd->pretimeout,gwdt->clk);400000Hz reads a bit odd. How about a space between the number and Hz ?
np, fixed it , thanks :-)
Quoted 17 lines
Quoted 17 lines
drivers/watchdog/sbsa_gwdt.c new file +16
-0+ +return 0 ; +} + +static void sbsa_gwdt_shutdown (struct platform_device *pdev) +{ +struct sbsa_gwdt *gwdt =platform_get_drvdata (pdev); + +sbsa_gwdt_stop (&gwdt->wdd); +} + +static int sbsa_gwdt_remove (struct platform_device *pdev) +{ +struct sbsa_gwdt *gwdt =platform_get_drvdata (pdev); +int ret =0 ; +
Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c line 412
Quoted 3 lines
drivers/watchdog/sbsa_gwdt.c new file +3
-0+if (!nowayout) + ret =sbsa_gwdt_stop (&gwdt->wdd); +I don't think you should do anything here. The driver can only be removed if closed, and it that case the watchdog will already have been stopped, or if nowayout was set it won't be stopped. Either case it is already in the state we want it to be in.
Sorry, I should delete it. Fixed
Quoted 66 lines
Quoted 65 lines
drivers/watchdog/sbsa_gwdt.c new file +62
-0+watchdog_unregister_device (&gwdt->wdd); + +return ret; +} + +/* Disable watchdog if it is active during suspend */ +static int __maybe_unused sbsa_gwdt_suspend (struct device *dev) +{ +struct sbsa_gwdt *gwdt =dev_get_drvdata (dev); + +if (watchdog_active (&gwdt->wdd)) +sbsa_gwdt_stop (&gwdt->wdd); + +return 0 ; +} + +/* Enable watchdog and configure it if necessary */ +static int __maybe_unused sbsa_gwdt_resume (struct device *dev) +{ +struct sbsa_gwdt *gwdt =dev_get_drvdata (dev); + +if (watchdog_active (&gwdt->wdd)) +sbsa_gwdt_start (&gwdt->wdd); + +return 0 ; +} + +static const struct dev_pm_ops sbsa_gwdt_pm_ops = { +SET_SYSTEM_SLEEP_PM_OPS (sbsa_gwdt_suspend, sbsa_gwdt_resume) +}; + +static const struct of_device_id sbsa_gwdt_of_match[] = { + { .compatible ="arm,sbsa-gwdt" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, sbsa_gwdt_of_match); + +static const struct platform_device_id sbsa_gwdt_pdev_match[] = { + { .name ="sbsa-gwdt" , }, + {}, +}; +MODULE_DEVICE_TABLE (platform, sbsa_gwdt_pdev_match); + +static struct platform_driver sbsa_gwdt_driver = { + .driver = { + .name ="sbsa-gwdt" , + .pm = &sbsa_gwdt_pm_ops, + .of_match_table = sbsa_gwdt_of_match, + }, + .probe = sbsa_gwdt_probe, + .remove = sbsa_gwdt_remove, + .shutdown = sbsa_gwdt_shutdown, + .id_table = sbsa_gwdt_pdev_match, +}; + +module_platform_driver (sbsa_gwdt_driver); + +MODULE_DESCRIPTION ("SBSA Generic Watchdog Driver" ); +MODULE_VERSION ("v1.0" ); +MODULE_AUTHOR ("Fu Wei <[email protected]>" ); +MODULE_AUTHOR ("Suravee Suthikulpanit <[email protected]>" ); +MODULE_LICENSE ("GPL v2" );
Signature · 14 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 5/6] Watchdog: introduce ARM SBSA watchdog driver
In reply to Timur TabiHi Timur,
Quoted 25 lines · Timur Tabi
Quoted 23 lines · On 05/25/2015 05:03 AM, [email protected] wrote:
drivers/watchdog/sbsa_gwdt.c new file +20
-0+/* +* help functions for accessing 32bit registers of SBSA Generic Watchdog +*/ +static void sbsa_gwdt_cf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (val, gwdt->control_base + reg); +} + +static void sbsa_gwdt_rf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (val, gwdt->refresh_base + reg); +} + +static u32 sbsa_gwdt_cf_read(unsigned int reg, struct watchdog_device*wdd)
(quoted diff) +2
-0+{ + struct sbsa_gwdt *gwdt = to_sbsa_gwdt(wdd);
Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c line 139
Quoted 3 lines
drivers/watchdog/sbsa_gwdt.c new file +3
-0+ +return readl_relaxed (gwdt->control_base + reg); +}I don't understand the value of these functions. You're just adding overhead to each read and write by dereferencing wdd every time. I would get rid of them and just call
readl_relaxed()andwritel_relaxed()directly.
yes, that makes sense, sometimes , I also feel these functions are a little redundant,
let me see if I can improve it.
Quoted 15 lines
drivers/watchdog/sbsa_gwdt.c line 151
Quoted 12 lines
drivers/watchdog/sbsa_gwdt.c new file +11
-0+/* +* help functions for accessing 64bit WCV register +*/ +static u64 sbsa_gwdt_get_wcv (struct watchdog_device *wdd) +{ +u32 wcv_lo, wcv_hi; + +do { + wcv_hi =sbsa_gwdt_cf_read (SBSA_GWDT_WCV_HI , wdd); + wcv_lo =sbsa_gwdt_cf_read (SBSA_GWDT_WCV_LO , wdd); + }while (wcv_hi !=sbsa_gwdt_cf_read (SBSA_GWDT_WCV_HI , wdd));Please add a comment indicating that you're trying to read WCV atomically.
OK , that makes sense
Quoted 11 lines
drivers/watchdog/sbsa_gwdt.c line 154
Quoted 4 lines
drivers/watchdog/sbsa_gwdt.c new file +3
-0+ +return (((u64 )wcv_hi <<32 ) | wcv_lo); +}How about defining this macro:
#define
make64(high, low)(((u64)(high) << 32) | (low))and using it instead? That makes the code easier to read.
good idea, but it's just used once, not sure if it's worthy Actually, I have seen some macro in some driver, but not in kernel header file.
Quoted 11 lines
drivers/watchdog/sbsa_gwdt.c line 161
Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c new file +7
-0+ +static void sbsa_gwdt_set_wcv (struct watchdog_device *wdd,u64 value) +{ +u32 wcv_lo, wcv_hi; + + wcv_lo = value &U32_MAX ; + wcv_hi = (value >>32 ) &U32_MAX ;Use
upper_32_bits()andlower_32_bits()instead.
cool, thanks , fixed it
Quoted 11 lines
drivers/watchdog/sbsa_gwdt.c line 167
Quoted 7 lines
drivers/watchdog/sbsa_gwdt.c new file +6
-0+ +sbsa_gwdt_cf_write (SBSA_GWDT_WCV_HI , wcv_hi, wdd); +sbsa_gwdt_cf_write (SBSA_GWDT_WCV_LO , wcv_lo, wdd); +} + +static void reload_timeout_to_wcv (struct watchdog_device *wdd)This should be
sbsa_gwdt_reload_timeout_to_wcv()
Quoted 11 lines
drivers/watchdog/sbsa_gwdt.c line 175
Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c new file +8
-0+{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); +u64 wcv; + + wcv =arch_counter_get_cntvct () + + (u64)(wdd->timeout - wdd->pretimeout) * gwdt->clk; + +sbsa_gwdt_set_wcv (wdd, wcv);Shouldn't you program WCV and WOR together?
why? WOR just for pretimeout in this driver.
Quoted 14 lines
Quoted 14 lines
drivers/watchdog/sbsa_gwdt.c new file +13
-0+static int sbsa_gwdt_set_pretimeout (struct watchdog_device *wdd, +unsigned int pretimeout) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); +u32 wor; + + wdd->pretimeout = pretimeout; +sbsa_gwdt_update_limits (wdd); + +if (!pretimeout) +/* gives sbsa_gwdt_start a chance to setup timeout */ + wor = gwdt->clk; +else
Quoted 8 lines
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +3
-0+ wor = pretimeout * gwdt->clk; + +/* refresh the WOR, that will cause an explicit watchdog refresh */
+sbsa_gwdt_cf_write(SBSA_GWDT_WOR, wor, wdd);Why not just ping the watchdog explicitely?
we just setup WOR, but we don't need to load pretimeout to WCV now, right ?
Quoted 14 lines
drivers/watchdog/sbsa_gwdt.c line 276
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +9
-0+static irqreturn_t sbsa_gwdt_interrupt (int irq,void *dev_id) +{ +struct sbsa_gwdt *gwdt = (struct sbsa_gwdt *)dev_id; +struct watchdog_device *wdd = &gwdt->wdd; +u32 status; + + status =sbsa_gwdt_cf_read (SBSA_GWDT_WCS , wdd); + +if (status &SBSA_GWDT_WCS_WS0 )This should always be true. Instead of reading WCS, I think you should just
panic().
I thinks I need to confirm it , in case this has been cleaned.
Quoted 23 lines
Quoted 9 lines
drivers/watchdog/sbsa_gwdt.c new file +8
-0+static int sbsa_gwdt_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct sbsa_gwdt *gwdt; +struct watchdog_device *wdd; +struct resource *res; +void *rf_base, *cf_base; +int irq;drivers/watchdog/sbsa_gwdt.c line 318
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+u32 clk, status; +int ret =0 ; +u64 first_period_max =U64_MAX ; + +/* +* Get the frequency of system counter from +* the cp15 interface of ARM Generic timer +*/ + clk =arch_timer_get_cntfrq (); +if (!clk) {You have
Quoted 7 lines
depends on
ARM_ARCH_TIMERin your
Kconfig, so you don't need to check the return ofarch_timer_get_cntfrq(). It can never be zero.Also, I would not use the variable name 'clk', because that's usually used for a "struct clk" object. I would call this "freq" instead.
yes, I have fixed it .
Quoted 6 lines
--
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Signature · 14 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 6/6] ACPI: import watchdog info of GTDT into platform device
In reply to Will DeaconHi Will,
As you know, I have moved all the GTDT code to ACPI driver , and simplify the GTDT relevant code in arm_arch_timer.c. That will be in my next patchset.
but you can check here :
https://git.linaro.org/people/fu.wei/linux.git/shortlog/refs/heads/acpi-topic-sbsa-watchdog_upstream_v4_devel
Great thanks for your suggestion!
Quoted 35 lines · Will Deacon
Quoted 5 lines · Fu Wei
Quoted 4 lines · Guenter Roeck
Quoted 3 lines · Will Deacon
Sure, the device it describes may only ever exist on ARM systems, but by that logic then we should be moving lots of drivers back under arch/arm[64].
Quoted 8 lines
Quoted 3 lines
It is nt the driver, but its instantiation. The question here would be how and where to instantiate the driver, not where the driver itself is located. The driver itself is ACPI agnostic.
I really don't mind to refactor the code, If we can make this patch better.
But for now, I can't see the good reason to move ACPI-relevant code into a watchdog driver.
I don't really mind where you move it, just as long as it's outside of
arch/arm64.Quoted 9 lines
The reasons I put the code here are
(1)SBSA watchdog only for ARM64
(2)GTDT only for ARM, design for ARM,
(3)For ARM Architecture, only ARM64 support ACPI.For minimizing
arch/arm64/kernel/acpi.c, we can't put the code here, and we had better keep these code outside the driver,So do you have any suggestion for the better location of the GTDT code?
I don't understand why you can't do the same as
drivers/clocksource/arm_arch_timer.cand parse the table directly in the driver. If there are objections from the driver/subsystem maintainers then it sounds like we need a mechanical ACPI table -> platform device conversion in the core, like we have for device-tree.Will
Signature · 14 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 5/6] Watchdog: introduce ARM SBSA watchdog driver
In reply to Fu WeiQuoted 4 lines · Fu Wei
Quoted 2 lines
This should always be true. Instead of reading WCS, I think you should just
Quoted 1 line
panic().I thinks I need to confirm it , in case this has been cleaned.
I don't see how it's possible for you to receive the interrupt and have WCS be cleared.
Signature · 7 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation. -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 5/6] Watchdog: introduce ARM SBSA watchdog driver
Hi Timur
Quoted 4 lines · Timur Tabi
Quoted 3 lines · Fu Wei
Quoted 3 lines
This should always be true. Instead of reading WCS, I think you should just
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
panic().I thinks I need to confirm it , in case this has been cleaned.
I don't see how it's possible for you to receive the interrupt and have WCS be cleared.
It is a SPI, every CPU can get it,
But maybe I miss something, but please let me know if other CPU can not get the interrupt.
Quoted 5 lines
--
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.
Signature · 14 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Guenter Roeck
maintainerRe: [PATCH v3 5/6] Watchdog: introduce ARM SBSA watchdog driver
In reply to Fu WeiOn 05/29/2015 02:11 AM, Fu Wei wrote:
[ ... ]
Quoted 10 lines
Quoted 9 lines
drivers/watchdog/sbsa_gwdt.c line 359
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +5
-0+ + status =sbsa_gwdt_cf_read (SBSA_GWDT_WCS , wdd); +if (status &SBSA_GWDT_WCS_WS1 ) { +dev_warn (dev,"System reset by WDT(WCS: %x, WCV: %llx)\n" , + status,sbsa_gwdt_get_wcv (wdd));Does this message (specifically the WCS / WCV values) have any useful meaning for the user ?
Quoted 9 lines
I think so, according to SBSA spec:
If WS0 is asserted and a timeout refresh occurs then the following must occur:
If the system is compliant to SBSA level 2 or higher the compare
value must retain its current value. This means that the compare value records the time that WS1 is asserted.So, I think WCV can log the time when system reset by WDT, that may help user figure out the problem. but WCS can be delete I think.
How would that help ? It is just a number with no reference to anything.
Thanks,
Guenter
Re: [PATCH v3 5/6] Watchdog: introduce ARM SBSA watchdog driver
Hi Guenter,
Quoted 23 lines · Guenter Roeck
On 05/29/2015 02:11 AM, Fu Wei wrote:
[ ... ]Quoted 20 lines
Quoted 11 lines
Quoted 6 lines
drivers/watchdog/sbsa_gwdt.c new file +4
-0+ + status =sbsa_gwdt_cf_read (SBSA_GWDT_WCS , wdd); +if (status &SBSA_GWDT_WCS_WS1 ) { + dev_warn(dev, "System reset by WDT(WCS: %x, WCV:%llx)\n",
+ status,sbsa_gwdt_get_wcv(wdd));Does this message (specifically the WCS / WCV values) have any useful meaning for the user ?
I think so, according to SBSA spec:
If WS0 is asserted and a timeout refresh occurs then the following must occur:
If the system is compliant to SBSA level 2 or higher the compare
value must retain its current value. This means that the compare value records the time that WS1 is asserted.
Quoted 5 lines
Quoted 3 lines
So, I think WCV can log the time when system reset by WDT, that may help user figure out the problem. but WCS can be delete I think.
How would that help ? It is just a number with no reference to anything.
This number is the time, when system reset by watchdog WCV : the number of clock, from system boot to system reset. Is that worthy to be logged? any suggestion ? :-)
Quoted 4 lines
Thanks,
Guenter
Signature · 10 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021
Re: [PATCH v3 5/6] Watchdog: introduce ARM SBSA watchdog driver
In reply to Fu WeiQuoted 3 lines · Fu Wei
It is a SPI, every CPU can get it,
But maybe I miss something, but please let me know if other CPU can not get the interrupt.
There's only one watchdog device, so there's only one interrupt. I don't know which CPU will get the interrupt, but the watchdog is not a per-CPU device.
Signature · 7 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project. -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 5/6] Watchdog: introduce ARM SBSA watchdog driver
Hi Timur
Quoted 11 lines · Timur Tabi
Quoted 4 lines · Fu Wei
It is a SPI, every CPU can get it,
But maybe I miss something, but please let me know if other CPU can not get the interrupt.There's only one watchdog device, so there's only one interrupt. I don't know which CPU will get the interrupt, but the watchdog is not a per-CPU device.
OK, first of all, I know, there maybe only watchdog in the system, but the Interrupter is SPI,
that means maybe some other device can also trigger the same Interrupter or maybe(in SMP) other CPU will handle it.
If this interrupter is triggered, that means system has goes wrong, who knows what is wrong ,
I have to make sure that system get into that routine ,because of the WS0, if not I won't do panic.
And in a interrupter routine , checking the Interrupter status register is right way to do.
Quoted 4 lines
--
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Signature · 10 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021
Re: [PATCH v3 5/6] Watchdog: introduce ARM SBSA watchdog driver
Quoted 4 lines · Fu Wei
If this interrupter is triggered, that means system has goes wrong, who knows what is wrong ,
I have to make sure that system get into that routine ,because of the WS0, if not I won't do panic.
But the interrupt handler is not registered as shared, which means that it cannot be generated by another device.
Quoted 2 lines
And in a interrupter routine , checking the Interrupter status register is right way to do.
If you get an interrupt, but WS0 is not set, then you should return IRQ_NONE instead of IRQ_HANDLED.
Also, I don't think IRQF_TIMER is correct. It's not a timer interrupt.
Watchdogs are *not* timers.
Signature · 7 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project. -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Guenter Roeck
maintainerRe: [PATCH v3 5/6] Watchdog: introduce ARM SBSA watchdog driver
In reply to Timur TabiQuoted 7 lines · Timur Tabi
Quoted 3 lines · Fu Wei
It is a SPI, every CPU can get it,
But maybe I miss something, but please let me know if other CPU can not get the interrupt.There's only one watchdog device, so there's only one interrupt. I don't know which CPU will get the interrupt, but the watchdog is not a per-CPU device.
Plus, that one interrupt is not shared, and the driver returns IRQ_HANDLED even if the bit is not set. So _something_ is definitely wrong. Either the interrupt is shared, then it needs to be requested as shared and the handler should only return IRQ_HANDLED if it actually handles the interrupt. Or it is not shared and the handler should always handle it.
Guenter
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 5/6] Watchdog: introduce ARM SBSA watchdog driver
Hi Guenter , Timur
Quoted 13 lines · Guenter Roeck
Quoted 12 lines · Timur Tabi
Quoted 4 lines · Fu Wei
It is a SPI, every CPU can get it,
But maybe I miss something, but please let me know if other CPU can not get the interrupt.There's only one watchdog device, so there's only one interrupt. I don't know which CPU will get the interrupt, but the watchdog is not a per-CPU device.
Quoted 6 lines
Plus, that one interrupt is not shared, and the driver returns
IRQ_HANDLEDeven if the bit is not set. So _something_ is definitely wrong. Either the interrupt is shared, then it needs to be requested as shared and the handler should only returnIRQ_HANDLEDif it actually handles the interrupt. Or it is not shared and the handler should always handle it.
I have thought about this again, For now, I did not find any reason to keep that "if (status & SBSA_GWDT_WCS_WS0)"
So you are right, I should delete it.
and for IRQF_TIMER, I will delete it.
Thanks for your correction.
Quoted 3 lines
Guenter
Signature · 10 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021
v4 cover Watchdog: introduce ARM SBSA watchdog driver
In reply to a message not in the archiveFrom: Fu Wei <[email protected]>
This patchset:
(1)Introduce Documentation/devicetree/bindings/watchdog/sbsa-gwdt.txt for FDT info of SBSA Generic Watchdog, and give two examples of adding SBSA Generic Watchdog device node into the dts files:
foundation-v8.dts and amd-seattle-soc.dtsi.
(2)Introduce ACPI GTDT parser: drivers/acpi/gtdt.c
Parse SBSA Generic Watchdog Structure in GTDT table of ACPI, and create a platform device with that information.
This platform device can be used by This Watchdog driver. drivers/clocksource/arm_arch_timer.c is simplified by this GTDT support.
(3)Introduce "pretimeout" into the watchdog framework, and update Documentation/watchdog/watchdog-kernel-api.txt to introduce:
(1)the new elements in the watchdog_device and watchdog_ops struct; (2)the new API "watchdog_init_timeouts".
(4)Introduce ARM SBSA watchdog driver:
a.Use linux kernel watchdog framework;
b.Work with FDT on ARM64;
c.Use "pretimeout" in watchdog framework;
d.In first timeout, do panic to save system context; e.Support getting timeout and pretimeout from parameter and FDT
at the driver init stage.
This patchset has been tested with watchdog daemon (ACPI/FDT, module/build-in) on the following platforms:
(1)ARM Foundation v8 model
Changelog:
v4: Refactor GTDT support code: remove it from arch/arm64/kernel/acpi.c,
put it into drivers/acpi/gtdt.c file.
Integrate the GTDT code of drivers/clocksource/arm_arch_timer.c into
drivers/acpi/gtdt.c.
Improve pretimeout support, fix "pretimeout == 0" problem.
Simplify sbsa_gwdt driver:
(1)timeout/pretimeout limits setup;
(2)keepalive function;
(3)delete "clk == 0" check;
(4)delete WS0 status bit check in interrupt routine;
(5)sbsa_gwdt_set_wcv function.v3: Delete "export arch_timer_get_rate" patch.
Driver back to use arch_timer_get_cntfrq.
Improve watchdog_init_timeouts function and update relevant documentation. Improve watchdog_timeout_invalid and watchdog_pretimeout_invalid. Improve foundation-v8.dts: delete the unnecessary tag of device node. Remove "ARM64 || COMPILE_TEST" from Kconfig.
Add comments in arch/arm64/kernel/acpi.c
Fix typoes and incorrect comments.
v2: Improve watchdog-kernel-api.txt documentation for pretimeout support.
Export "arch_timer_get_rate" in arm_arch_timer.c.
Add watchdog_init_timeouts API for pretimeout support in framework. Improve suspend and resume foundation in driver
Improve timeout/pretimeout values init code in driver. Delete unnecessary items of the sbsa_gwdt struct and #define. Delete all unnecessary debug info in driver.
Fix 64bit division bug.
Use the arch_timer interface to get watchdog clock rate. Add MODULE_DEVICE_TABLE for platform device id.
Fix typoes.
v1: The first version upstream patchset to linux mailing list.
Fu Wei (7):
Documentation: add sbsa-gwdt.txt documentation
ARM64: add SBSA Generic Watchdog device node in foundation-v8.dts
ARM64: add SBSA Generic Watchdog device node in amd-seattle-soc.dtsi
Watchdog: introdouce "pretimeout" into framework
Watchdog: introduce ARM SBSA watchdog driver
ACPI: add GTDT table parse driver into ACPI driver
clocksource: simplify ACPI code in arm_arch_timer.c
.../devicetree/bindings/watchdog/sbsa-gwdt.txt | 36 ++ Documentation/watchdog/watchdog-kernel-api.txt | 47 ++- arch/arm64/boot/dts/amd/amd-seattle-soc.dtsi | 11 + arch/arm64/boot/dts/arm/foundation-v8.dts | 10 + arch/arm64/kernel/time.c | 4 +- drivers/acpi/Kconfig | 9 + drivers/acpi/Makefile | 1 + drivers/acpi/gtdt.c | 180 +++++++++ drivers/clocksource/Kconfig | 1 + drivers/clocksource/arm_arch_timer.c | 60 +-- drivers/watchdog/Kconfig | 12 + drivers/watchdog/Makefile | 1 + drivers/watchdog/sbsa_gwdt.c | 426 +++++++++++++++++++++ drivers/watchdog/watchdog_core.c | 115 ++++-- drivers/watchdog/watchdog_dev.c | 53 +++ include/clocksource/arm_arch_timer.h | 8 + include/linux/acpi.h | 5 + include/linux/clocksource.h | 4 +- include/linux/watchdog.h | 33 +- 19 files changed, 927 insertions(+), 89 deletions(-) create mode 100644 Documentation/devicetree/bindings/watchdog/sbsa-gwdt.txt create mode 100644 drivers/acpi/gtdt.c create mode 100644 drivers/watchdog/sbsa_gwdt.c
Signature · 1 line
1.8.3.1
PATCH v4 1/7 Documentation: add sbsa-gwdt.txt documentation
From: Fu Wei <[email protected]>
The sbsa-gwdt.txt documentation in devicetree/bindings/watchdog is for introducing SBSA(Server Base System Architecture) Generic Watchdog device node info into FDT.
--- .../devicetree/bindings/watchdog/sbsa-gwdt.txt | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/sbsa-gwdt.txt
Documentation/devicetree/bindings/watchdog/sbsa-gwdt.txt new file +36 -0
@@ -0,0 +1,36 @@ +* SBSA(Server Base System Architecture) Generic Watchdog + +The SBSA Generic Watchdog Timer is used for resetting the system after +two stages of timeout. +More details: ARM-DEN-0029 - Server Base System Architecture (SBSA) + +Required properties: +- compatible : Should at least contain "arm,sbsa-gwdt". + +- reg : base physical address of the frames and length of memory mapped region. + +- reg-names : Should contain the resource reg names to show the order of + the values in "reg". + Must include the following entries : "refresh", "control". + +- interrupts : Should at least contain WS0 interrupt, + the WS1 Signal is optional. + +- interrupt-names : Should contain the resource interrupt names. + Must include the following entries : "ws0". "ws1" is optional. + +Optional properties +- timeout-sec : Watchdog pre-timeout and timeout values (in seconds). + The first is timeout values, then pre-timeout. + +Example for FVP Foundation Model v8: + +watchdog@2a440000 { + compatible = "arm,sbsa-gwdt"; + reg = <0x0 0x2a440000 0 0x10000>, + <0x0 0x2a450000 0 0x10000>; + reg-names = "control", "refresh"; + interrupts = <0 27 4>; + interrupt-names = "ws0"; + timeout-sec = <10 5>; +};
Signature · 1 line
1.9.1
PATCH v4 2/7 ARM64: add SBSA Generic Watchdog device node in foundation-v8.dts
In reply to [email protected]From: Fu Wei <[email protected]>
This can be a example of adding SBSA Generic Watchdog device node into some dts files for the Soc which contains SBSA Generic Watchdog.
--- arch/arm64/boot/dts/arm/foundation-v8.dts | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/arm64/boot/dts/arm/foundation-v8.dts +10 -0
@@ -237,4 +237,14 @@ }; }; }; + watchdog@2a440000 { + compatible = "arm,sbsa-gwdt"; + reg = <0x0 0x2a440000 0 0x10000>, + <0x0 0x2a450000 0 0x10000>; + reg-names = "control", + "refresh"; + interrupts = <0 27 4>; + interrupt-names = "ws0"; + timeout-sec = <10 5>; + }; };
Signature · 1 line
1.9.1
PATCH v4 3/7 ARM64: add SBSA Generic Watchdog device node in amd-seattle-soc.dtsi
In reply to [email protected]From: Fu Wei <[email protected]>
This can be a example of adding SBSA Generic Watchdog device node into some dts files for the Soc which contains SBSA Generic Watchdog.
--- arch/arm64/boot/dts/amd/amd-seattle-soc.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/arm64/boot/dts/amd/amd-seattle-soc.dtsi +11 -0
@@ -84,6 +84,17 @@ clock-names = "uartclk", "apb_pclk"; }; + watchdog0: watchdog@e0bb0000 { + compatible = "arm,sbsa-gwdt"; + reg = <0x0 0xe0bb0000 0 0x10000>, + <0x0 0xe0bc0000 0 0x10000>; + reg-names = "refresh", + "control"; + interrupts = <0 337 4>; + interrupt-names = "ws0"; + timeout-sec = <10 5>; + }; + spi0: ssp@e1020000 { status = "disabled"; compatible = "arm,pl022", "arm,primecell";
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v4 4/7 Watchdog: introdouce "pretimeout" into framework
In reply to [email protected]From: Fu Wei <[email protected]>
Also update Documentation/watchdog/watchdog-kernel-api.txt to introduce:
(1)the new elements in the watchdog_device and watchdog_ops struct; (2)the new API "watchdog_init_timeouts"
Reasons:
(1)kernel already has two watchdog drivers are using "pretimeout":
drivers/char/ipmi/ipmi_watchdog.c drivers/watchdog/kempld_wdt.c(but the definition is different)
(2)some other drivers are going to use this: ARM SBSA Generic Watchdog
--- Documentation/watchdog/watchdog-kernel-api.txt | 47 ++++++++-- drivers/watchdog/watchdog_core.c | 115 +++++++++++++++++++------ drivers/watchdog/watchdog_dev.c | 53 ++++++++++++ include/linux/watchdog.h | 33 ++++++- 4 files changed, 212 insertions(+), 36 deletions(-)
Documentation/watchdog/watchdog-kernel-api.txt +42 -5
@@ -49,6 +49,9 @@ struct watchdog_device { unsigned int timeout; unsigned int min_timeout; unsigned int max_timeout; + unsigned int pretimeout; + unsigned int min_pretimeout; + unsigned int max_pretimeout; void *driver_data; struct mutex lock; unsigned long status;
@@ -70,6 +73,9 @@ It contains following fields: * timeout: the watchdog timer's timeout value (in seconds). * min_timeout: the watchdog timer's minimum timeout value (in seconds). * max_timeout: the watchdog timer's maximum timeout value (in seconds). +* pretimeout: the watchdog timer's pretimeout value (in seconds). +* min_pretimeout: the watchdog timer's minimum pretimeout value (in seconds). +* max_pretimeout: the watchdog timer's maximum pretimeout value (in seconds). * bootstatus: status of the device after booting (reported with watchdog WDIOF_* status bits). * driver_data: a pointer to the drivers private data of a watchdog device.
@@ -92,6 +98,7 @@ struct watchdog_ops { int (*ping)(struct watchdog_device *); unsigned int (*status)(struct watchdog_device *); int (*set_timeout)(struct watchdog_device *, unsigned int); + int (*set_pretimeout)(struct watchdog_device *, unsigned int); unsigned int (*get_timeleft)(struct watchdog_device *); void (*ref)(struct watchdog_device *); void (*unref)(struct watchdog_device *);
@@ -153,9 +160,19 @@ they are supported. These optional routines/operations are: and -EIO for "could not write value to the watchdog". On success this routine should set the timeout value of the watchdog_device to the achieved timeout value (which may be different from the requested one - because the watchdog does not necessarily has a 1 second resolution). + because the watchdog does not necessarily has a 1 second resolution; + If the driver supports pretimeout, then the timeout value must be greater + than that). (Note: the WDIOF_SETTIMEOUT needs to be set in the options field of the watchdog's info structure). +* set_pretimeout: this routine checks and changes the pretimeout of the + watchdog timer device. It returns 0 on success, -EINVAL for "parameter out of + range" and -EIO for "could not write value to the watchdog". On success this + routine should set the pretimeout value of the watchdog_device to the + achieved pretimeout value (which may be different from the requested one + because the watchdog does not necessarily has a 1 second resolution). + (Note: the WDIOF_PRETIMEOUT needs to be set in the options field of the + watchdog's info structure). * get_timeleft: this routines returns the time that's left before a reset. * ref: the operation that calls kref_get on the kref of a dynamically allocated watchdog_device struct.
@@ -219,8 +236,28 @@ extern int watchdog_init_timeout(struct watchdog_device *wdd, unsigned int timeout_parm, struct device *dev); The watchdog_init_timeout function allows you to initialize the timeout field -using the module timeout parameter or by retrieving the timeout-sec property from -the device tree (if the module timeout parameter is invalid). Best practice is -to set the default timeout value as timeout value in the watchdog_device and -then use this function to set the user "preferred" timeout value. +using the module timeout parameter or by retrieving the first element of +the timeout-sec property from the device tree (if the module timeout parameter +is invalid). Best practice is to set the default timeout value as timeout value +in the watchdog_device and then use this function to set the user "preferred" +timeout value. +This routine returns zero on success and a negative errno code for failure. + +Some watchdog timers have two stage of timeouts(timeout and pretimeout), +to initialize the timeout and pretimeout fields at the same time, the following +function can be used: + +extern int watchdog_init_timeouts(struct watchdog_device *wdd, + unsigned int pretimeout_parm, + unsigned int timeout_parm, + struct device *dev); + +The watchdog_init_timeouts function allows you to initialize the pretimeout and +timeout fields using the module pretimeout and timeout parameter or by +retrieving the elements in the timeout-sec property(the first element is for +timeout, the second one is for pretimeout) from the device tree(if the module +pretimeout and timeout parameter are invalid). +Best practice is to set the default pretimeout and timeout value as pretimeout +and timeout value in the watchdog_device and then use this function to set the +user "preferred" pretimeout value. This routine returns zero on success and a negative errno code for failure.
drivers/watchdog/watchdog_core.c +87 -28
154 lines not on this page · raw message
drivers/watchdog/watchdog_dev.c +53 -0
65 lines not on this page · raw message
include/linux/watchdog.h +30 -3
@@ -25,6 +25,7 @@ struct watchdog_device;* @ping: The routine that sends a keepalive ping to the watchdog device. * @status: The routine that shows the status of the watchdog device. * @set_timeout:The routine for setting the watchdog devices timeout value. +* @set_pretimeout:The routine for setting the watchdog devices pretimeout value * @get_timeleft:The routine that get's the time that's left before a reset. * @ref: The ref operation for dyn. allocated watchdog_device structs * @unref: The unref operation for dyn. allocated watchdog_device structs
@@ -44,6 +45,7 @@ struct watchdog_ops {int (*ping)(struct watchdog_device *);unsigned int (*status)(struct watchdog_device *);int (*set_timeout)(struct watchdog_device *,unsigned int ); +int (*set_pretimeout)(struct watchdog_device *,unsigned int );unsigned int (*get_timeleft)(struct watchdog_device *);void (*ref)(struct watchdog_device *);void (*unref)(struct watchdog_device *);
@@ -62,6 +64,9 @@ struct watchdog_ops {* @timeout: The watchdog devices timeout value. * @min_timeout:The watchdog devices minimum timeout value. * @max_timeout:The watchdog devices maximum timeout value. +* @pretimeout: The watchdog devices pretimeout value. +* @min_pretimeout:The watchdog devices minimum pretimeout value. +* @max_pretimeout:The watchdog devices maximum pretimeout value. * @driver-data:Pointer to the drivers private data. * @lock: Lock for watchdog core internal use only. * @status: Field that contains the devices internal status bits.
@@ -86,6 +91,9 @@ struct watchdog_device {unsigned int timeout;unsigned int min_timeout;unsigned int max_timeout; +unsigned int pretimeout; +unsigned int min_pretimeout; +unsigned int max_pretimeout;void *driver_data;struct mutex lock;unsigned long status;
@@ -117,7 +125,17 @@ static inline void watchdog_set_nowayout(struct watchdog_device *wdd, bool nowaystatic inline bool watchdog_timeout_invalid (struct watchdog_device *wdd,unsigned int t) {return ((wdd->max_timeout !=0 ) && - (t < wdd->min_timeout || t > wdd->max_timeout)); + (t < wdd->min_timeout || t > wdd->max_timeout || + t <= wdd->pretimeout)); +} + +/* 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 (wdd->max_pretimeout !=0 && + (t < wdd->min_pretimeout || t > wdd->max_pretimeout || + (wdd->timeout !=0 && t >= wdd->timeout))); }/* Use the following functions to manipulate watchdog driver specific data */
@@ -132,11 +150,20 @@ static inline void *watchdog_get_drvdata(struct watchdog_device *wdd) }/* drivers/watchdog/watchdog_core.c */ -extern int watchdog_init_timeout (struct watchdog_device *wdd, -unsigned int timeout_parm,struct device *dev); +extern int watchdog_init_timeouts (struct watchdog_device *wdd, +unsigned int pretimeout_parm, +unsigned int timeout_parm, +struct device *dev);extern int watchdog_register_device (struct watchdog_device *);extern void watchdog_unregister_device (struct watchdog_device *); +static inline int watchdog_init_timeout (struct watchdog_device *wdd, +unsigned int timeout_parm, +struct device *dev) +{ +return watchdog_init_timeouts (wdd,0 , timeout_parm, dev); +} +#ifdef CONFIG_HARDLOCKUP_DETECTOR void watchdog_nmi_disable_all (void );void watchdog_nmi_enable_all (void );
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v4 5/7 Watchdog: introduce ARM SBSA watchdog driver
In reply to [email protected]From: Fu Wei <[email protected]>
This driver bases on linux kernel watchdog framework, and use "pretimeout" in the framework. It supports getting timeout and pretimeout from parameter and FDT at the driver init stage. In first timeout, the interrupt routine run panic to save system context.
--- drivers/watchdog/Kconfig | 12 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/sbsa_gwdt.c | 426 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 439 insertions(+) create mode 100644 drivers/watchdog/sbsa_gwdt.c
drivers/watchdog/Kconfig +12 -0
@@ -152,6 +152,18 @@ config ARM_SP805_WATCHDOG ARM Primecell SP805 Watchdog timer. This will reboot your system when the timeout is reached. +config ARM_SBSA_WATCHDOG + tristate "ARM SBSA Generic Watchdog" + depends on ARM64 + depends on ARM_ARCH_TIMER + select WATCHDOG_CORE + select ACPI_GTDT if ACPI + help + ARM SBSA Generic Watchdog. This watchdog has two Watchdog timeouts. + The first timeout will trigger a panic; the second timeout will + trigger a system reset. + More details: ARM DEN0029B - Server Base System Architecture (SBSA) + config AT91RM9200_WATCHDOG tristate "AT91RM9200 watchdog" depends on SOC_AT91RM9200 && MFD_SYSCON
drivers/watchdog/Makefile +1 -0
@@ -30,6 +30,7 @@ obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o # ARM Architecture obj-$(CONFIG_ARM_SP805_WATCHDOG) += sp805_wdt.o +obj-$(CONFIG_ARM_SBSA_WATCHDOG) += sbsa_gwdt.o obj-$(CONFIG_AT91RM9200_WATCHDOG) += at91rm9200_wdt.o obj-$(CONFIG_AT91SAM9X_WATCHDOG) += at91sam9_wdt.o obj-$(CONFIG_CADENCE_WATCHDOG) += cadence_wdt.o
drivers/watchdog/sbsa_gwdt.c new file +426 -0
426 lines not on this page · raw message
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v4 6/7 ACPI: add GTDT table parse driver into ACPI driver
In reply to [email protected]From: Fu Wei <[email protected]>
This driver adds support for parsing SBSA Generic Watchdog Structure in GTDT, and creating a platform device with that information. This allows the operating system to obtain device data from the resource of platform device.
The platform device named "sbsa-gwdt" can be used by the ARM SBSA Generic Watchdog driver.
--- drivers/acpi/Kconfig | 9 ++++ drivers/acpi/Makefile | 1 + drivers/acpi/gtdt.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 drivers/acpi/gtdt.c
drivers/acpi/Kconfig +9 -0
@@ -433,4 +433,13 @@ config XPOWER_PMIC_OPREGION endif +config ACPI_GTDT + bool "ACPI GTDT Support" + depends on ARM64 + help + GTDT (Generic Timer Description Table) provides information + for per-processor timers and Platform (memory-mapped) timers + for ARM platforms. Select this option to provide information + needed for the timers init. + endif # ACPI
drivers/acpi/Makefile +1 -0
@@ -96,3 +96,4 @@ obj-$(CONFIG_ACPI_EXTLOG) += acpi_extlog.o obj-$(CONFIG_PMIC_OPREGION) += pmic/intel_pmic.o obj-$(CONFIG_CRC_PMIC_OPREGION) += pmic/intel_pmic_crc.o obj-$(CONFIG_XPOWER_PMIC_OPREGION) += pmic/intel_pmic_xpower.o +obj-$(CONFIG_ACPI_GTDT) += gtdt.o
drivers/acpi/gtdt.c new file +137 -0
137 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v4 7/7 clocksource: simplify ACPI code in arm_arch_timer.c
In reply to [email protected]From: Fu Wei <[email protected]>
The patch update arm_arch_timer driver to use the function provided by the new GTDT driver of ACPI.
By this way, arm_arch_timer.c can be simplified, and separate all the ACPI GTDT knowledge from this timer driver.
--- arch/arm64/kernel/time.c | 4 +-- drivers/acpi/gtdt.c | 43 ++++++++++++++++++++++++++ drivers/clocksource/Kconfig | 1 + drivers/clocksource/arm_arch_timer.c | 60 +++++++----------------------------- include/clocksource/arm_arch_timer.h | 8 +++++ include/linux/acpi.h | 5 +++ include/linux/clocksource.h | 4 +-- 7 files changed, 72 insertions(+), 53 deletions(-)
arch/arm64/kernel/time.c +2 -2
@@ -75,9 +75,9 @@ void __init time_init(void)/* * Since ACPI or FDT will only one be available in the system, -* we can use acpi_generic_timer_init() here safely +* we can use arch_timer_acpi_init() here safely */ -acpi_generic_timer_init (); +arch_timer_acpi_init (); arch_timer_rate =arch_timer_get_rate ();if (!arch_timer_rate)
drivers/acpi/gtdt.c +43 -0
55 lines not on this page · raw message
drivers/clocksource/Kconfig +1 -0
@@ -109,6 +109,7 @@ config CLKSRC_EFM32 config ARM_ARCH_TIMER bool select CLKSRC_OF if OF + select ACPI_GTDT if ACPI config ARM_ARCH_TIMER_EVTSTREAM bool "Support for ARM architected timer event stream generation"
drivers/clocksource/arm_arch_timer.c +11 -49
79 lines not on this page · raw message
include/clocksource/arm_arch_timer.h +8 -0
@@ -43,6 +43,14 @@ enum arch_timer_reg {#define ARCH_TIMER_EVT_STREAM_FREQ 10000/* 100us */ +struct arch_timer_data { +int phys_secure_ppi; +int phys_nonsecure_ppi; +int virt_ppi; +int hyp_ppi; +bool c3stop; +}; +#ifdef CONFIG_ARM_ARCH_TIMER extern u32 arch_timer_get_rate (void );
include/linux/acpi.h +5 -0
@@ -458,6 +458,11 @@ void acpi_walk_dep_device_list(acpi_handle handle);struct platform_device *acpi_create_platform_device (struct acpi_device *);#define ACPI_PTR (_ptr) (_ptr) +#ifdef CONFIG_ACPI_GTDT +struct arch_timer_data ; +int __init gtdt_arch_timer_data_init (struct arch_timer_data *data); +#endif +#else /* !CONFIG_ACPI */ #define acpi_disabled 1
include/linux/clocksource.h +2 -2
@@ -254,9 +254,9 @@ static inline void clocksource_of_init(void) {}#endif #ifdef CONFIG_ACPI -void acpi_generic_timer_init (void ); +void arch_timer_acpi_init (void );#else -static inline void acpi_generic_timer_init (void ) { } +static inline void arch_timer_acpi_init (void ) { }#endif #endif /* _LINUX_CLOCKSOURCE_H */
Signature · 1 line
1.9.1
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
In reply to [email protected]Quoted 15 lines · On 06/01/2015 11:05 PM, [email protected] wrote:
drivers/watchdog/sbsa_gwdt.c new file +15
-0+/* +* help functions for accessing 32bit registers of SBSA Generic Watchdog +*/ +static void sbsa_gwdt_cf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (val, gwdt->control_base + reg); +} + +static void sbsa_gwdt_rf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd);
drivers/watchdog/sbsa_gwdt.c line 127
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+ +writel_relaxed (val, gwdt->refresh_base + reg); +} + +static u32 sbsa_gwdt_cf_read (unsigned int reg,struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +return readl_relaxed (gwdt->control_base + reg); +}
I still think you should get rid of these functions and just call readl_relaxed() and writel_relaxed() every time, but I won't complain again if you keep them.
drivers/watchdog/sbsa_gwdt.c line 240
Quoted 11 lines
drivers/watchdog/sbsa_gwdt.c new file +11
-0+static irqreturn_t sbsa_gwdt_interrupt (int irq,void *dev_id) +{ +struct sbsa_gwdt *gwdt = (struct sbsa_gwdt *)dev_id; +struct watchdog_device *wdd = &gwdt->wdd; + +if (wdd->pretimeout) +/* The pretimeout is valid, go panic */ +panic ("SBSA Watchdog pre-timeout" ); +else +/* We don't use pretimeout, trigger WS1 now*/ +sbsa_gwdt_set_wcv (wdd,0 );
I don't like this. The triggering of the hardware reset should never depend on an interrupt being handled properly. You should always program WCV correctly in advance. This is especially true since pre-timeout will probably rarely be used. So what happens if the CPU is totally hung and this interrupt handler is never called? When will the timeout occur?
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +5
-0+static int sbsa_gwdt_probe (struct platform_device *pdev) +{ +u64 first_period_max =U64_MAX ; +struct device *dev = &pdev->dev; +struct watchdog_device *wdd;
drivers/watchdog/sbsa_gwdt.c line 278
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+struct sbsa_gwdt *gwdt; +struct resource *res; +void *rf_base, *cf_base; +int ret, irq; +u32 status; + + gwdt =devm_kzalloc (dev,sizeof (*gwdt),GFP_KERNEL ); +if (!gwdt) +return -ENOMEM ; +platform_set_drvdata (pdev, gwdt);
You should probably do this *after* calling platform_get_irq_byname().
Quoted 37 lines
drivers/watchdog/sbsa_gwdt.c new file +37
-0+ + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"refresh" ); + rf_base =devm_ioremap_resource (dev, res); +if (IS_ERR (rf_base)) +return PTR_ERR (rf_base); + + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"control" ); + cf_base =devm_ioremap_resource (dev, res); +if (IS_ERR (cf_base)) +return PTR_ERR (cf_base); + + irq =platform_get_irq_byname (pdev,"ws0" ); +if (irq <0 ) { +dev_err (dev,"unable to get ws0 interrupt.\n" ); +return irq; + } + +/* +* Get the frequency of system counter from the cp15 interface of ARM +* Generic timer. We don't need to check it, because if it returns "0", +* system would panic in very early stage. +*/ + gwdt->clk =arch_timer_get_cntfrq (); + gwdt->refresh_base = rf_base; + gwdt->control_base = cf_base; + + wdd = &gwdt->wdd; + wdd->parent = dev; + wdd->info = &sbsa_gwdt_info; + wdd->ops = &sbsa_gwdt_ops; +watchdog_set_drvdata (wdd, gwdt); +watchdog_set_nowayout (wdd, nowayout); + + wdd->min_pretimeout =0 ; + wdd->max_pretimeout =U32_MAX / gwdt->clk; + wdd->min_timeout =1 ; +do_div (first_period_max, gwdt->clk);
drivers/watchdog/sbsa_gwdt.c line 325
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+ wdd->max_timeout = first_period_max; + + wdd->pretimeout =DEFAULT_PRETIMEOUT ; + wdd->timeout =DEFAULT_TIMEOUT ; +watchdog_init_timeouts (wdd, pretimeout, timeout, dev); + + status =sbsa_gwdt_cf_read (SBSA_GWDT_WCS , wdd); +if (status &SBSA_GWDT_WCS_WS1 ) { +dev_warn (dev,"System reset by WDT(WCV: %llx)\n" , +sbsa_gwdt_get_wcv (wdd));
"System was previously reset via watchdog" is much clearer.
drivers/watchdog/sbsa_gwdt.c line 330
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +5
-0+ wdd->bootstatus |=WDIOF_CARDRESET ; + } +/* Check if watchdog is already enabled */ +if (status &SBSA_GWDT_WCS_EN ) { +dev_warn (dev,"already enabled!\n" );
"watchdog is already enabled". Never use exclamation marks in kernel messages.
Quoted 9 lines
drivers/watchdog/sbsa_gwdt.c new file +9
-0+sbsa_gwdt_keepalive (wdd); + } + +/* update pretimeout to WOR */ +sbsa_gwdt_set_pretimeout (wdd, wdd->pretimeout); + + ret =devm_request_irq (dev, irq, sbsa_gwdt_interrupt,0 , + pdev->name, gwdt); +if (ret) {
drivers/watchdog/sbsa_gwdt.c line 349
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+dev_err (dev,"unable to request IRQ %d\n" , irq); +return ret; + } + + ret =watchdog_register_device (wdd); +if (ret) +return ret; + +dev_info (dev,"Initialized with %ds timeout, %ds pretimeout @ %u Hz\n" , + wdd->timeout, wdd->pretimeout, gwdt->clk);
if (wdd->pretimeout)
"watchdog initialized to %us timeout and %us pre-timeout at %u Hz\n",wdd->timeout, wdd->pretimeout, gwdt->clk
else
"watchdog initialized to %us timeout at %u Hz\n", wdd->timeout, gwdt->clk
I think it's unlikely that users will use pre-timeout, so your code should treat pre-timeout as a special case, not the normal usage.
Signature · 7 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project. -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Guenter Roeck
maintainerRe: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
Quoted 141 lines · Timur Tabi
Quoted 15 lines · On 06/01/2015 11:05 PM, [email protected] wrote:
drivers/watchdog/sbsa_gwdt.c new file +15
-0+/* +* help functions for accessing 32bit registers of SBSA Generic Watchdog +*/ +static void sbsa_gwdt_cf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (val, gwdt->control_base + reg); +} + +static void sbsa_gwdt_rf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd);drivers/watchdog/sbsa_gwdt.c line 127
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+ +writel_relaxed (val, gwdt->refresh_base + reg); +} + +static u32 sbsa_gwdt_cf_read (unsigned int reg,struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +return readl_relaxed (gwdt->control_base + reg); +}I still think you should get rid of these functions and just call
readl_relaxed()andwritel_relaxed()every time, but I won't complain again if you keep them.drivers/watchdog/sbsa_gwdt.c line 240
Quoted 11 lines
drivers/watchdog/sbsa_gwdt.c new file +11
-0+static irqreturn_t sbsa_gwdt_interrupt (int irq,void *dev_id) +{ +struct sbsa_gwdt *gwdt = (struct sbsa_gwdt *)dev_id; +struct watchdog_device *wdd = &gwdt->wdd; + +if (wdd->pretimeout) +/* The pretimeout is valid, go panic */ +panic ("SBSA Watchdog pre-timeout" ); +else +/* We don't use pretimeout, trigger WS1 now*/ +sbsa_gwdt_set_wcv (wdd,0 );I don't like this. The triggering of the hardware reset should never depend on an interrupt being handled properly. You should always program WCV correctly in advance. This is especially true since pre-timeout will probably rarely be used. So what happens if the CPU is totally hung and this interrupt handler is never called? When will the timeout occur?
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +5
-0+static int sbsa_gwdt_probe (struct platform_device *pdev) +{ +u64 first_period_max =U64_MAX ; +struct device *dev = &pdev->dev; +struct watchdog_device *wdd;drivers/watchdog/sbsa_gwdt.c line 278
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+struct sbsa_gwdt *gwdt; +struct resource *res; +void *rf_base, *cf_base; +int ret, irq; +u32 status; + + gwdt =devm_kzalloc (dev,sizeof (*gwdt),GFP_KERNEL ); +if (!gwdt) +return -ENOMEM ; +platform_set_drvdata (pdev, gwdt);You should probably do this *after* calling
platform_get_irq_byname().Quoted 37 lines
drivers/watchdog/sbsa_gwdt.c new file +37
-0+ + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"refresh" ); + rf_base =devm_ioremap_resource (dev, res); +if (IS_ERR (rf_base)) +return PTR_ERR (rf_base); + + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"control" ); + cf_base =devm_ioremap_resource (dev, res); +if (IS_ERR (cf_base)) +return PTR_ERR (cf_base); + + irq =platform_get_irq_byname (pdev,"ws0" ); +if (irq <0 ) { +dev_err (dev,"unable to get ws0 interrupt.\n" ); +return irq; + } + +/* +* Get the frequency of system counter from the cp15 interface of ARM +* Generic timer. We don't need to check it, because if it returns "0", +* system would panic in very early stage. +*/ + gwdt->clk =arch_timer_get_cntfrq (); + gwdt->refresh_base = rf_base; + gwdt->control_base = cf_base; + + wdd = &gwdt->wdd; + wdd->parent = dev; + wdd->info = &sbsa_gwdt_info; + wdd->ops = &sbsa_gwdt_ops; +watchdog_set_drvdata (wdd, gwdt); +watchdog_set_nowayout (wdd, nowayout); + + wdd->min_pretimeout =0 ; + wdd->max_pretimeout =U32_MAX / gwdt->clk; + wdd->min_timeout =1 ; +do_div (first_period_max, gwdt->clk);drivers/watchdog/sbsa_gwdt.c line 325
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+ wdd->max_timeout = first_period_max; + + wdd->pretimeout =DEFAULT_PRETIMEOUT ; + wdd->timeout =DEFAULT_TIMEOUT ; +watchdog_init_timeouts (wdd, pretimeout, timeout, dev); + + status =sbsa_gwdt_cf_read (SBSA_GWDT_WCS , wdd); +if (status &SBSA_GWDT_WCS_WS1 ) { +dev_warn (dev,"System reset by WDT(WCV: %llx)\n" , +sbsa_gwdt_get_wcv (wdd));"System was previously reset via watchdog" is much clearer.
drivers/watchdog/sbsa_gwdt.c line 330
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +5
-0+ wdd->bootstatus |=WDIOF_CARDRESET ; + } +/* Check if watchdog is already enabled */ +if (status &SBSA_GWDT_WCS_EN ) { +dev_warn (dev,"already enabled!\n" );"watchdog is already enabled". Never use exclamation marks in kernel messages.
Quoted 9 lines
drivers/watchdog/sbsa_gwdt.c new file +9
-0+sbsa_gwdt_keepalive (wdd); + } + +/* update pretimeout to WOR */ +sbsa_gwdt_set_pretimeout (wdd, wdd->pretimeout); + + ret =devm_request_irq (dev, irq, sbsa_gwdt_interrupt,0 , + pdev->name, gwdt); +if (ret) {drivers/watchdog/sbsa_gwdt.c line 349
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+dev_err (dev,"unable to request IRQ %d\n" , irq); +return ret; + } + + ret =watchdog_register_device (wdd); +if (ret) +return ret; + +dev_info (dev,"Initialized with %ds timeout, %ds pretimeout @ %u Hz\n" , + wdd->timeout, wdd->pretimeout, gwdt->clk);if (
wdd->pretimeout)
Quoted 6 lines
"watchdog initialized to %us timeout and %us pre-timeout at %u Hz\n", wdd->timeout, wdd->pretimeout, gwdt->clk else "watchdog initialized to %us timeout at %u Hz\n", wdd->timeout, gwdt->clkI think it's unlikely that users will use pre-timeout, so your code should treat pre-timeout as a special case, not the normal usage.
+1 to all your comments.
Guenter
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Guenter Roeck
maintainerRe: [PATCH v4 4/7] Watchdog: introdouce "pretimeout" into framework
In reply to [email protected]Quoted 132 lines · On 06/01/2015 09:05 PM, [email protected] wrote:
From: Fu Wei <[email protected]>
Also update
Documentation/watchdog/watchdog-kernel-api.txtto introduce:
(1)the new elements in thewatchdog_deviceandwatchdog_opsstruct; (2)the new API "watchdog_init_timeouts"Reasons:
(1)kernel already has two watchdog drivers are using "pretimeout":
drivers/char/ipmi/ipmi_watchdog.cdrivers/watchdog/kempld_wdt.c(but the definition is different)
(2)some other drivers are going to use this: ARM SBSA Generic WatchdogSigned-off-by Fu Wei <[email protected]>--- Documentation/watchdog/watchdog-kernel-api.txt | 47 ++++++++-- drivers/watchdog/watchdog_core.c | 115 +++++++++++++++++++------ drivers/watchdog/watchdog_dev.c | 53 ++++++++++++ include/linux/watchdog.h | 33 ++++++- 4 files changed, 212 insertions(+), 36 deletions(-)Documentation/watchdog/watchdog-kernel-api.txt +42
-5@@ -49,6 +49,9 @@ struct watchdog_device { unsigned int timeout; unsigned int min_timeout; unsigned int max_timeout; + unsigned int pretimeout; + unsigned int min_pretimeout; + unsigned int max_pretimeout; void *driver_data; struct mutex lock; unsigned long status;@@ -70,6 +73,9 @@ It contains following fields: * timeout: the watchdog timer's timeout value (in seconds). * min_timeout: the watchdog timer's minimum timeout value (in seconds). * max_timeout: the watchdog timer's maximum timeout value (in seconds). +* pretimeout: the watchdog timer's pretimeout value (in seconds). +* min_pretimeout: the watchdog timer's minimum pretimeout value (in seconds). +* max_pretimeout: the watchdog timer's maximum pretimeout value (in seconds). * bootstatus: status of the device after booting (reported with watchdog WDIOF_* status bits). * driver_data: a pointer to the drivers private data of a watchdog device.@@ -92,6 +98,7 @@ struct watchdog_ops { int (*ping)(struct watchdog_device *); unsigned int (*status)(struct watchdog_device *); int (*set_timeout)(struct watchdog_device *, unsigned int); + int (*set_pretimeout)(struct watchdog_device *, unsigned int); unsigned int (*get_timeleft)(struct watchdog_device *); void (*ref)(struct watchdog_device *); void (*unref)(struct watchdog_device *);@@ -153,9 +160,19 @@ they are supported. These optional routines/operations are: and -EIO for "could not write value to the watchdog". On success this routine should set the timeout value of the watchdog_device to the achieved timeout value (which may be different from the requested one - because the watchdog does not necessarily has a 1 second resolution). + because the watchdog does not necessarily has a 1 second resolution; + If the driver supports pretimeout, then the timeout value must be greater + than that). (Note: the WDIOF_SETTIMEOUT needs to be set in the options field of the watchdog's info structure). +* set_pretimeout: this routine checks and changes the pretimeout of the + watchdog timer device. It returns 0 on success, -EINVAL for "parameter out of + range" and -EIO for "could not write value to the watchdog". On success this + routine should set the pretimeout value of the watchdog_device to the + achieved pretimeout value (which may be different from the requested one + because the watchdog does not necessarily has a 1 second resolution). + (Note: the WDIOF_PRETIMEOUT needs to be set in the options field of the + watchdog's info structure). * get_timeleft: this routines returns the time that's left before a reset. * ref: the operation that calls kref_get on the kref of a dynamically allocated watchdog_device struct.@@ -219,8 +236,28 @@ extern int watchdog_init_timeout(struct watchdog_device *wdd, unsigned int timeout_parm, struct device *dev); The watchdog_init_timeout function allows you to initialize the timeout field -using the module timeout parameter or by retrieving the timeout-sec property from -the device tree (if the module timeout parameter is invalid). Best practice is -to set the default timeout value as timeout value in the watchdog_device and -then use this function to set the user "preferred" timeout value. +using the module timeout parameter or by retrieving the first element of +the timeout-sec property from the device tree (if the module timeout parameter +is invalid). Best practice is to set the default timeout value as timeout value +in the watchdog_device and then use this function to set the user "preferred" +timeout value. +This routine returns zero on success and a negative errno code for failure. + +Some watchdog timers have two stage of timeouts(timeout and pretimeout), +to initialize the timeout and pretimeout fields at the same time, the following +function can be used: + +extern int watchdog_init_timeouts(struct watchdog_device *wdd, + unsigned int pretimeout_parm, + unsigned int timeout_parm, + struct device *dev); + +The watchdog_init_timeouts function allows you to initialize the pretimeout and +timeout fields using the module pretimeout and timeout parameter or by +retrieving the elements in the timeout-sec property(the first element is for +timeout, the second one is for pretimeout) from the device tree(if the module +pretimeout and timeout parameter are invalid). +Best practice is to set the default pretimeout and timeout value as pretimeout +and timeout value in the watchdog_device and then use this function to set the +user "preferred" pretimeout value. This routine returns zero on success and a negative errno code for failure.drivers/watchdog/watchdog_core.c +8
-3@@ -43,60 +43,119 @@static DEFINE_IDA (watchdog_ida);static struct class *watchdog_class; -static void watchdog_check_min_max_timeout (struct watchdog_device *wdd) +static void watchdog_check_min_max_timeouts (struct watchdog_device *wdd) {/* -* Check that we have valid min and max timeout values, if -* not reset them both to 0 (=not used or unknown) +* Check that we have valid min and max pretimeout and timeout values, +* if not reset them both to 0 (=not used or unknown) */ +if (wdd->min_pretimeout > wdd->max_pretimeout) { +pr_info ("Invalid min and max pretimeout, resetting to 0\n" ); + wdd->min_pretimeout =0 ; + wdd->max_pretimeout =0 ; + }if (wdd->min_timeout > wdd->max_timeout) {pr_info ("Invalid min and max timeout values, resetting to 0!\n" ); wdd->min_timeout =0 ;
drivers/watchdog/watchdog_core.c line 69
Quoted 10 lines
drivers/watchdog/watchdog_core.c +8
-0wdd->max_timeout =0 ; } +/* +* Check that we have valid min timeout and max pretimeout values, +* if not reset them. +*/ +if (wdd->min_pretimeout && wdd->min_timeout < wdd->min_pretimeout) { +pr_info ("Invalid min_timeout, resetting to min_pretimeout+1\n" ); + wdd->min_timeout = wdd->min_pretimeout +1 ; + }
min_timeout = 10max_timeout = 20min_pretimeout = 30max_pretimeout = 40
will result in min_timeout set to 31.
drivers/watchdog/watchdog_core.c line 72
Quoted 3 lines
drivers/watchdog/watchdog_core.c +3
-0+if (wdd->max_pretimeout && wdd->max_timeout < wdd->max_pretimeout) { +pr_info ("Invalid max_pretimeout, resetting to max_timeout-1\n" ); + wdd->max_pretimeout = wdd->max_timeout -1 ;
and then you set max_pretimeout to 19.
So we'll end up with
min_timeout = 31max_timeout = 20min_pretimeout = 30max_pretimeout = 19
Another example: max_pretimeout = 10, max_timeout = 0 -> max_pretimeout = -1.
drivers/watchdog/watchdog_core.c line 73
Quoted 1 line
drivers/watchdog/watchdog_core.c +1
-0+ }
You'll need to determine valid ranges and then enforce those. Maybe something like
min_pretimeout < min_timeout < max_timeout
and
min_pretimeout < max_pretimeout < max_timeout
Not sure if we should adjust anything to a value different to 0. Seems to me this is just asking for trouble.
Quoted 7 lines
drivers/watchdog/watchdog_core.c +2
-1}/** -* watchdog_init_timeout() - initialize the timeout field +* watchdog_init_timeouts() - initialize the pretimeout and timeout field +* @pretimeout_parm: pretimeout module parameter * @timeout_parm: timeout module parameter
drivers/watchdog/watchdog_core.c line 84
Quoted 10 lines
drivers/watchdog/watchdog_core.c +3
-5* @dev: Device that stores the timeout-sec property * -* Initialize the timeout field of the watchdog_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 -* be the default timeout value. +* Initialize the pretimeout and timeout field of the watchdog_device struct +* with either the pretimeout and timeout module parameter (if it is valid +* value) or the timeout-sec property (only if it is a valid value and the
just 'if it is valid', or 'if it is a valid value' in both cases.
drivers/watchdog/watchdog_core.c line 85
Quoted 1 line
drivers/watchdog/watchdog_core.c +1
-0+* pretimeout_parm and timeout_parm is out of bounds). If none of them are
s/and/or/
Quoted 22 lines
drivers/watchdog/watchdog_core.c +9
-7+* valid, then we keep the old value (which should normally be the default +* timeout value). * * A zero is returned on success and -EINVAL for failure. */ -int watchdog_init_timeout (struct watchdog_device *wdd, -unsigned int timeout_parm,struct device *dev) +int watchdog_init_timeouts (struct watchdog_device *wdd, +unsigned int pretimeout_parm, +unsigned int timeout_parm, +struct device *dev) { -unsigned int t =0 ; -int ret =0 ; +int ret =0 , length =0 ; +u32 timeouts[2 ] = {0 }; -watchdog_check_min_max_timeout (wdd); +watchdog_check_min_max_timeouts (wdd); -/* try to get the timeout module parameter first */ -if (!watchdog_timeout_invalid (wdd, timeout_parm) && timeout_parm) {
drivers/watchdog/watchdog_core.c line 108
Quoted 10 lines
drivers/watchdog/watchdog_core.c +8
-2- wdd->timeout = timeout_parm; -return ret; +/* +* Try to get the pretimeout module parameter first, +* but it can be "0", that means we don't use pretimeout. +*/ +if (pretimeout_parm) { +if (!watchdog_pretimeout_invalid (wdd, pretimeout_parm)) + timeouts[1 ] = pretimeout_parm; + ret = -EINVAL ;/* pretimeout_parm is not "0", and invalid */
pretimeout_parm is always invalid ? Why ?
drivers/watchdog/watchdog_core.c line 113
Quoted 6 lines
drivers/watchdog/watchdog_core.c +4
-1} -if (timeout_parm) + +/* +* Try to get the timeout module parameter, +* if it's valid and pretimeout is ont invalid(ret == 0),
s/ont/not/
drivers/watchdog/watchdog_core.c line 117
Quoted 4 lines
drivers/watchdog/watchdog_core.c +4
-0+* assignment and return zero. Otherwise, try dtb. +*/ +if (timeout_parm) { +if (!watchdog_timeout_invalid (wdd, timeout_parm) && !ret) {
Unless I am missing something, you'll never get here if the pretimeout module parameter is set.
Quoted 4 lines
drivers/watchdog/watchdog_core.c +4
-0+ wdd->timeout = timeout_parm; + wdd->pretimeout = timeouts[1 ]; +return 0 ; + }
drivers/watchdog/watchdog_core.c line 130
Quoted 10 lines
drivers/watchdog/watchdog_core.c +7
-1ret = -EINVAL ; + } -/* try to get the timeout_sec property */ +/* +* We get here, the situation is one of them: +* (1)at least one of parameters is invalid(ret = -EINVAL); +* (2)both of them are 0.(ret = 0) +* So give up the module parameter(at least drop the invalid one), +* try to get the timeout_sec property from dtb.
Please simplify the comment.
Either at least one of the module parameters is invalid, or both of them are 0. Try to get the timeout_sec property.
Quoted 4 lines
drivers/watchdog/watchdog_core.c +1
-1+*/ if (dev ==NULL || dev->of_node ==NULL )return ret; -of_property_read_u32 (dev->of_node,"timeout-sec" , &t);
drivers/watchdog/watchdog_core.c line 138
Quoted 10 lines
drivers/watchdog/watchdog_core.c +4
-5-if (!watchdog_timeout_invalid (wdd, t) && t) - wdd->timeout = t; -else - ret = -EINVAL ; -return ret; +/* +* We get here, that means maybe we can get timeouts from dtb, +* if "timeout-sec" is available and the data is valid. +*/
That comment is not needed; it is obvious.
drivers/watchdog/watchdog_core.c line 140
Quoted 2 lines
drivers/watchdog/watchdog_core.c +2
-0+of_find_property (dev->of_node,"timeout-sec" , &length); +if (length >0 && length <=sizeof (u32) *2 ) {
You need to check the return value of of_find_property() instead of assuming that length will be 0 if it is not found.
drivers/watchdog/watchdog_core.c line 146
Quoted 6 lines
drivers/watchdog/watchdog_core.c +6
-0+of_property_read_u32_array (dev->of_node, +"timeout-sec" , timeouts, + length /sizeof (u32)); +if (length ==sizeof (u32) *2 && timeouts[1 ] && +watchdog_pretimeout_invalid (wdd, timeouts[1 ])) +return -EINVAL ;/* pretimeout is invalid */
Obvious comment.
Quoted 142 lines
drivers/watchdog/watchdog_core.c +12
-2+ +if (!watchdog_timeout_invalid (wdd, timeouts[0 ]) && + timeouts[0 ]) { + wdd->timeout = timeouts[0 ]; + wdd->pretimeout = timeouts[1 ]; +return 0 ; + } + } + +return -EINVAL ; } -EXPORT_SYMBOL_GPL (watchdog_init_timeout); +EXPORT_SYMBOL_GPL (watchdog_init_timeouts);/** * watchdog_register_device() - register a watchdog device @@ -119,7 +178,7 @@ int watchdog_register_device(struct watchdog_device *wdd)if (wdd->ops->start ==NULL || wdd->ops->stop ==NULL )return -EINVAL ; -watchdog_check_min_max_timeout (wdd); +watchdog_check_min_max_timeouts (wdd);/* * Note: now that all watchdog_device data has been verified, we drivers/watchdog/watchdog_dev.c +53
-0@@ -218,6 +218,38 @@ out_timeout: }/* +* watchdog_set_pretimeout: set the watchdog timer pretimeout +* @wddev: the watchdog device to set the timeout for +* @pretimeout: pretimeout to set in seconds +*/ + +static int watchdog_set_pretimeout (struct watchdog_device *wddev, +unsigned int pretimeout) +{ +int err; + +if (!wddev->ops->set_pretimeout || + !(wddev->info->options &WDIOF_PRETIMEOUT )) +return -EOPNOTSUPP ; + +if (watchdog_pretimeout_invalid (wddev, pretimeout)) +return -EINVAL ; + +mutex_lock (&wddev->lock); + +if (test_bit (WDOG_UNREGISTERED , &wddev->status)) { + err = -ENODEV ; + goto out_pretimeout; + } + + err = wddev->ops->set_pretimeout (wddev, pretimeout); + +out_pretimeout: +mutex_unlock (&wddev->lock); +return err; +} + +/* * watchdog_get_timeleft: wrapper to get the time left before a reboot * @wddev: the watchdog device to get the remaining time from * @timeleft: the time that's left @@ -388,6 +420,27 @@ static long watchdog_ioctl(struct file *file, unsigned int cmd,if (wdd->timeout ==0 )return -EOPNOTSUPP ;return put_user (wdd->timeout, p); +case WDIOC_SETPRETIMEOUT : +/* check if we support the pretimeout */ +if (!(wdd->info->options &WDIOF_PRETIMEOUT )) +return -EOPNOTSUPP ; +if (get_user (val, p)) +return -EFAULT ; + err =watchdog_set_pretimeout (wdd, val); +if (err <0 ) +return err; +/* +* If the watchdog is active then we send a keepalive ping +* to make sure that the watchdog keeps running (and if +* possible that it takes the new pretimeout) +*/ +watchdog_ping (wdd); +/* Fall */ +case WDIOC_GETPRETIMEOUT : +/* check if we support the pretimeout */ +if (wdd->info->options &WDIOF_PRETIMEOUT ) +return put_user (wdd->pretimeout, p); +return -EOPNOTSUPP ;case WDIOC_GETTIMELEFT : err =watchdog_get_timeleft (wdd, &val);if (err)include/linux/watchdog.h +9
-1@@ -25,6 +25,7 @@ struct watchdog_device;* @ping: The routine that sends a keepalive ping to the watchdog device. * @status: The routine that shows the status of the watchdog device. * @set_timeout:The routine for setting the watchdog devices timeout value. +* @set_pretimeout:The routine for setting the watchdog devices pretimeout value * @get_timeleft:The routine that get's the time that's left before a reset. * @ref: The ref operation for dyn. allocated watchdog_device structs * @unref: The unref operation for dyn. allocated watchdog_device structs @@ -44,6 +45,7 @@ struct watchdog_ops {int (*ping)(struct watchdog_device *);unsigned int (*status)(struct watchdog_device *);int (*set_timeout)(struct watchdog_device *,unsigned int ); +int (*set_pretimeout)(struct watchdog_device *,unsigned int );unsigned int (*get_timeleft)(struct watchdog_device *);void (*ref)(struct watchdog_device *);void (*unref)(struct watchdog_device *);@@ -62,6 +64,9 @@ struct watchdog_ops {* @timeout: The watchdog devices timeout value. * @min_timeout:The watchdog devices minimum timeout value. * @max_timeout:The watchdog devices maximum timeout value. +* @pretimeout: The watchdog devices pretimeout value. +* @min_pretimeout:The watchdog devices minimum pretimeout value. +* @max_pretimeout:The watchdog devices maximum pretimeout value. * @driver-data:Pointer to the drivers private data. * @lock: Lock for watchdog core internal use only. * @status: Field that contains the devices internal status bits. @@ -86,6 +91,9 @@ struct watchdog_device {unsigned int timeout;unsigned int min_timeout;unsigned int max_timeout; +unsigned int pretimeout; +unsigned int min_pretimeout; +unsigned int max_pretimeout;void *driver_data;struct mutex lock;unsigned long status;@@ -117,7 +125,17 @@ static inline void watchdog_set_nowayout(struct watchdog_device *wdd, bool nowaystatic inline bool watchdog_timeout_invalid (struct watchdog_device *wdd,unsigned int t) { return ((wdd->max_timeout != 0) && - (t < wdd->min_timeout || t > wdd->max_timeout)); + (t < wdd->min_timeout || t > wdd->max_timeout ||
include/linux/watchdog.h static inline void watchdog_set_nowayout(struct watchdog_device *wdd, bool noway · line 138
Quoted 10 lines
include/linux/watchdog.h +10
-0+ t <= wdd->pretimeout)); +} + +/* 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 (wdd->max_pretimeout !=0 && + (t < wdd->min_pretimeout || t > wdd->max_pretimeout || + (wdd->timeout !=0 && t >= wdd->timeout)));
This validates a pretimeout as valid if max_pretimeout == 0, no matter what timeout is set to.
Do we really need to check if timeout == 0 ? Can that ever happen ?
include/linux/watchdog.h static inline void *watchdog_get_drvdata(struct watchdog_device *wdd) · line 156
Quoted 13 lines
include/linux/watchdog.h +4
-2}/* Use the following functions to manipulate watchdog driver specific data */ @@ -132,11 +150,20 @@ static inline void *watchdog_get_drvdata(struct watchdog_device *wdd) }/* drivers/watchdog/watchdog_core.c */ -extern int watchdog_init_timeout (struct watchdog_device *wdd, -unsigned int timeout_parm,struct device *dev); +extern int watchdog_init_timeouts (struct watchdog_device *wdd, +unsigned int pretimeout_parm, +unsigned int timeout_parm, +struct device *dev);
No 'extern' here, please. Yes, we'll need to fix that for the other function declarations, but that is not a reason to introduce new ones.
Thanks,
Guenter
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
In reply to Timur TabiHi Timur,
Thanks , feedback inline
Quoted 25 lines · Timur Tabi
Quoted 23 lines · On 06/01/2015 11:05 PM, [email protected] wrote:
drivers/watchdog/sbsa_gwdt.c new file +20
-0+/* +* help functions for accessing 32bit registers of SBSA Generic Watchdog +*/ +static void sbsa_gwdt_cf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (val, gwdt->control_base + reg); +} + +static void sbsa_gwdt_rf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (val, gwdt->refresh_base + reg); +} + +static u32 sbsa_gwdt_cf_read(unsigned int reg, struct watchdog_device*wdd)
(quoted diff) +2
-0+{ + struct sbsa_gwdt *gwdt = to_sbsa_gwdt(wdd);
Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c line 127
Quoted 3 lines
drivers/watchdog/sbsa_gwdt.c new file +3
-0+ +return readl_relaxed (gwdt->control_base + reg); +}I still think you should get rid of these functions and just call
readl_relaxed()andwritel_relaxed()every time, but I won't complain again if you keep them.
yes, that make sense, and will reduce the size of code, and I think the code's readability will be OK too.
will try in my next patch,
Quoted 15 lines
drivers/watchdog/sbsa_gwdt.c line 240
Quoted 12 lines
drivers/watchdog/sbsa_gwdt.c new file +11
-0+static irqreturn_t sbsa_gwdt_interrupt (int irq,void *dev_id) +{ +struct sbsa_gwdt *gwdt = (struct sbsa_gwdt *)dev_id; +struct watchdog_device *wdd = &gwdt->wdd; + +if (wdd->pretimeout) +/* The pretimeout is valid, go panic */ +panic ("SBSA Watchdog pre-timeout" ); +else +/* We don't use pretimeout, trigger WS1 now*/ +sbsa_gwdt_set_wcv (wdd,0 );I don't like this.
If so, what is your idea ,if pretimeout == 0?
the reason of using WCV as (timout - pretimeout): it can provide the longer timeout period,
(1)If we use WOR, it can only provide 10s @ 400MHz(max).
as Guenter said earlier, the default timer out for most watchdog will be 30s, so I think 10s limit will be a little short
(2)we can always program WCV just like ping.
(3)if a timeout arrives, WOR will be use, so use it as pretimeout, but we still can make this pretimeout longer by programming WCV(I don't think it's necessary)
Quoted 2 lines
The triggering of the hardware reset should never depend on an interrupt being handled properly.
if this fail, system reset in 1S, because WOR == (1s)
Quoted 3 lines
You should always program WCV
correctly in advance. This is especially true since pre-timeout will probably rarely be used.
always programming WCV is doable. But I absolutely can not agree " pre-timeout will probably rarely be used"
If so, SBSA watchdog is just a normal watchdog, This use case just makes this HW useless.
If so, go to use SP805.
you still don't see the importance of this warning and pretimeout to a real server.
If the software of a real server goes wrong, then you just directly restart it , never try to sync/protect the current data, never try to figure out what is wrong with it.
I don't think that is a good server software.
At least, I don't thinks " pre-timeout will probably rarely be used" is a good idea for a server.
in another word, in a server ,pre-timeout should always be used.
Quoted 1 line
So what happens if the CPU is totally hung and
Again, system reset in 1S, because WOR == (1s).
Quoted 1 line
this interrupt handler is never called? When will the timeout occur?
if this interrupt hardler is never called, what I can see is "some one is feeding the dog".
OK, in case, WS0 is triggered, but this interrupt hardler isn't called, then software really goes wrong. Then , Again, Again system reset in 1S, because WOR == (1s).
Quoted 11 lines
Quoted 11 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+static int sbsa_gwdt_probe (struct platform_device *pdev) +{ +u64 first_period_max =U64_MAX ; +struct device *dev = &pdev->dev; +struct watchdog_device *wdd; +struct sbsa_gwdt *gwdt; +struct resource *res; +void *rf_base, *cf_base; +int ret, irq; +u32 status;
Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c line 278
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +5
-0+ + gwdt =devm_kzalloc (dev,sizeof (*gwdt),GFP_KERNEL ); +if (!gwdt) +return -ENOMEM ; +platform_set_drvdata (pdev, gwdt);You should probably do this *after* calling
platform_get_irq_byname().
it just dose (pdev->) dev->driver_data = gwdt
If we got gwdt, we can do that.
But maybe I miss something(or a rule of usage), so please let know why this has to be called *after* calling platform_get_irq_byname().
Quoted 47 lines
Quoted 47 lines
(quoted diff) +2
-0+ + res = platform_get_resource_byname(pdev, IORESOURCE_MEM,"refresh");
drivers/watchdog/sbsa_gwdt.c new file +5
-0+ rf_base =devm_ioremap_resource (dev, res); +if (IS_ERR (rf_base)) +return PTR_ERR (rf_base); + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM,"control");
drivers/watchdog/sbsa_gwdt.c new file +12
-0+ cf_base =devm_ioremap_resource (dev, res); +if (IS_ERR (cf_base)) +return PTR_ERR (cf_base); + + irq =platform_get_irq_byname (pdev,"ws0" ); +if (irq <0 ) { +dev_err (dev,"unable to get ws0 interrupt.\n" ); +return irq; + } + +/* +* Get the frequency of system counter from the cp15 interface of ARM
+ * Generic timer. We don't need to check it, because if it returns
"0",drivers/watchdog/sbsa_gwdt.c new file +22
-0+* system would panic in very early stage. +*/ + gwdt->clk =arch_timer_get_cntfrq (); + gwdt->refresh_base = rf_base; + gwdt->control_base = cf_base; + + wdd = &gwdt->wdd; + wdd->parent = dev; + wdd->info = &sbsa_gwdt_info; + wdd->ops = &sbsa_gwdt_ops; +watchdog_set_drvdata (wdd, gwdt); +watchdog_set_nowayout (wdd, nowayout); + + wdd->min_pretimeout =0 ; + wdd->max_pretimeout =U32_MAX / gwdt->clk; + wdd->min_timeout =1 ; +do_div (first_period_max, gwdt->clk); + wdd->max_timeout = first_period_max; + + wdd->pretimeout =DEFAULT_PRETIMEOUT ; + wdd->timeout =DEFAULT_TIMEOUT ; +watchdog_init_timeouts (wdd, pretimeout, timeout, dev);
Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c line 325
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +5
-0+ + status =sbsa_gwdt_cf_read (SBSA_GWDT_WCS , wdd); +if (status &SBSA_GWDT_WCS_WS1 ) { +dev_warn (dev,"System reset by WDT(WCV: %llx)\n" , +sbsa_gwdt_get_wcv (wdd));"System was previously reset via watchdog" is much clearer.
OK
Quoted 9 lines
drivers/watchdog/sbsa_gwdt.c line 330
Quoted 6 lines
drivers/watchdog/sbsa_gwdt.c new file +5
-0+ wdd->bootstatus |=WDIOF_CARDRESET ; + } +/* Check if watchdog is already enabled */ +if (status &SBSA_GWDT_WCS_EN ) { +dev_warn (dev,"already enabled!\n" );"watchdog is already enabled".
I think I don't need to print "watchdog", dev_warn(dev, has help us on this.
If you do so , the message will be "watchdog: watchdog0: watchdog is already enabled"
Quoted 2 lines
Never use exclamation marks in kernel
messages.
that make sense , will delete it.
Quoted 27 lines
Quoted 19 lines
drivers/watchdog/sbsa_gwdt.c new file +18
-0+sbsa_gwdt_keepalive (wdd); + } + +/* update pretimeout to WOR */ +sbsa_gwdt_set_pretimeout (wdd, wdd->pretimeout); + + ret =devm_request_irq (dev, irq, sbsa_gwdt_interrupt,0 , + pdev->name, gwdt); +if (ret) { +dev_err (dev,"unable to request IRQ %d\n" , irq); +return ret; + } + + ret =watchdog_register_device (wdd); +if (ret) +return ret; + + dev_info(dev, "Initialized with %ds timeout, %ds pretimeout @ %uQuoted 2 lines
Hz\n",
+wdd->timeout,wdd->pretimeout,gwdt->clk);if (
wdd->pretimeout)
"watchdog initialized to %us timeout and %us pre-timeout at %u
Hz\n",wdd->timeout,wdd->pretimeout,gwdt->clk
else
Quoted 5 lines
"watchdog initialized to %us timeout at %u Hz\n", wdd->timeout,
gwdt->clkI think it's unlikely that users will use pre-timeout, so your code should treat pre-timeout as a special case, not the normal usage.
I don't think so, that why you didn't use pretimeout in your driver. Because you don't see the meaning of "pretimeout" to a server.
Quoted 5 lines
--
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Signature · 14 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Guenter Roeck
maintainerRe: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
Quoted 72 lines · Fu Wei
Hi Timur,
Thanks , feedback inline
Quoted 25 lines · Timur Tabi
Quoted 23 lines · On 06/01/2015 11:05 PM, [email protected] wrote:
drivers/watchdog/sbsa_gwdt.c new file +20
-0+/* +* help functions for accessing 32bit registers of SBSA Generic Watchdog +*/ +static void sbsa_gwdt_cf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (val, gwdt->control_base + reg); +} + +static void sbsa_gwdt_rf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (val, gwdt->refresh_base + reg); +} + +static u32 sbsa_gwdt_cf_read(unsigned int reg, struct watchdog_device*wdd)
(quoted diff) +2
-0+{ + struct sbsa_gwdt *gwdt = to_sbsa_gwdt(wdd);Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c line 127
Quoted 3 lines
drivers/watchdog/sbsa_gwdt.c new file +3
-0+ +return readl_relaxed (gwdt->control_base + reg); +}I still think you should get rid of these functions and just call
readl_relaxed()andwritel_relaxed()every time, but I won't complain again if you keep them.yes, that make sense, and will reduce the size of code, and I think the code's readability will be OK too.
will try in my next patch,Quoted 15 lines
drivers/watchdog/sbsa_gwdt.c line 240
Quoted 12 lines
drivers/watchdog/sbsa_gwdt.c new file +11
-0+static irqreturn_t sbsa_gwdt_interrupt (int irq,void *dev_id) +{ +struct sbsa_gwdt *gwdt = (struct sbsa_gwdt *)dev_id; +struct watchdog_device *wdd = &gwdt->wdd; + +if (wdd->pretimeout) +/* The pretimeout is valid, go panic */ +panic ("SBSA Watchdog pre-timeout" ); +else +/* We don't use pretimeout, trigger WS1 now*/ +sbsa_gwdt_set_wcv (wdd,0 );I don't like this.
If so, what is your idea ,if pretimeout == 0?
the reason of using WCV as (timout - pretimeout): it can provide the longer timeout period,
(1)If we use WOR, it can only provide 10s @ 400MHz(max).
as Guenter said earlier, the default timer out for most watchdog will be 30s, so I think 10s limit will be a little short
(2)we can always program WCV just like ping.
(3)if a timeout arrives, WOR will be use, so use it as pretimeout, but we still can make this pretimeout longer by programming WCV(I don't think it's necessary)
Quoted 5 lines
Quoted 2 lines
The triggering of the hardware reset should never depend on an interrupt being handled properly.
if this fail, system reset in 1S, because WOR == (1s)
So ?
Quoted 4 lines
Quoted 3 lines
You should always program WCV
correctly in advance. This is especially true since pre-timeout will probably rarely be used.
Quoted 8 lines
always programming WCV is doable. But I absolutely can not agree " pre-timeout will probably rarely be used"
If so, SBSA watchdog is just a normal watchdog, This use case just makes this HW useless.
If so, go to use SP805.
you still don't see the importance of this warning and pretimeout to a real server.
If pretimeout isn't used, why not just set WCV = timeout, WOR = 0 ?
Guenter
Quoted 154 lines
If the software of a real server goes wrong, then you just directly restart it , never try to sync/protect the current data, never try to figure out what is wrong with it.
I don't think that is a good server software.At least, I don't thinks " pre-timeout will probably rarely be used" is a good idea for a server.
in another word, in a server ,pre-timeout should always be used.Quoted 1 line
So what happens if the CPU is totally hung and
Again, system reset in 1S, because WOR == (1s).
Quoted 1 line
this interrupt handler is never called? When will the timeout occur?
if this interrupt hardler is never called, what I can see is "some one is feeding the dog".
OK, in case, WS0 is triggered, but this interrupt hardler isn't called, then software really goes wrong. Then , Again, Again system reset in 1S, because WOR == (1s).Quoted 11 lines
Quoted 11 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+static int sbsa_gwdt_probe (struct platform_device *pdev) +{ +u64 first_period_max =U64_MAX ; +struct device *dev = &pdev->dev; +struct watchdog_device *wdd; +struct sbsa_gwdt *gwdt; +struct resource *res; +void *rf_base, *cf_base; +int ret, irq; +u32 status;Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c line 278
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +5
-0+ + gwdt =devm_kzalloc (dev,sizeof (*gwdt),GFP_KERNEL ); +if (!gwdt) +return -ENOMEM ; +platform_set_drvdata (pdev, gwdt);You should probably do this *after* calling
platform_get_irq_byname().it just dose (pdev->)
dev->driver_data= gwdt
If we got gwdt, we can do that.But maybe I miss something(or a rule of usage), so please let know why this has to be called *after* calling
platform_get_irq_byname().Quoted 47 lines
Quoted 47 lines
(quoted diff) +2
-0+ + res = platform_get_resource_byname(pdev, IORESOURCE_MEM,"refresh");
drivers/watchdog/sbsa_gwdt.c new file +5
-0+ rf_base =devm_ioremap_resource (dev, res); +if (IS_ERR (rf_base)) +return PTR_ERR (rf_base); + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM,"control");
drivers/watchdog/sbsa_gwdt.c new file +12
-0+ cf_base =devm_ioremap_resource (dev, res); +if (IS_ERR (cf_base)) +return PTR_ERR (cf_base); + + irq =platform_get_irq_byname (pdev,"ws0" ); +if (irq <0 ) { +dev_err (dev,"unable to get ws0 interrupt.\n" ); +return irq; + } + +/* +* Get the frequency of system counter from the cp15 interface of ARM
+ * Generic timer. We don't need to check it, because if it returns
"0",drivers/watchdog/sbsa_gwdt.c new file +22
-0+* system would panic in very early stage. +*/ + gwdt->clk =arch_timer_get_cntfrq (); + gwdt->refresh_base = rf_base; + gwdt->control_base = cf_base; + + wdd = &gwdt->wdd; + wdd->parent = dev; + wdd->info = &sbsa_gwdt_info; + wdd->ops = &sbsa_gwdt_ops; +watchdog_set_drvdata (wdd, gwdt); +watchdog_set_nowayout (wdd, nowayout); + + wdd->min_pretimeout =0 ; + wdd->max_pretimeout =U32_MAX / gwdt->clk; + wdd->min_timeout =1 ; +do_div (first_period_max, gwdt->clk); + wdd->max_timeout = first_period_max; + + wdd->pretimeout =DEFAULT_PRETIMEOUT ; + wdd->timeout =DEFAULT_TIMEOUT ; +watchdog_init_timeouts (wdd, pretimeout, timeout, dev);Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c line 325
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +5
-0+ + status =sbsa_gwdt_cf_read (SBSA_GWDT_WCS , wdd); +if (status &SBSA_GWDT_WCS_WS1 ) { +dev_warn (dev,"System reset by WDT(WCV: %llx)\n" , +sbsa_gwdt_get_wcv (wdd));"System was previously reset via watchdog" is much clearer.
OK
Quoted 9 lines
drivers/watchdog/sbsa_gwdt.c line 330
Quoted 6 lines
drivers/watchdog/sbsa_gwdt.c new file +5
-0+ wdd->bootstatus |=WDIOF_CARDRESET ; + } +/* Check if watchdog is already enabled */ +if (status &SBSA_GWDT_WCS_EN ) { +dev_warn (dev,"already enabled!\n" );"watchdog is already enabled".
I think I don't need to print "watchdog", dev_warn(dev, has help us on this.
If you do so , the message will be "watchdog: watchdog0: watchdog is already enabled"Quoted 2 lines
Never use exclamation marks in kernel
messages.that make sense , will delete it.
Quoted 30 lines
Quoted 19 lines
drivers/watchdog/sbsa_gwdt.c new file +18
-0+sbsa_gwdt_keepalive (wdd); + } + +/* update pretimeout to WOR */ +sbsa_gwdt_set_pretimeout (wdd, wdd->pretimeout); + + ret =devm_request_irq (dev, irq, sbsa_gwdt_interrupt,0 , + pdev->name, gwdt); +if (ret) { +dev_err (dev,"unable to request IRQ %d\n" , irq); +return ret; + } + + ret =watchdog_register_device (wdd); +if (ret) +return ret; + + dev_info(dev, "Initialized with %ds timeout, %ds pretimeout @ %uQuoted 2 lines
Hz\n",
+wdd->timeout,wdd->pretimeout,gwdt->clk);if (
wdd->pretimeout)
"watchdog initialized to %us timeout and %us pre-timeout at %u
Hz\n",wdd->timeout,wdd->pretimeout,gwdt->clk
else"watchdog initialized to %us timeout at %u Hz\n", wdd->timeout,
gwdt->clk
Quoted 14 lines
Quoted 2 lines
I think it's unlikely that users will use pre-timeout, so your code should treat pre-timeout as a special case, not the normal usage.
I don't think so, that why you didn't use pretimeout in your driver. Because you don't see the meaning of "pretimeout" to a server.
Quoted 5 lines
--
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
In reply to Fu WeiQuoted 15 lines · Fu Wei
Quoted 6 lines
Quoted 6 lines
drivers/watchdog/sbsa_gwdt.c new file +6
-0+static irqreturn_t sbsa_gwdt_interrupt (int irq,void *dev_id) +{ +struct sbsa_gwdt *gwdt = (struct sbsa_gwdt *)dev_id; +struct watchdog_device *wdd = &gwdt->wdd; + +if (wdd->pretimeout)Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c line 240
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +5
-0+/* The pretimeout is valid, go panic */ +panic ("SBSA Watchdog pre-timeout" ); + else +/* We don't use pretimeout, trigger WS1 now*/ + sbsa_gwdt_set_wcv(wdd, 0);I don't like this.
Quoted 1 line
If so, what is your idea ,if pretimeout == 0?
If pretimeout == 0, then WCV should be set to timeout/2. The WS0 timeout will occur after timeout/2 seconds, and the driver will ignore it in the interrupt handler. Then after another timeout/2 seconds, WS1 will timeout and the system will reset.
Quoted 9 lines
the reason of using WCV as (timout - pretimeout): it can provide the longer timeout period,
(1)If we use WOR, it can only provide 10s @ 400MHz(max).
as Guenter said earlier, the default timer out for most watchdog will be 30s, so I think 10s limit will be a little short
(2)we can always program WCV just like ping.
(3)if a timeout arrives, WOR will be use, so use it as pretimeout, but we still can make this pretimeout longer by programming WCV(I don't think it's necessary)
I understand that, but like I said, I think pretimeout will be rarely used, and so the driver should work best with pre-timeout enabled.
Quoted 5 lines
Quoted 2 lines
The triggering of the hardware reset should never depend on an interrupt being handled properly.
if this fail, system reset in 1S, because WOR == (1s)
Quoted 7 lines
Quoted 3 lines
You should always program WCV
correctly in advance. This is especially true since pre-timeout will probably rarely be used.always programming WCV is doable. But I absolutely can not agree " pre-timeout will probably rarely be used"
If so, SBSA watchdog is just a normal watchdog,
So what? What's wrong with that? Users don't have any control over which watchdog hardware is on the SOC, and they don't care. They will use the same watchdog software as they do on x86.
Users *want* a normal watchdog. Pre-timeout is only supported on time watchdog hardware, so no one will standardize on it. ARM servers supposed to be interchangeable with x86 servers. Customers are not going to do anything special on an ARM server that they don't do on an x86 server. I've been working in the ARM server industry for over two years, and that's why everyone says.
Quoted 10 lines
This use case just
makes this HW useless.
If so, go to use SP805.
you still don't see the importance of this warning and pretimeout to a real server.If the software of a real server goes wrong, then you just directly restart it , never try to sync/protect the current data, never try to figure out what is wrong with it.
I don't think that is a good server software.
And that is exactly why my driver treats WS0 as the real timeout, and WS1 as a "backup" timeout. When WS0 expires, the system tries to do a "polite" reset. If that doesn't work, then WS1 will do a hard reset.
This also allows me to have a timeout that's twice as long as your driver, so my timeout occurs in WS0, not WS1.
Quoted 3 lines
At least, I don't thinks " pre-timeout will probably rarely be used" is a good idea for a server.
in another word, in a server ,pre-timeout should always be used.
Except that few servers today support pre-timeout, so customers won't depend on it.
Quoted 7 lines
Quoted 1 line
You should probably do this *after* calling
platform_get_irq_byname().it just dose (pdev->)
dev->driver_data= gwdt
If we got gwdt, we can do that.But maybe I miss something(or a rule of usage), so please let know why this has to be called *after* calling
platform_get_irq_byname().
It's just so that you can avoid calling kzalloc() if the platform_get_irq_byname() fails. It's not important.
Quoted 3 lines
I think I don't need to print "watchdog", dev_warn(dev, has help us on this.
If you do so , the message will be "watchdog: watchdog0: watchdog is already enabled"
Ok.
Signature · 7 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project. -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
In reply to [email protected]drivers/watchdog/sbsa_gwdt.c line 237
Quoted 3 lines · On 06/01/2015 11:05 PM, [email protected] wrote:
drivers/watchdog/sbsa_gwdt.c new file +3
-0+if (wdd->pretimeout) +/* The pretimeout is valid, go panic */ +panic ("SBSA Watchdog pre-timeout" );
The problem with this is that WS1 will still occur. So a few seconds after the panic() call, the hardware will reset. There won't be any time to debug or log anything.
drivers/watchdog/sbsa_gwdt.c line 240
Quoted 2 lines
drivers/watchdog/sbsa_gwdt.c new file +2
-0+/* We don't use pretimeout, trigger WS1 now*/ +sbsa_gwdt_set_wcv (wdd,0 );
Are you sure this will work? This will set WCV to 0, which means it the WS1 reset won't happen until the timestamp counter wraps around to 0. That could be a very long time from now.
Signature · 7 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project. -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Guenter Roeck
maintainerRe: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
Quoted 9 lines · Timur Tabi
drivers/watchdog/sbsa_gwdt.c line 237
Quoted 3 lines · On 06/01/2015 11:05 PM, [email protected] wrote:
drivers/watchdog/sbsa_gwdt.c new file +3
-0+if (wdd->pretimeout) +/* The pretimeout is valid, go panic */ +panic ("SBSA Watchdog pre-timeout" );The problem with this is that WS1 will still occur. So a few seconds after the
panic()call, the hardware will reset. There won't be any time to debug or log anything.
In general the idea here would be to use a crashdump kernel, which, when loaded, would reset the watchdog before it fires. This kernel would then write a core dump to a specified location.
If arm64 doesn't support a crashdump kernel, it might still be possible to log the backtrace somewhere (eg in nvram using pstore if that is supported via acpi or efi).
Is there reason to believe that this all won't work on arm64 ?
Thanks,
Guenter
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
Quoted 3 lines · Guenter Roeck
In general the idea here would be to use a crashdump kernel, which, when loaded, would reset the watchdog before it fires. This kernel would then write a core dump to a specified location.
What is the mechanism for resetting the watchdog? The only code that knows about the hardware registers is this driver. Does the crashdump kernel call the watchdog stop function?
Quoted 3 lines
If arm64 doesn't support a crashdump kernel, it might still be possible to log the backtrace somewhere (eg in nvram using pstore if that is supported via acpi or efi).
I think it's expected that the firmware support a crash dump mechanism of some kind. But if we're talking about firmware support, then why bother with the panic() in the first place?
Quoted 1 line
Is there reason to believe that this all won't work on arm64 ?
No, but I'm still trying to figure out why pre-timeout is valuable. If we don't disable WS1, then we risk having the hardware reset before we can take advantage of what the panic() offers. In which case, what's the point of pre-timeout?
Signature · 7 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project. -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
Quoted 8 lines · On Wednesday 03 June 2015 13:53:29 Timur Tabi wrote:
Quoted 3 lines · Guenter Roeck
In general the idea here would be to use a crashdump kernel, which, when loaded, would reset the watchdog before it fires. This kernel would then write a core dump to a specified location.
What is the mechanism for resetting the watchdog? The only code that knows about the hardware registers is this driver. Does the crashdump kernel call the watchdog stop function?
It might or might not, depending on what you want to achieve. In most cases, I'd expect the crashdump kernel to have it enabled if we want to let the user set a pretimeout, but that is a policy question that is not for the kernel to decide.
Quoted 7 lines
Quoted 3 lines
If arm64 doesn't support a crashdump kernel, it might still be possible to log the backtrace somewhere (eg in nvram using pstore if that is supported via acpi or efi).
I think it's expected that the firmware support a crash dump mechanism of some kind. But if we're talking about firmware support, then why bother with the
panic()in the first place?
panic() is what triggers all the crash dump or pstore mechanisms, it has to do that anyway.
Quoted 6 lines
Quoted 1 line
Is there reason to believe that this all won't work on arm64 ?
No, but I'm still trying to figure out why pre-timeout is valuable. If we don't disable WS1, then we risk having the hardware reset before we can take advantage of what the
panic()offers. In which case, what's the point of pre-timeout?
The timeouts are both configurable, so the sysadmin has to make sure that the time between them is long enough to do whatever is necessary.
Arnd
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
In reply to Guenter RoeckHi Gurnter
Quoted 81 lines · Guenter Roeck
Quoted 80 lines · Fu Wei
Hi Timur,
Thanks , feedback inline
Quoted 29 lines · Timur Tabi
Quoted 26 lines · On 06/01/2015 11:05 PM, [email protected] wrote:
+/*
+ * help functions for accessing 32bit registers of SBSA Generic Watchdog
+ */drivers/watchdog/sbsa_gwdt.c new file +17
-0+static void sbsa_gwdt_cf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (val, gwdt->control_base + reg); +} + +static void sbsa_gwdt_rf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (val, gwdt->refresh_base + reg); +} + +static u32 sbsa_gwdt_cf_read(unsigned int reg, struct watchdog_device*wdd)
drivers/watchdog/sbsa_gwdt.c new file +4
-0+{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +return readl_relaxed (gwdt->control_base + reg);Quoted 8 lines
Quoted 1 line
+}
I still think you should get rid of these functions and just call
readl_relaxed()andwritel_relaxed()every time, but I won't complain again
if you keep them.yes, that make sense, and will reduce the size of code, and I think the code's readability will be OK too.
will try in my next patch,Quoted 16 lines
drivers/watchdog/sbsa_gwdt.c line 240
Quoted 12 lines
drivers/watchdog/sbsa_gwdt.c new file +11
-0+static irqreturn_t sbsa_gwdt_interrupt (int irq,void *dev_id) +{ +struct sbsa_gwdt *gwdt = (struct sbsa_gwdt *)dev_id; +struct watchdog_device *wdd = &gwdt->wdd; + +if (wdd->pretimeout) +/* The pretimeout is valid, go panic */ +panic ("SBSA Watchdog pre-timeout" ); +else +/* We don't use pretimeout, trigger WS1 now*/ +sbsa_gwdt_set_wcv (wdd,0 );I don't like this.
If so, what is your idea ,if pretimeout == 0?
the reason of using WCV as (timout - pretimeout): it can provide the longer timeout period,
(1)If we use WOR, it can only provide 10s @ 400MHz(max).
as Guenter said earlier, the default timer out for most watchdog will be 30s, so I think 10s limit will be a little short
(2)we can always program WCV just like ping.
(3)if a timeout arrives, WOR will be use, so use it as pretimeout, but we still can make this pretimeout longer by programming WCV(I don't think it's necessary)
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
The triggering of the hardware reset should never depend on an interrupt being handled properly.
if this fail, system reset in 1S, because WOR == (1s)
So ?
Even the interrupt routine isn't triggered, (WOR + system counter) --> WCV, then, sy system reset in 1S.
the hardware reset doesn't depend on an interrupt.
Quoted 15 lines
Quoted 6 lines
Quoted 4 lines
You should always program WCV
correctly in advance. This is especially true since pre-timeout will probably rarely be used.Quoted 8 lines
always programming WCV is doable. But I absolutely can not agree " pre-timeout will probably rarely be used"
If so, SBSA watchdog is just a normal watchdog, This use case just makes this HW useless.
If so, go to use SP805.
you still don't see the importance of this warning and pretimeout to a real server.
Quoted 1 line
If pretimeout isn't used, why not just set WCV = timeout, WOR = 0 ?
Because if WOR = 0 , according to SBSA, once you want to enable watchdog, (0 + system counter) --> WCV , then , WS0 and WS1 will be triggered immediately. we have not a chance(a time slot) to update WCV.
Quoted 191 lines
Guenter
Quoted 186 lines
If the software of a real server goes wrong, then you just directly restart it ,
never try to sync/protect the current data, never try to figure out what is wrong with it.
I don't think that is a good server software.At least, I don't thinks " pre-timeout will probably rarely be used" is a good idea for a server.
in another word, in a server ,pre-timeout should always be used.Quoted 1 line
So what happens if the CPU is totally hung and
Again, system reset in 1S, because WOR == (1s).
Quoted 1 line
this interrupt handler is never called? When will the timeout occur?
if this interrupt hardler is never called, what I can see is "some one is feeding the dog".
OK, in case, WS0 is triggered, but this interrupt hardler isn't called, then software really goes wrong. Then , Again, Again system reset in 1S, because WOR == (1s).Quoted 12 lines
Quoted 12 lines
drivers/watchdog/sbsa_gwdt.c new file +11
-0+static int sbsa_gwdt_probe (struct platform_device *pdev) +{ +u64 first_period_max =U64_MAX ; +struct device *dev = &pdev->dev; +struct watchdog_device *wdd; +struct sbsa_gwdt *gwdt; +struct resource *res; +void *rf_base, *cf_base; +int ret, irq; +u32 status; +Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c line 278
Quoted 4 lines
drivers/watchdog/sbsa_gwdt.c new file +4
-0+ gwdt =devm_kzalloc (dev,sizeof (*gwdt),GFP_KERNEL ); +if (!gwdt) +return -ENOMEM ; +platform_set_drvdata (pdev, gwdt);You should probably do this *after* calling
platform_get_irq_byname().it just dose (pdev->)
dev->driver_data= gwdt
If we got gwdt, we can do that.But maybe I miss something(or a rule of usage), so please let know why this has to be called *after* calling
platform_get_irq_byname().Quoted 50 lines
Quoted 50 lines
(quoted diff) +2
-0+ + res = platform_get_resource_byname(pdev, IORESOURCE_MEM,"refresh");
drivers/watchdog/sbsa_gwdt.c new file +5
-0+ rf_base =devm_ioremap_resource (dev, res); +if (IS_ERR (rf_base)) +return PTR_ERR (rf_base); + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM,"control");
drivers/watchdog/sbsa_gwdt.c new file +12
-0+ cf_base =devm_ioremap_resource (dev, res); +if (IS_ERR (cf_base)) +return PTR_ERR (cf_base); + + irq =platform_get_irq_byname (pdev,"ws0" ); +if (irq <0 ) { +dev_err (dev,"unable to get ws0 interrupt.\n" ); +return irq; + } + +/* +* Get the frequency of system counter from the cp15 interface of
ARM
+ * Generic timer. We don't need to check it, because if it
returns
"0",drivers/watchdog/sbsa_gwdt.c new file +23
-0+* system would panic in very early stage. +*/ + gwdt->clk =arch_timer_get_cntfrq (); + gwdt->refresh_base = rf_base; + gwdt->control_base = cf_base; + + wdd = &gwdt->wdd; + wdd->parent = dev; + wdd->info = &sbsa_gwdt_info; + wdd->ops = &sbsa_gwdt_ops; +watchdog_set_drvdata (wdd, gwdt); +watchdog_set_nowayout (wdd, nowayout); + + wdd->min_pretimeout =0 ; + wdd->max_pretimeout =U32_MAX / gwdt->clk; + wdd->min_timeout =1 ; +do_div (first_period_max, gwdt->clk); + wdd->max_timeout = first_period_max; + + wdd->pretimeout =DEFAULT_PRETIMEOUT ; + wdd->timeout =DEFAULT_TIMEOUT ; +watchdog_init_timeouts (wdd, pretimeout, timeout, dev); +Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c line 325
Quoted 4 lines
drivers/watchdog/sbsa_gwdt.c new file +4
-0+ status =sbsa_gwdt_cf_read (SBSA_GWDT_WCS , wdd); +if (status &SBSA_GWDT_WCS_WS1 ) { +dev_warn (dev,"System reset by WDT(WCV: %llx)\n" , +sbsa_gwdt_get_wcv (wdd));"System was previously reset via watchdog" is much clearer.
OK
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c line 330
Quoted 6 lines
drivers/watchdog/sbsa_gwdt.c new file +5
-0+ wdd->bootstatus |=WDIOF_CARDRESET ; + } +/* Check if watchdog is already enabled */ +if (status &SBSA_GWDT_WCS_EN ) { +dev_warn (dev,"already enabled!\n" );"watchdog is already enabled".
I think I don't need to print "watchdog", dev_warn(dev, has help us on
this.
If you do so , the message will be "watchdog: watchdog0: watchdog is already enabled"Quoted 3 lines
Never use exclamation marks in kernel
messages.
that make sense , will delete it.
Quoted 28 lines
Quoted 19 lines
drivers/watchdog/sbsa_gwdt.c new file +18
-0+sbsa_gwdt_keepalive (wdd); + } + +/* update pretimeout to WOR */ +sbsa_gwdt_set_pretimeout (wdd, wdd->pretimeout); + + ret =devm_request_irq (dev, irq, sbsa_gwdt_interrupt,0 , + pdev->name, gwdt); +if (ret) { +dev_err (dev,"unable to request IRQ %d\n" , irq); +return ret; + } + + ret =watchdog_register_device (wdd); +if (ret) +return ret; + + dev_info(dev, "Initialized with %ds timeout, %ds pretimeout @ %uQuoted 2 lines
Hz\n",
+wdd->timeout,wdd->pretimeout,gwdt->clk);if (
wdd->pretimeout)
"watchdog initialized to %us timeout and %us pre-timeout at %u
Hz\n",wdd->timeout,wdd->pretimeout,gwdt->clk
elseQuoted 6 lines
"watchdog initialized to %us timeout at %u Hz\n", wdd->timeout,
gwdt->clkI think it's unlikely that users will use pre-timeout, so your code should
treat pre-timeout as a special case, not the normal usage.I don't think so, that why you didn't use pretimeout in your driver. Because you don't see the meaning of "pretimeout" to a server.
Quoted 5 lines
--
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Signature · 14 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
In reply to Guenter RoeckHi Guenter,
Quoted 11 lines · Guenter Roeck
Quoted 9 lines · Timur Tabi
drivers/watchdog/sbsa_gwdt.c line 237
Quoted 3 lines · On 06/01/2015 11:05 PM, [email protected] wrote:
drivers/watchdog/sbsa_gwdt.c new file +3
-0+if (wdd->pretimeout) +/* The pretimeout is valid, go panic */ +panic ("SBSA Watchdog pre-timeout" );The problem with this is that WS1 will still occur. So a few seconds after the
panic()call, the hardware will reset. There won't be any time to debug or log anything.
Quoted 7 lines
In general the idea here would be to use a crashdump kernel, which, when loaded, would reset the watchdog before it fires. This kernel would then write a core dump to a specified location.
If arm64 doesn't support a crashdump kernel, it might still be possible to log the backtrace somewhere (eg in nvram using pstore if that is supported via acpi or efi).
yes, you are right , thanks for explaining this.
Quoted 2 lines
Is there reason to believe that this all won't work on arm64 ?
I don't think there is a reason.
Quoted 3 lines
Thanks,
Guenter
Signature · 10 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021
Re: [PATCH v4 4/7] Watchdog: introdouce "pretimeout" into framework
In reply to Guenter RoeckHi Guenter,
Great thanks for your review,
Quoted 210 lines · Guenter Roeck
Quoted 168 lines · On 06/01/2015 09:05 PM, [email protected] wrote:
From: Fu Wei <[email protected]>
Also update
Documentation/watchdog/watchdog-kernel-api.txtto introduce:
(1)the new elements in thewatchdog_deviceandwatchdog_opsstruct; (2)the new API "watchdog_init_timeouts"Reasons:
(1)kernel already has two watchdog drivers are using "pretimeout":
drivers/char/ipmi/ipmi_watchdog.cdrivers/watchdog/kempld_wdt.c(but the definition is different)
(2)some other drivers are going to use this: ARM SBSA Generic WatchdogSigned-off-by Fu Wei <[email protected]>--- Documentation/watchdog/watchdog-kernel-api.txt | 47 ++++++++-- drivers/watchdog/watchdog_core.c | 115 +++++++++++++++++++------ drivers/watchdog/watchdog_dev.c | 53 ++++++++++++ include/linux/watchdog.h | 33 ++++++- 4 files changed, 212 insertions(+), 36 deletions(-)Documentation/watchdog/watchdog-kernel-api.txt +5
-0@@ -49,6 +49,9 @@ struct watchdog_device { unsigned int timeout; unsigned int min_timeout; unsigned int max_timeout; + unsigned int pretimeout; + unsigned int min_pretimeout; + unsigned int max_pretimeout; void *driver_data; struct mutex lock; unsigned long status;@@ -70,6 +73,9 @@ It contains following fields: * timeout: the watchdog timer's timeout value (in seconds). * min_timeout: the watchdog timer's minimum timeout value (in seconds). * max_timeout: the watchdog timer's maximum timeout value (in seconds). +* pretimeout: the watchdog timer's pretimeout value (in seconds). +* min_pretimeout: the watchdog timer's minimum pretimeout value (inseconds).
+*max_pretimeout: the watchdog timer's maximum pretimeout value (in seconds).
* bootstatus: status of the device after booting (reported with watchdog WDIOF_* status bits).
*driver_data: a pointer to the drivers private data of a watchdog
device.Documentation/watchdog/watchdog-kernel-api.txt +1
-0@@ -92,6 +98,7 @@ struct watchdog_ops { int (*ping)(struct watchdog_device *); unsigned int (*status)(struct watchdog_device *); int (*set_timeout)(struct watchdog_device *, unsigned int); + int (*set_pretimeout)(struct watchdog_device *, unsigned int); unsigned int (*get_timeleft)(struct watchdog_device *); void (*ref)(struct watchdog_device *); void (*unref)(struct watchdog_device *);@@ -153,9 +160,19 @@ they are supported. These optionalroutines/operations are:
and-EIOfor "could not write value to the watchdog". On success this routine should set the timeout value of thewatchdog_deviceto the achieved timeout value (which may be different from the requested oneDocumentation/watchdog/watchdog-kernel-api.txt +2
-1- because the watchdog does not necessarily has a 1 second resolution). + because the watchdog does not necessarily has a 1 second resolution; + If the driver supports pretimeout, then the timeout value must begreater
+ than that).
(Note: theWDIOF_SETTIMEOUTneeds to be set in the options field of
the
watchdog's info structure).Documentation/watchdog/watchdog-kernel-api.txt +2
-0+* set_pretimeout: this routine checks and changes the pretimeout of the + watchdog timer device. It returns 0 on success, -EINVAL for "parameterout of
+ range" and-EIOfor "could not write value to the watchdog". On success thisDocumentation/watchdog/watchdog-kernel-api.txt +2
-0+ routine should set the pretimeout value of the watchdog_device to the + achieved pretimeout value (which may be different from the requestedone
Documentation/watchdog/watchdog-kernel-api.txt +3
-0+ because the watchdog does not necessarily has a 1 second resolution). + (Note: the WDIOF_PRETIMEOUT needs to be set in the options field of the + watchdog's info structure). * get_timeleft: this routines returns the time that's left before areset.
* ref: the operation that callskref_geton the kref of a dynamically allocatedwatchdog_devicestruct.Documentation/watchdog/watchdog-kernel-api.txt +0
-0@@ -219,8 +236,28 @@ extern int watchdog_init_timeout(struct watchdog_device *wdd, unsigned int timeout_parm, struct device *dev); The watchdog_init_timeout function allows you to initialize the timeoutfield
-using the module timeout parameter or by retrieving the timeout-sec property from
-the device tree (if the module timeout parameter is invalid). Best practice is
-to set the default timeout value as timeout value in thewatchdog_deviceandDocumentation/watchdog/watchdog-kernel-api.txt +2
-1-then use this function to set the user "preferred" timeout value. +using the module timeout parameter or by retrieving the first element of +the timeout-sec property from the device tree (if the module timeoutparameter
+is invalid). Best practice is to set the default timeout value as timeout value
+in thewatchdog_deviceand then use this function to set the user "preferred"Documentation/watchdog/watchdog-kernel-api.txt +2
-0+timeout value. +This routine returns zero on success and a negative errno code forfailure.
Documentation/watchdog/watchdog-kernel-api.txt +3
-0+ +Some watchdog timers have two stage of timeouts(timeout and pretimeout), +to initialize the timeout and pretimeout fields at the same time, thefollowing
Documentation/watchdog/watchdog-kernel-api.txt +8
-0+function can be used: + +extern int watchdog_init_timeouts(struct watchdog_device *wdd, + unsigned int pretimeout_parm, + unsigned int timeout_parm, + struct device *dev); + +The watchdog_init_timeouts function allows you to initialize thepretimeout and
Documentation/watchdog/watchdog-kernel-api.txt +2
-0+timeout fields using the module pretimeout and timeout parameter or by +retrieving the elements in the timeout-sec property(the first element isfor
+timeout, the second one is for pretimeout) from the device tree(if the moduleDocumentation/watchdog/watchdog-kernel-api.txt +2
-0+pretimeout and timeout parameter are invalid). +Best practice is to set the default pretimeout and timeout value aspretimeout
+and timeout value in thewatchdog_deviceand then use this function to set the
+user "preferred" pretimeout value.
This routine returns zero on success and a negative errno code for
failure.drivers/watchdog/watchdog_core.c +8
-3@@ -43,60 +43,119 @@static DEFINE_IDA (watchdog_ida);static struct class *watchdog_class; -static void watchdog_check_min_max_timeout (struct watchdog_device *wdd) +static void watchdog_check_min_max_timeouts (struct watchdog_device *wdd) {/* -* Check that we have valid min and max timeout values, if -* not reset them both to 0 (=not used or unknown) +* Check that we have valid min and max pretimeout and timeout values, +* if not reset them both to 0 (=not used or unknown) */ +if (wdd->min_pretimeout > wdd->max_pretimeout) { +pr_info ("Invalid min and max pretimeout, resetting to 0\n"); + wdd->min_pretimeout =0 ; + wdd->max_pretimeout =0 ; + }if (wdd->min_timeout > wdd->max_timeout) {pr_info ("Invalid min and max timeout values, resetting to 0!\n"); wdd->min_timeout =0 ; wdd->max_timeout =0 ; }drivers/watchdog/watchdog_core.c line 74
Quoted 10 lines
drivers/watchdog/watchdog_core.c +8
-0+/* +* Check that we have valid min timeout and max pretimeout values, +* if not reset them. +*/ +if (wdd->min_pretimeout && wdd->min_timeout < wdd->min_pretimeout) { + pr_info("Invalid min_timeout, resetting to min_pretimeout+1\n"); + wdd->min_timeout = wdd->min_pretimeout + 1; + }
min_timeout= 10max_timeout= 20min_pretimeout= 30max_pretimeout= 40will result in
min_timeoutset to 31.drivers/watchdog/watchdog_core.c line 79
Quoted 5 lines
drivers/watchdog/watchdog_core.c +3
-0+if (wdd->max_pretimeout && wdd->max_timeout < wdd->max_pretimeout) { + pr_info("Invalid max_pretimeout, resetting to max_timeout-1\n"); + wdd->max_pretimeout = wdd->max_timeout - 1;and then you set
max_pretimeoutto 19.So we'll end up with
min_timeout= 31max_timeout= 20min_pretimeout= 30max_pretimeout= 19Another example:
max_pretimeout= 10,max_timeout= 0 ->max_pretimeout= -1.drivers/watchdog/watchdog_core.c line 80
Quoted 1 line
drivers/watchdog/watchdog_core.c +1
-0+ }
Quoted 8 lines
You'll need to determine valid ranges and then enforce those. Maybe something like
min_pretimeout<min_timeout<max_timeout
and
min_pretimeout<max_pretimeout<max_timeoutNot sure if we should adjust anything to a value different to 0. Seems to me this is just asking for trouble.
yes, this is a new problem, but let me fix this in my new patchset:
(1)these values is set by driver in the initialization procedure, according to hardware info.
(2) I thinks there is not any driver should call this function after initialization.
So if we find any incorrect value, I think the hardware info we got
is wrong , maybe we can just give up
any suggestion ?
Quoted 26 lines
Quoted 16 lines
drivers/watchdog/watchdog_core.c +2
-2}/** -* watchdog_init_timeout() - initialize the timeout field +* watchdog_init_timeouts() - initialize the pretimeout and timeout field +* @pretimeout_parm: pretimeout module parameter * @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
- * timeout module parameter (if it is valid value) or the timeout-sec property
- * (only if it is a valid value and thetimeout_parmis out of bounds).
- * If none of them are valid then we keep the old value (which shouldQuoted 8 lines
normally
- * be the default timeout value.
+ * Initialize the pretimeout and timeout field of thewatchdog_devicestruct
+ * with either the pretimeout and timeout module parameter (if it is valid
+ * value) or the timeout-sec property (only if it is a valid value and the
Quoted 1 line
just 'if it is valid', or 'if it is a valid value' in both cases.
OK. np,. Thanks
Quoted 6 lines
Quoted 3 lines
+ *
pretimeout_parmandtimeout_parmis out of bounds). If none of them ares/and/or/
Thanks , fixed
Quoted 33 lines
Quoted 33 lines
+ * valid, then we keep the old value (which should normally be the default
+ * timeout value).
*
* A zero is returned on success and-EINVALfor failure. */drivers/watchdog/watchdog_core.c +0
-2-int watchdog_init_timeout (struct watchdog_device *wdd, - unsigned int timeout_parm, struct device*dev)
drivers/watchdog/watchdog_core.c +7
-5+int watchdog_init_timeouts (struct watchdog_device *wdd, +unsigned int pretimeout_parm, +unsigned int timeout_parm, +struct device *dev) { -unsigned int t =0 ; -int ret =0 ; +int ret =0 , length =0 ; +u32 timeouts[2 ] = {0 }; -watchdog_check_min_max_timeout (wdd); +watchdog_check_min_max_timeouts (wdd); -/* try to get the timeout module parameter first */ -if (!watchdog_timeout_invalid (wdd, timeout_parm) && timeout_parm){
drivers/watchdog/watchdog_core.c +4
-2- wdd->timeout = timeout_parm; -return ret; +/* +* Try to get the pretimeout module parameter first, +* but it can be "0", that means we don't use pretimeout. +*/
Quoted 8 lines
Quoted 5 lines
drivers/watchdog/watchdog_core.c +4
-0+if (pretimeout_parm) { +if (!watchdog_pretimeout_invalid (wdd, pretimeout_parm)) + timeouts[1 ] = pretimeout_parm; + ret = -EINVAL ;/* pretimeout_parm is not "0", and invalid */
pretimeout_parmis always invalid ? Why ?
Sorry, I lost a "else" , this is a bug/typo
Quoted 10 lines
drivers/watchdog/watchdog_core.c line 113
Quoted 7 lines
}drivers/watchdog/watchdog_core.c +4
-1-if (timeout_parm) + +/* +* Try to get the timeout module parameter, +* if it's valid and pretimeout is ont invalid(ret == 0), s/ont/not/
Thanks , fixed
Quoted 11 lines
Quoted 6 lines
drivers/watchdog/watchdog_core.c +4
-0+* assignment and return zero. Otherwise, try dtb. +*/ +if (timeout_parm) { +if (!watchdog_timeout_invalid (wdd, timeout_parm) && !ret){
Unless I am missing something, you'll never get here if the pretimeout module
parameter is set.
yes, because of the bug above.
Will fix it in my next patchset , thanks :-)
Quoted 17 lines
Quoted 5 lines
drivers/watchdog/watchdog_core.c +4
-0+ wdd->timeout = timeout_parm; + wdd->pretimeout = timeouts[1 ]; +return 0 ; + }drivers/watchdog/watchdog_core.c line 130
Quoted 10 lines
drivers/watchdog/watchdog_core.c +7
-1ret = -EINVAL ; + } -/* try to get the timeout_sec property */ +/* +* We get here, the situation is one of them: +* (1)at least one of parameters is invalid(ret = -EINVAL); +* (2)both of them are 0.(ret = 0) +* So give up the module parameter(at least drop the invalid one), +* try to get the timeout_sec property from dtb.
Quoted 4 lines
Please simplify the comment.
Either at least one of the module parameters is invalid, or both of them are 0. Try to get the
timeout_secproperty.
Thanks , will do.
Quoted 10 lines
Quoted 10 lines
drivers/watchdog/watchdog_core.c +1
-5+*/ if (dev ==NULL || dev->of_node ==NULL )return ret; -of_property_read_u32 (dev->of_node,"timeout-sec" , &t); -if (!watchdog_timeout_invalid (wdd, t) && t) - wdd->timeout = t; -else - ret = -EINVAL ;
Quoted 8 lines
drivers/watchdog/watchdog_core.c line 138
Quoted 5 lines
drivers/watchdog/watchdog_core.c +4
-1-return ret; +/* +* We get here, that means maybe we can get timeouts from dtb, +* if "timeout-sec" is available and the data is valid. +*/ That comment is not needed; it is obvious.
OK, will remove it
Quoted 7 lines
drivers/watchdog/watchdog_core.c line 140
Quoted 3 lines
drivers/watchdog/watchdog_core.c +2
-0+of_find_property (dev->of_node,"timeout-sec" , &length); +if (length >0 && length <=sizeof (u32) *2 ) {You need to check the return value of
of_find_property()instead of assuming that length will be 0 if it is not found.
you are right, will do, thanks
Quoted 11 lines
Quoted 8 lines
drivers/watchdog/watchdog_core.c +6
-0+of_property_read_u32_array (dev->of_node, +"timeout-sec" , timeouts, + length /sizeof (u32)); +if (length ==sizeof (u32) *2 && timeouts[1 ] && +watchdog_pretimeout_invalid (wdd, timeouts[1 ])) +return -EINVAL ;/* pretimeout is invalid */
Obvious comment.
OK, will remove it
Quoted 173 lines
Quoted 163 lines
drivers/watchdog/watchdog_core.c +12
-2+ +if (!watchdog_timeout_invalid (wdd, timeouts[0 ]) && + timeouts[0 ]) { + wdd->timeout = timeouts[0 ]; + wdd->pretimeout = timeouts[1 ]; +return 0 ; + } + } + +return -EINVAL ; } -EXPORT_SYMBOL_GPL (watchdog_init_timeout); +EXPORT_SYMBOL_GPL (watchdog_init_timeouts);/** * watchdog_register_device() - register a watchdog device @@ -119,7 +178,7 @@ int watchdog_register_device(struct watchdog_device *wdd)if (wdd->ops->start ==NULL || wdd->ops->stop ==NULL )return -EINVAL ; -watchdog_check_min_max_timeout (wdd); +watchdog_check_min_max_timeouts (wdd);/* * Note: now that all
watchdog_devicedata has been verified, wedrivers/watchdog/watchdog_dev.c +32
-0@@ -218,6 +218,38 @@ out_timeout: }/* +* watchdog_set_pretimeout: set the watchdog timer pretimeout +* @wddev: the watchdog device to set the timeout for +* @pretimeout: pretimeout to set in seconds +*/ + +static int watchdog_set_pretimeout (struct watchdog_device *wddev, +unsigned int pretimeout) +{ +int err; + +if (!wddev->ops->set_pretimeout || + !(wddev->info->options &WDIOF_PRETIMEOUT )) +return -EOPNOTSUPP ; + +if (watchdog_pretimeout_invalid (wddev, pretimeout)) +return -EINVAL ; + +mutex_lock (&wddev->lock); + +if (test_bit (WDOG_UNREGISTERED , &wddev->status)) { + err = -ENODEV ; + goto out_pretimeout; + } + + err = wddev->ops->set_pretimeout (wddev, pretimeout); + +out_pretimeout: +mutex_unlock (&wddev->lock); +return err; +} + +/* * watchdog_get_timeleft: wrapper to get the time left before a reboot
* @wddev: the watchdog device to get the remaining time from
* @timeleft: the time that's leftdrivers/watchdog/watchdog_dev.c +21
-0@@ -388,6 +420,27 @@ static long watchdog_ioctl(struct file *file, unsigned int cmd, if (wdd->timeout == 0) return -EOPNOTSUPP;return put_user (wdd->timeout, p); +case WDIOC_SETPRETIMEOUT : +/* check if we support the pretimeout */ +if (!(wdd->info->options &WDIOF_PRETIMEOUT )) +return -EOPNOTSUPP ; +if (get_user (val, p)) +return -EFAULT ; + err =watchdog_set_pretimeout (wdd, val); +if (err <0 ) +return err; +/* +* If the watchdog is active then we send a keepalive ping +* to make sure that the watchdog keeps running (and if +* possible that it takes the new pretimeout) +*/ +watchdog_ping (wdd); +/* Fall */ +case WDIOC_GETPRETIMEOUT : +/* check if we support the pretimeout */ +if (wdd->info->options &WDIOF_PRETIMEOUT ) +return put_user (wdd->pretimeout, p); +return -EOPNOTSUPP ;case WDIOC_GETTIMELEFT : err =watchdog_get_timeleft (wdd, &val);if (err)
include/linux/watchdog.h +0
-0@@ -25,6 +25,7 @@ struct watchdog_device;* @ping: The routine that sends a keepalive ping to the watchdog device.
* @status: The routine that shows the status of the watchdog device.
* @set_timeout:The routine for setting the watchdog devices timeout
value.
+ * @set_pretimeout:The routine for setting the watchdog devices pretimeout value
* @get_timeleft:The routine that get's the time that's left before a
reset.
* @ref: The ref operation for dyn. allocatedwatchdog_device
structs
* @unref: The unref operation for dyn. allocatedwatchdog_device
structsinclude/linux/watchdog.h +7
-0@@ -44,6 +45,7 @@ struct watchdog_ops {int (*ping)(struct watchdog_device *);unsigned int (*status)(struct watchdog_device *);int (*set_timeout)(struct watchdog_device *,unsigned int ); +int (*set_pretimeout)(struct watchdog_device *,unsigned int );unsigned int (*get_timeleft)(struct watchdog_device *);void (*ref)(struct watchdog_device *);void (*unref)(struct watchdog_device *);@@ -62,6 +64,9 @@ struct watchdog_ops {* @timeout: The watchdog devices timeout value. * @min_timeout:The watchdog devices minimum timeout value. * @max_timeout:The watchdog devices maximum timeout value. +* @pretimeout: The watchdog devices pretimeout value. +* @min_pretimeout:The watchdog devices minimum pretimeout value. +* @max_pretimeout:The watchdog devices maximum pretimeout value. * @driver-data:Pointer to the drivers private data. * @lock: Lock for watchdog core internal use only. * @status: Field that contains the devices internal status bits. @@ -86,6 +91,9 @@ struct watchdog_device {unsigned int timeout;unsigned int min_timeout;unsigned int max_timeout; +unsigned int pretimeout; +unsigned int min_pretimeout; +unsigned int max_pretimeout;void *driver_data;struct mutex lock;unsigned long status;@@ -117,7 +125,17 @@ static inline void watchdog_set_nowayout(struct
watchdog_device*wdd, bool noway
static inline bool watchdog_timeout_invalid(structwatchdog_device*wdd,
unsigned int t){ return ((wdd->max_timeout != 0) &&include/linux/watchdog.h +5
-1- (t < wdd->min_timeout || t > wdd->max_timeout)); + (t < wdd->min_timeout || t > wdd->max_timeout || + t <= wdd->pretimeout)); +} + +/* Use the following function to check if a pretimeout value is invalid */
+static inline bool watchdog_pretimeout_invalid(structwatchdog_device*wdd,include/linux/watchdog.h static inline void watchdog_set_nowayout(struct watchdog_device *wdd, bool noway · line 138
Quoted 5 lines
include/linux/watchdog.h +5
-0+ unsigned int t) +{ +return (wdd->max_pretimeout !=0 && + (t < wdd->min_pretimeout || t > wdd->max_pretimeout || + (wdd->timeout !=0 && t >= wdd->timeout)));This validates a pretimeout as valid if
max_pretimeout== 0, no matter what timeout is set to.
Quoted 1 line
Do we really need to check if timeout == 0 ? Can that ever happen ?
(wdd->timeout != 0 && t >= wdd->timeout)
if we have set timeout(wdd->timeout != 0), and t(pretimeout) > wdd->timeout, t is a invalid value.
Am I correct?
the reason of adding "wdd->timeout != 0": if driver calls this function before setting up wdd->timeout.
Quoted 9 lines
Quoted 9 lines
}/* Use the following functions to manipulate watchdog driver specific
data */include/linux/watchdog.h +0
-0@@ -132,11 +150,20 @@ static inline void *watchdog_get_drvdata(struct watchdog_device *wdd) }
Quoted 12 lines
include/linux/watchdog.h static inline void *watchdog_get_drvdata(struct watchdog_device *wdd) · line 156
Quoted 8 lines
include/linux/watchdog.h +4
-2/* drivers/watchdog/watchdog_core.c */ -extern int watchdog_init_timeout (struct watchdog_device *wdd, -unsigned int timeout_parm,struct device *dev); +extern int watchdog_init_timeouts (struct watchdog_device *wdd, +unsigned int pretimeout_parm, +unsigned int timeout_parm, +struct device *dev);No 'extern' here, please. Yes, we'll need to fix that for the other function declarations, but that is not a reason to introduce new ones.
OK, I do agree with you on this, have fixed it in my next patchset.
Quoted 4 lines
Thanks,
Guenter
Signature · 10 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021
Guenter Roeck
maintainerRe: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
In reply to Fu WeiQuoted 113 lines · Fu Wei
Hi Gurnter
Quoted 81 lines · Guenter Roeck
Quoted 80 lines · Fu Wei
Hi Timur,
Thanks , feedback inline
Quoted 29 lines · Timur Tabi
Quoted 26 lines · On 06/01/2015 11:05 PM, [email protected] wrote:
+/*
+ * help functions for accessing 32bit registers of SBSA Generic Watchdog
+ */drivers/watchdog/sbsa_gwdt.c new file +17
-0+static void sbsa_gwdt_cf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (val, gwdt->control_base + reg); +} + +static void sbsa_gwdt_rf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (val, gwdt->refresh_base + reg); +} + +static u32 sbsa_gwdt_cf_read(unsigned int reg, struct watchdog_device*wdd)
drivers/watchdog/sbsa_gwdt.c new file +4
-0+{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +return readl_relaxed (gwdt->control_base + reg);Quoted 8 lines
Quoted 1 line
+}
I still think you should get rid of these functions and just call
readl_relaxed()andwritel_relaxed()every time, but I won't complain again
if you keep them.yes, that make sense, and will reduce the size of code, and I think the code's readability will be OK too.
will try in my next patch,Quoted 16 lines
drivers/watchdog/sbsa_gwdt.c line 240
Quoted 12 lines
drivers/watchdog/sbsa_gwdt.c new file +11
-0+static irqreturn_t sbsa_gwdt_interrupt (int irq,void *dev_id) +{ +struct sbsa_gwdt *gwdt = (struct sbsa_gwdt *)dev_id; +struct watchdog_device *wdd = &gwdt->wdd; + +if (wdd->pretimeout) +/* The pretimeout is valid, go panic */ +panic ("SBSA Watchdog pre-timeout" ); +else +/* We don't use pretimeout, trigger WS1 now*/ +sbsa_gwdt_set_wcv (wdd,0 );I don't like this.
If so, what is your idea ,if pretimeout == 0?
the reason of using WCV as (timout - pretimeout): it can provide the longer timeout period,
(1)If we use WOR, it can only provide 10s @ 400MHz(max).
as Guenter said earlier, the default timer out for most watchdog will be 30s, so I think 10s limit will be a little short
(2)we can always program WCV just like ping.
(3)if a timeout arrives, WOR will be use, so use it as pretimeout, but we still can make this pretimeout longer by programming WCV(I don't think it's necessary)Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
The triggering of the hardware reset should never depend on an interrupt being handled properly.
if this fail, system reset in 1S, because WOR == (1s)
So ?
Even the interrupt routine isn't triggered, (WOR + system counter) --> WCV, then, sy system reset in 1S.
the hardware reset doesn't depend on an interrupt.
Quoted 15 lines
Quoted 14 lines
Quoted 4 lines
You should always program WCV
correctly in advance. This is especially true since pre-timeout will probably rarely be used.always programming WCV is doable. But I absolutely can not agree " pre-timeout will probably rarely be used"
If so, SBSA watchdog is just a normal watchdog, This use case just makes this HW useless.
If so, go to use SP805.
you still don't see the importance of this warning and pretimeout to a real server.
Quoted 6 lines
Quoted 1 line
If pretimeout isn't used, why not just set WCV = timeout, WOR = 0 ?
Because if WOR = 0 , according to SBSA, once you want to enable watchdog, (0 + system counter) --> WCV , then , WS0 and WS1 will be triggered immediately. we have not a chance(a time slot) to update WCV.
I would have thought that this is exactly what we want if pretimeout is not used. What am I missing here ?
Guenter
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
Hi Guenter,
Quoted 129 lines · Guenter Roeck
Quoted 128 lines · Fu Wei
Hi Gurnter
Quoted 88 lines · Guenter Roeck
Quoted 86 lines · Fu Wei
Hi Timur,
Thanks , feedback inline
Quoted 35 lines · Timur Tabi
Quoted 22 lines · On 06/01/2015 11:05 PM, [email protected] wrote:
+/*
+ * help functions for accessing 32bit registers of SBSA Generic Watchdog
+ */drivers/watchdog/sbsa_gwdt.c new file +17
-0+static void sbsa_gwdt_cf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (val, gwdt->control_base + reg); +} + +static void sbsa_gwdt_rf_write (unsigned int reg,u32 val, +struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (val, gwdt->refresh_base + reg); +} + +static u32 sbsa_gwdt_cf_read(unsigned int reg, struct watchdog_device*wdd)
drivers/watchdog/sbsa_gwdt.c line 127
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +5
-0+{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +return readl_relaxed (gwdt->control_base + reg); +}Quoted 4 lines
I still think you should get rid of these functions and just call
readl_relaxed()andwritel_relaxed()every time, but I won't complain again
if you keep them.yes, that make sense, and will reduce the size of code, and I think the code's readability will be OK too.
will try in my next patch,Quoted 17 lines
drivers/watchdog/sbsa_gwdt.c line 240
Quoted 12 lines
drivers/watchdog/sbsa_gwdt.c new file +11
-0+static irqreturn_t sbsa_gwdt_interrupt (int irq,void *dev_id) +{ +struct sbsa_gwdt *gwdt = (struct sbsa_gwdt *)dev_id; +struct watchdog_device *wdd = &gwdt->wdd; + +if (wdd->pretimeout) +/* The pretimeout is valid, go panic */ +panic ("SBSA Watchdog pre-timeout" ); +else +/* We don't use pretimeout, trigger WS1 now*/ +sbsa_gwdt_set_wcv (wdd,0 );I don't like this.
If so, what is your idea ,if pretimeout == 0?
the reason of using WCV as (timout - pretimeout): it can provide the longer timeout period,
(1)If we use WOR, it can only provide 10s @ 400MHz(max).
as Guenter said earlier, the default timer out for most watchdog will be 30s, so I think 10s limit will be a little short
(2)we can always program WCV just like ping.
(3)if a timeout arrives, WOR will be use, so use it as pretimeout, but we still can make this pretimeout longer by programming WCV(I don't think it's necessary)Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
The triggering of the hardware reset should never depend on an interrupt being handled properly.
if this fail, system reset in 1S, because WOR == (1s)
So ?
Even the interrupt routine isn't triggered, (WOR + system counter) --> WCV,
then, sy system reset in 1S.the hardware reset doesn't depend on an interrupt.
Quoted 17 lines
Quoted 7 lines
Quoted 4 lines
You should always program WCV
correctly in advance. This is especially true since pre-timeout will probably rarely be used.Quoted 8 lines
always programming WCV is doable. But I absolutely can not agree " pre-timeout will probably rarely be used"
If so, SBSA watchdog is just a normal watchdog, This use case just makes this HW useless.
If so, go to use SP805.
you still don't see the importance of this warning and pretimeout to a real server.If pretimeout isn't used, why not just set WCV = timeout, WOR = 0 ?
Quoted 8 lines
Quoted 5 lines
Because if WOR = 0 , according to SBSA, once you want to enable watchdog, (0 + system counter) --> WCV , then , WS0 and WS1 will be triggered immediately.
we have not a chance(a time slot) to update WCV.I would have thought that this is exactly what we want if pretimeout is not used.
Although pretimeout == 0 is not good for a server, but If administrator set up pretimeout == 0. *I thinks we should trigger WS1 ASAP* . Because WS1 maybe a interrupter or a reboot signal, that is why we can not reboot system directly.
This driver is SBSA watchdog driver, that means we need to follow SBSA spec:
(1) SBSA watchdog has two stage timeouts --> timeout and pretimeout is the best solution in watchdog framework, at least for now.
(2) The watchdog has the following output signals:
Watchdog Signal 0 (WS0)---> "The initial signal is typically wired
to an interrupt and alerts the system."(original word from spec), I thinks the key work should be "interrupt" and "alerts". So in WS0 interrupt routine, reset is absolutely a wrong operation. Although I think we should make this "alerts" more useful. But for the first version of driver, I thinks panic is useful enough.
Watchdog Signal 1 (WS1). ---> "The signal is fed to a higher agent
as an interrupt or reset for it to take executive action." (original word from spec) . The key work should be "interrupt", "or" and "reset" . So WS1 maybe a interrupt.
so even in the WS0 interrupt routine, if pretimeout == 0 , we need to trigger WS1(that is what my patch is doing now, set WCV to 0, so WCV is always less than SystemCounter, and in this situation(WS0 = TRUE), WS1 will be trigger immediately), but definitely not a reset too.
But in worst case, if the WS0 is triggered, but the interrupt routine doesn't work(can not set up WCV), it doesn't matter, we just need to wait for a WOR(1s in my driver) timeout, then WS1 will be triggered. That is hardware mechanism, once we config SBSA watchdog correctly, that should work. If it doesn't, I think the chip design doesn't follow the SBSA spec.
Make a summary here, for SBSA watchdog driver, it need to support two stage timeouts and need to trigger WS0/1 when timeouts occur(can not simply reset system in interrupt routines).
If a driver doesn't do these above, the driver can not be called SBSA watchdog driver.
But according to SBSA, even pretimeout == 0, we can not setup WOR = 0. if we make WOR = 0 , once we set up WCS(enabling watchdog), that cause a explicit watchdog refresh, then WCV = (0 + system counter), so WS0 and WS1 will be triggered serially and immediately(in theory, the "delay" also depend on implementation). So in my patchset , if pretimeout == 0, WOR will be 1s at least to make sure we have time to setup WCV. I have made comments in the patch for explaining this.
Maybe some people want to ask: if we can not set up WOR = 0, but pretimeout can be 0 and timeout can not, why I still want to use WOR for pretimeout and using WCV as (timout - pretimeout) ?? For this:
(1)WCV can provide the longer timeout period, If we use WOR, it can only provide 10s @ 400MHz(max). The default timer out for most watchdog will be 30s, so I think 10s limit will be a little short. (2)we can always program(write) WCV just like ping.
(3)if the first timeout occurs, WOR will be loaded to WCV(WOR + system counter) automatically , so why not just use WOR as pretimeout? Although we still can make this pretimeout longer by programming WCV, I don't think it's necessary for now.
Quoted 4 lines
What am I missing here ?
Guenter
Signature · 10 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021
Guenter Roeck
maintainerRe: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
Quoted 179 lines · Fu Wei
Hi Guenter,
Quoted 129 lines · Guenter Roeck
Quoted 128 lines · Fu Wei
Hi Gurnter
Quoted 88 lines · Guenter Roeck
Quoted 86 lines · Fu Wei
Hi Timur,
Thanks , feedback inline
Quoted 35 lines · Timur Tabi
Quoted 22 lines · On 06/01/2015 11:05 PM, [email protected] wrote:
+/*
+ * help functions for accessing 32bit registers of SBSA Generic Watchdog
+ */(quoted diff) +17
-0+static void sbsa_gwdt_cf_write(unsigned int reg, u32 val, + struct watchdog_device *wdd) +{ + struct sbsa_gwdt *gwdt = to_sbsa_gwdt(wdd); + + writel_relaxed(val, gwdt->control_base + reg); +} + +static void sbsa_gwdt_rf_write(unsigned int reg, u32 val, + struct watchdog_device *wdd) +{ + struct sbsa_gwdt *gwdt = to_sbsa_gwdt(wdd); + + writel_relaxed(val, gwdt->refresh_base + reg); +} + +static u32 sbsa_gwdt_cf_read(unsigned int reg, struct watchdog_device*wdd)
Review
Quoted 5 lines
(quoted diff) +5
-0+{ + struct sbsa_gwdt *gwdt = to_sbsa_gwdt(wdd); + + return readl_relaxed(gwdt->control_base + reg); +}Quoted 4 lines
I still think you should get rid of these functions and just call
readl_relaxed()andwritel_relaxed()every time, but I won't complain again
if you keep them.yes, that make sense, and will reduce the size of code, and I think the code's readability will be OK too.
will try in my next patch,Quoted 17 lines
Review
Quoted 12 lines
(quoted diff) +11
-0+static irqreturn_t sbsa_gwdt_interrupt(int irq, void *dev_id) +{ + struct sbsa_gwdt *gwdt = (struct sbsa_gwdt *)dev_id; + struct watchdog_device *wdd = &gwdt->wdd; + + if (wdd->pretimeout) + /* The pretimeout is valid, go panic */ + panic("SBSA Watchdog pre-timeout"); + else + /* We don't use pretimeout, trigger WS1 now*/ + sbsa_gwdt_set_wcv(wdd, 0);I don't like this.
If so, what is your idea ,if pretimeout == 0?
the reason of using WCV as (timout - pretimeout): it can provide the longer timeout period,
(1)If we use WOR, it can only provide 10s @ 400MHz(max).
as Guenter said earlier, the default timer out for most watchdog will be 30s, so I think 10s limit will be a little short
(2)we can always program WCV just like ping.
(3)if a timeout arrives, WOR will be use, so use it as pretimeout, but we still can make this pretimeout longer by programming WCV(I don't think it's necessary)Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
The triggering of the hardware reset should never depend on an interrupt being handled properly.
if this fail, system reset in 1S, because WOR == (1s)
So ?
Even the interrupt routine isn't triggered, (WOR + system counter) --> WCV,
then, sy system reset in 1S.the hardware reset doesn't depend on an interrupt.
Quoted 17 lines
Quoted 7 lines
Quoted 4 lines
You should always program WCV
correctly in advance. This is especially true since pre-timeout will probably rarely be used.Quoted 8 lines
always programming WCV is doable. But I absolutely can not agree " pre-timeout will probably rarely be used"
If so, SBSA watchdog is just a normal watchdog, This use case just makes this HW useless.
If so, go to use SP805.
you still don't see the importance of this warning and pretimeout to a real server.If pretimeout isn't used, why not just set WCV = timeout, WOR = 0 ?
Quoted 8 lines
Quoted 5 lines
Because if WOR = 0 , according to SBSA, once you want to enable watchdog, (0 + system counter) --> WCV , then , WS0 and WS1 will be triggered immediately.
we have not a chance(a time slot) to update WCV.I would have thought that this is exactly what we want if pretimeout is not used.
Although pretimeout == 0 is not good for a server, but If administrator set up pretimeout == 0. *I thinks we should trigger WS1 ASAP* . Because WS1 maybe a interrupter or a reboot signal, that is why we can not reboot system directly.
This driver is SBSA watchdog driver, that means we need to follow SBSA spec:
(1) SBSA watchdog has two stage timeouts --> timeout and pretimeout is the best solution in watchdog framework, at least for now.
(2) The watchdog has the following output signals:Watchdog Signal 0 (WS0)---> "The initial signal is typically wiredto an interrupt and alerts the system."(original word from spec), I thinks the key work should be "interrupt" and "alerts". So in WS0 interrupt routine, reset is absolutely a wrong operation. Although I think we should make this "alerts" more useful. But for the first version of driver, I thinks panic is useful enough.
Watchdog Signal 1 (WS1). ---> "The signal is fed to a higher agentas an interrupt or reset for it to take executive action." (original word from spec) . The key work should be "interrupt", "or" and "reset" . So WS1 maybe a interrupt.
so even in the WS0 interrupt routine, if pretimeout == 0 , we need to trigger WS1(that is what my patch is doing now, set WCV to 0, so WCV is always less than SystemCounter, and in this situation(WS0 = TRUE), WS1 will be trigger immediately), but definitely not a reset too.But in worst case, if the WS0 is triggered, but the interrupt routine doesn't work(can not set up WCV), it doesn't matter, we just need to wait for a WOR(1s in my driver) timeout, then WS1 will be triggered. That is hardware mechanism, once we config SBSA watchdog correctly, that should work. If it doesn't, I think the chip design doesn't follow the SBSA spec.
Make a summary here, for SBSA watchdog driver, it need to support two stage timeouts and need to trigger WS0/1 when timeouts occur(can not simply reset system in interrupt routines).
If a driver doesn't do these above, the driver can not be called SBSA watchdog driver.
Quoted 4 lines
But according to SBSA, even pretimeout == 0, we can not setup WOR = 0. if we make WOR = 0 , once we set up WCS(enabling watchdog), that cause a explicit watchdog refresh, then WCV = (0 + system counter), so WS0 and WS1 will be triggered serially and immediately(in theory, the
I still don't understand why this would be a problem.
Quoted 4 lines
"delay" also depend on implementation). So in my patchset , if pretimeout == 0, WOR will be 1s at least to make sure we have time to setup WCV. I have made comments in the patch for explaining this.
Quoted 13 lines
Maybe some people want to ask: if we can not set up WOR = 0, but pretimeout can be 0 and timeout can not, why I still want to use WOR for pretimeout and using WCV as (timout - pretimeout) ?? For this:
(1)WCV can provide the longer timeout period, If we use WOR, it can only provide 10s @ 400MHz(max). The default timer out for most watchdog will be 30s, so I think 10s limit will be a little short. (2)we can always program(write) WCV just like ping.
(3)if the first timeout occurs, WOR will be loaded to WCV(WOR + system counter) automatically , so why not just use WOR as pretimeout? Although we still can make this pretimeout longer by programming WCV, I don't think it's necessary for now.
Too bad I don't have an arm64 system to test myself. I am not sure I understand why WOR must be set to > 0 if pretimeout == 0, and even if it must be set to a value > 0 I don't understand why setting it to 1 (instead of 1 second) would not be sufficient.
Guenter
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
Hi Guenter,
Thanks for reply so quickly.
Quoted 199 lines · Guenter Roeck
Quoted 198 lines · Fu Wei
Hi Guenter,
Quoted 150 lines · Guenter Roeck
Quoted 141 lines · Fu Wei
Hi Gurnter
Quoted 102 lines · Guenter Roeck
Quoted 99 lines · Fu Wei
Hi Timur,
Thanks , feedback inline
Quoted 38 lines · Timur Tabi
Quoted 23 lines · On 06/01/2015 11:05 PM, [email protected] wrote:
+/*
+ * help functions for accessing 32bit registers of SBSA Generic Watchdog
+ */(quoted diff) +17
-0+static void sbsa_gwdt_cf_write(unsigned int reg, u32 val, + struct watchdog_device *wdd) +{ + struct sbsa_gwdt *gwdt = to_sbsa_gwdt(wdd); + + writel_relaxed(val, gwdt->control_base + reg); +} + +static void sbsa_gwdt_rf_write(unsigned int reg, u32 val, + struct watchdog_device *wdd) +{ + struct sbsa_gwdt *gwdt = to_sbsa_gwdt(wdd); + + writel_relaxed(val, gwdt->refresh_base + reg); +} + +static u32 sbsa_gwdt_cf_read(unsigned int reg, struct
watchdog_device
*wdd)Review
Quoted 5 lines
(quoted diff) +5
-0+{ + struct sbsa_gwdt *gwdt = to_sbsa_gwdt(wdd); + + return readl_relaxed(gwdt->control_base + reg); +}Quoted 4 lines
I still think you should get rid of these functions and just call
readl_relaxed()andwritel_relaxed()every time, but I won't complain again
if you keep them.yes, that make sense, and will reduce the size of code, and I think the code's readability will be OK too.
will try in my next patch,Quoted 10 lines
Quoted 10 lines
(quoted diff) +9
-0+static irqreturn_t sbsa_gwdt_interrupt(int irq, void *dev_id) +{ + struct sbsa_gwdt *gwdt = (struct sbsa_gwdt *)dev_id; + struct watchdog_device *wdd = &gwdt->wdd; + + if (wdd->pretimeout) + /* The pretimeout is valid, go panic */ + panic("SBSA Watchdog pre-timeout"); + elseQuoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ /* We don't use pretimeout, trigger WS1 now*/ + sbsa_gwdt_set_wcv(wdd, 0);I don't like this.
If so, what is your idea ,if pretimeout == 0?
the reason of using WCV as (timout - pretimeout): it can provide the longer timeout period,
(1)If we use WOR, it can only provide 10s @ 400MHz(max).
as Guenter said earlier, the default timer out for most watchdog will be 30s, so I think 10s limit will be a little short
(2)we can always program WCV just like ping.
(3)if a timeout arrives, WOR will be use, so use it as pretimeout, but we still can make this pretimeout longer by programming WCV(I don't think it's necessary)Quoted 2 lines
The triggering of the hardware reset should never depend on an interrupt being handled properly.
Quoted 3 lines
Quoted 2 lines
if this fail, system reset in 1S, because WOR == (1s)
So ?
Even the interrupt routine isn't triggered, (WOR + system counter) --> WCV,
then, sy system reset in 1S.the hardware reset doesn't depend on an interrupt.
Quoted 17 lines
Quoted 8 lines
Quoted 4 lines
You should always program WCV
correctly in advance. This is especially true since pre-timeout will probably rarely be used.Quoted 8 lines
always programming WCV is doable. But I absolutely can not agree " pre-timeout will probably rarely be used"
If so, SBSA watchdog is just a normal watchdog, This use case just makes this HW useless.
If so, go to use SP805.
you still don't see the importance of this warning and pretimeout to a real server.Quoted 1 line
If pretimeout isn't used, why not just set WCV = timeout, WOR = 0 ?
Quoted 6 lines
Because if WOR = 0 , according to SBSA, once you want to enable watchdog,
(0 + system counter) --> WCV , then , WS0 and WS1 will be triggered immediately.
we have not a chance(a time slot) to update WCV.Quoted 3 lines
I would have thought that this is exactly what we want if pretimeout is not
used.Although pretimeout == 0 is not good for a server, but If administrator set up pretimeout == 0. *I thinks we should trigger WS1 ASAP* . Because WS1 maybe a interrupter or a reboot signal, that is why we can not reboot system directly.
This driver is SBSA watchdog driver, that means we need to follow SBSA spec:
(1) SBSA watchdog has two stage timeouts --> timeout and pretimeout is the best solution in watchdog framework, at least for now.
(2) The watchdog has the following output signals:Watchdog Signal 0 (WS0)---> "The initial signal is typically wiredto an interrupt and alerts the system."(original word from spec), I thinks the key work should be "interrupt" and "alerts". So in WS0 interrupt routine, reset is absolutely a wrong operation. Although I think we should make this "alerts" more useful. But for the first version of driver, I thinks panic is useful enough.
Watchdog Signal 1 (WS1). ---> "The signal is fed to a higher agentas an interrupt or reset for it to take executive action." (original word from spec) . The key work should be "interrupt", "or" and "reset" . So WS1 maybe a interrupt.
so even in the WS0 interrupt routine, if pretimeout == 0 , we need to trigger WS1(that is what my patch is doing now, set WCV to 0, so WCV is always less than SystemCounter, and in this situation(WS0 = TRUE), WS1 will be trigger immediately), but definitely not a reset too.But in worst case, if the WS0 is triggered, but the interrupt routine doesn't work(can not set up WCV), it doesn't matter, we just need to wait for a WOR(1s in my driver) timeout, then WS1 will be triggered. That is hardware mechanism, once we config SBSA watchdog correctly, that should work. If it doesn't, I think the chip design doesn't follow the SBSA spec.
Make a summary here, for SBSA watchdog driver, it need to support two stage timeouts and need to trigger WS0/1 when timeouts occur(can not simply reset system in interrupt routines).
If a driver doesn't do these above, the driver can not be called SBSA watchdog driver.
Quoted 7 lines
Quoted 4 lines
But according to SBSA, even pretimeout == 0, we can not setup WOR = 0. if we make WOR = 0 , once we set up WCS(enabling watchdog), that cause a explicit watchdog refresh, then WCV = (0 + system counter), so WS0 and WS1 will be triggered serially and immediately(in theory, the
I still don't understand why this would be a problem.
that 20+ lines pseudocode from the page 23 of SBSA spec 2.3 can explain this well.
Please let me know which line confuse you, I will explain them one by one below.
Quoted 19 lines
Quoted 5 lines
"delay" also depend on implementation). So in my patchset , if pretimeout == 0, WOR will be 1s at least to make sure we have time to setup WCV. I have made comments in the patch for explaining this.
Quoted 13 lines
Maybe some people want to ask: if we can not set up WOR = 0, but pretimeout can be 0 and timeout can not, why I still want to use WOR for pretimeout and using WCV as (timout - pretimeout) ?? For this:
(1)WCV can provide the longer timeout period, If we use WOR, it can only provide 10s @ 400MHz(max). The default timer out for most watchdog will be 30s, so I think 10s limit will be a little short. (2)we can always program(write) WCV just like ping.
(3)if the first timeout occurs, WOR will be loaded to WCV(WOR + system counter) automatically , so why not just use WOR as pretimeout? Although we still can make this pretimeout longer by programming WCV, I don't think it's necessary for now.
Quoted 2 lines
Too bad I don't have an arm64 system to test myself. I am not sure I understand why WOR must be set to > 0 if pretimeout == 0, and even
Although SBSA spec has published for years(2.2 was published at 15th Jan 2014), but this is still a relatively new spec of hardware, for now . I only has Foundation model and FAST model for testing. But I would like to suggest: this driver should follow the SBSA spec first, but not a specific hardware, even some of hardware has this watchdog, but there maybe some hardware bug in it(at least I know there is one).
I am using 1 second, just because I think 1 second is safe enough to reload WCV. (from write "1" in WCS to reload WCV[31:0] and WCV[63:32] )
Actually, in most of case , we need WOR > 1, only when we enable the watchdog( write "1" to WCS, this causes a ExplicitRefresh, see Line 7 "ExplicitRefresh == TRUE" and Line 8 below).
in this cause , we just need a time slot to reload WCV, the driver doesn't really spend 1s on this.
But If WOR ==0, (Line 1) TimeoutRefresh = TRUE in a very short time, the minimum time depends on the implementation. Then The first timeout stage occur(see Line 7 (TimeoutRefresh == TRUE and WS0 == FALSE), and Line 8 below again ) and WS0 was triggered(Line 16~18). Because WOR ==0 too, (Line 1) TimeoutRefresh = TRUE occur in a very short time again, then see Line 16, 17, 20
In worst case, if pretimeout is 0, First timeout stage occur(see Line 7 (TimeoutRefresh == TRUE and WS0 == FALSE), and Line 8 below, then
Line 16~18) but the interrupt routine doesn't work, we can still got
WS1 in the time we configured in WOR. (Line 1) TimeoutRefresh = TRUE occur when SystemCounter[63:0] > SystemCounter[63:0] + ZeroExtend(WOR[31:0]), then Line 16, 17, 20
---------------------------------------------------
CompareValue : WCV
WatchdogOffsetValue : WOR
1 TimeoutRefresh = (SystemCounter[63:0] > CompareValue[63:0])
2 If WatchdogColdReset
3 WatchdogEnable = DISABLED
4 Endif
5 If LoadNewCompareValue
6 CompareValue = new_value
7 ElseIf ExplicitRefresh == TRUE or (TimeoutRefresh == TRUE and WS0 == FALSE)
8 CompareValue = SystemCounter[63:0] +ZeroExtend(WatchdogOffsetValue[31:0])
9 Endif
10 If WatchdogEnable == DISABLED
11 WS0 = FALSE
12 WS1 = FALSE
13 ElseIf ExplicitRefresh == TRUE
14 WS0 = FALSE
15 WS1 = FALSE
16 ElseIf TimeoutRefresh == TRUE
17 If WS0 == FALSE
18 WS0 = TRUE
19 Else
20 WS1 = TRUE
21 Endif
22 Endif
---------------------------------------------------
I would like to stress that pretimeout == 0 should not happen in a real server system, that is why we defined a SBSA watchdog, but not a normal one
But we still need to thinking about the situation that administrator want to do this on a very special purpose.
maybe we can set min_pretimeout = 1 for this driver. that is just a suggestion.
Quoted 2 lines
if it must be set to a value > 0 I don't understand why setting it to 1 (instead of 1 second) would not be sufficient.
it don't have to be 1 second , it can be 0.1, 0.5 or 0.01 second. like I said before, we just need a time slot to setup WCV in sbsa_gwdt_start. I have commented this in sbsa_gwdt_set_pretimeout in this patchset.
But I think the minimum time slot depend on implementation, the spec doesn't mention about this.
If pretimeout == 0, and we set up WOR a little bigger, it *ONLY* affect "the worst case" I mention above. in this case, a administrator set up pretimeout == 0 which should not happen in a real server, then the system goes very wrong. I don't think it is important that this server system reset in 1 second or 0.0001 second, at this time, this server can not provide any useful info anyway(because we don't use pretimeout).
If system may go wrong, the administrator should set up pretimeout > 0 to figure out what is wrong with it just like he always should do.
Quoted 3 lines
Guenter
Signature · 14 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Guenter Roeck
maintainerRe: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
Quoted 4 lines · Fu Wei
I would like to stress that pretimeout == 0 should not happen in a real server system, that is why we defined a SBSA watchdog, but not a normal one
Clarification - In _your opinion_, a server should always use pretimeout.
Quoted 3 lines
But we still need to thinking about the situation that administrator want to do this on a very special purpose.
I could as well argue that setting pretimeout is the special situation. Some administrators may not want to bother but just want the system to reset if a watchdog timeout occurs. _Maybe_ if it happens multiple times, they might want to set up pretimeout to figure out why.
Declaring that one _has_ to configure pretimeout is just a personal opinion, nothing else. We don't know what server administrators want, and we should not dictate anything unless technically necessary.
Quoted 2 lines
maybe we can set
min_pretimeout= 1 for this driver. that is just a suggestion.
No. It is not technically necessary.
Quoted 8 lines
Quoted 3 lines
if it must be set to a value > 0 I don't understand why setting it to 1 (instead of 1 second) would not be sufficient.
it don't have to be 1 second , it can be 0.1, 0.5 or 0.01 second. like I said before, we just need a time slot to setup WCV in
sbsa_gwdt_start. I have commented this insbsa_gwdt_set_pretimeoutin this patchset.
I think what you really want to say is that you want to have time to handle the interrupt. But handling the interrupt is not asked for if pretimeout == 0.
Quoted 2 lines
But I think the minimum time slot depend on implementation, the spec doesn't mention about this.
Yes, because a minimum value does not exist.
Quoted 10 lines
If pretimeout == 0, and we set up WOR a little bigger, it *ONLY* affect "the worst case" I mention above. in this case, a administrator set up pretimeout == 0 which should not happen in a real server, then the system goes very wrong. I don't think it is important that this server system reset in 1 second or 0.0001 second, at this time, this server can not provide any useful info anyway(because we don't use pretimeout).
If system may go wrong, the administrator should set up pretimeout > 0 to figure out what is wrong with it just like he always should do.
Yes, exactly. But otherwise, if pretimeout is set to 0, we want to reset immediately as directed.
As I interpret the specification, WOR=0 forces WS1 immediately after WS0.
1) if TimeoutRefresh = True:
CompareValue := SystemCounter + WOR (= SystemCounter WS0 := True
2) TimeoutRefresh is True again, WS0 == True:
WS1 = True
This is exactly the behavior we want if pretimeout == 0. In this situation, we don't want to handle the interrupt, we just want to reset the system as fast as possible.
Having said that, have you tested what happens in your system if you set WOR=0 ?
Thanks,
Guenter
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
Hi Guenter,
Thanks for your feedback
Quoted 10 lines · Guenter Roeck
Quoted 4 lines · Fu Wei
I would like to stress that pretimeout == 0 should not happen in a real server system, that is why we defined a SBSA watchdog, but not a normal one
Clarification - In
_youropinion_, a server should always use pretimeout.
Quoted 7 lines
Quoted 3 lines
But we still need to thinking about the situation that administrator want to do this on a very special purpose.
I could as well argue that setting pretimeout is the special situation. Some administrators may not want to bother but just want the system to reset if a watchdog timeout occurs. _Maybe_ if it happens multiple times, they might want to set up pretimeout to figure out why.
you are right,
before this driver and device are really used in some server, we don't know How do administrators use this pretimeout,
and the percentage of using pretimeout, But here you did mention a good usage of pretimeout: we can figure out what is wrong with system.
except the usages, this two stage timeouts is a main feature of SBSA watchdog, if we drop this feature, I don't think that is a SBSA watchdog driver. it becomes normal watchdog driver using SBSA watchdog hardware.
Quoted 4 lines
Declaring that one _has_ to configure pretimeout is just a personal opinion, nothing else. We don't know what server administrators want, and we should not dictate anything unless technically necessary.
yes, agree with you on "we should not dictate anything unless technically necessary."
Quoted 5 lines
Quoted 4 lines
maybe we can set
min_pretimeout= 1 for this driver. that is just a suggestion.No. It is not technically necessary.
it is just a thought. but I never do that , because min_pretimeout = 0 is technically doable in this driver.
Quoted 12 lines
Quoted 10 lines
Quoted 4 lines
if it must be set to a value > 0 I don't understand why setting it to 1 (instead of 1 second) would not be sufficient.
it don't have to be 1 second , it can be 0.1, 0.5 or 0.01 second. like I said before, we just need a time slot to setup WCV in
sbsa_gwdt_start. I have commented this insbsa_gwdt_set_pretimeoutin this patchset.
Quoted 3 lines
I think what you really want to say is that you want to have time to handle the interrupt. But handling the interrupt is not asked for if pretimeout == 0.
No, that is not what I want to say. pretimeout == 0 but WOR can not be 0 is nothing to do with interrupt.
In another word, pretimeout == 0 we should trigger WS1 ASAP, we don't need to handle the interrupt.
I have explained this in previous email:
"
we need WOR > 1, only when we enable the watchdog( write "1" to WCS, this causes a ExplicitRefresh, see Line 7 "ExplicitRefresh == TRUE" and Line 8 below).
in this cause , we just need a time slot to reload WCV, the driver doesn't really spend 1s on this.
But If WOR ==0, (Line 1) TimeoutRefresh = TRUE in a very short time, the minimum time depends on the implementation. Then The first timeout stage occur(see Line 7 (TimeoutRefresh == TRUE and WS0 == FALSE), and Line 8 below again ) and WS0 was triggered(Line 16~18). Because WOR ==0 too, (Line 1) TimeoutRefresh = TRUE occur in a very short time again, then see Line 16, 17, 20
"
in one word, according to SBSA, If we make WOR == 0, once we enable watchdog, WS0 and WS1 will be triggered immediately, we have not chance to set up WCV for (timeout - pretimeout).
In another word, WOR == 0, we can not enable watchdog, enabling become a warn reset button.
Quoted 18 lines
Quoted 3 lines
But I think the minimum time slot depend on implementation, the spec doesn't mention about this.
Yes, because a minimum value does not exist.
Quoted 10 lines
If pretimeout == 0, and we set up WOR a little bigger, it *ONLY* affect "the worst case" I mention above. in this case, a administrator set up pretimeout == 0 which should not happen in a real server, then the system goes very wrong. I don't think it is important that this server system reset in 1 second or 0.0001 second, at this time, this server can not provide any useful info anyway(because we don't use pretimeout).
If system may go wrong, the administrator should set up pretimeout > 0 to figure out what is wrong with it just like he always should do.
Quoted 2 lines
Yes, exactly. But otherwise, if pretimeout is set to 0, we want to reset immediately as directed.
In this driver, if pretimeout is set to 0, we want to *trigger WS1* immediately as directed.
Yes, If we could.
Quoted 9 lines
As I interpret the specification, WOR=0 forces WS1 immediately after WS0.
1) if TimeoutRefresh = True:
CompareValue := SystemCounter + WOR (= SystemCounter WS0 := True
2) TimeoutRefresh is True again, WS0 == True:
WS1 = True
Quoted 3 lines
This is exactly the behavior we want if pretimeout == 0. In this situation, we don't want to handle the interrupt, we just want to reset the system as fast as possible.
Yes, if WOR only affect in TimeoutRefresh, we cat always make WOR == pretimeout But the problem is if we enable watchdog (write 0x01 to WCS will cause an explicit watchdog refresh), then
1) if ExplicitRefresh = True:
CompareValue := SystemCounter + WOR
WS0 := True
2) TimeoutRefresh is True again, WS0 == True:
WS1 = True
so once we enable watchdog, system reset, that is not what we want. this behavior is following SBSA spec.
FYI:
-----
An explicit watchdog refresh occurs when one of a number of different events occur:
The Watchdog Refresh Register is written.
The Watchdog Offset Register is written.
The Watchdog Control and Status register is written.
-----
Quoted 3 lines
Having said that, have you tested what happens in your system if you set WOR=0 ?
I have not HW, but I have tested it on Foundation model, the result is just what I expect:
-------------------------------------
pretimeout=0 ,
and
static int sbsa_gwdt_set_pretimeout(struct watchdog_device *wdd,
unsigned int pretimeout)
{
struct sbsa_gwdt *gwdt = to_sbsa_gwdt(wdd);
wdd->pretimeout = pretimeout;
/* refresh the WOR, that will cause an explicit watchdog refresh */
sbsa_gwdt_cf_write(SBSA_GWDT_WOR, pretimeout * gwdt->clk, wdd);
return 0;
}-------------------------------------
Once I enable watchdog, system down(there is a WS1 interrupter in Foundation model, but not more info for that), there is not panic(if ws0 is triggered).
Quoted 4 lines
Thanks,
Guenter
Signature · 10 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021
Guenter Roeck
maintainerRe: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
Quoted 9 lines · Fu Wei
Yes, if WOR only affect in TimeoutRefresh, we cat always make WOR == pretimeout But the problem is if we enable watchdog (write
0x01to WCS will cause an explicit watchdog refresh), then
1) if ExplicitRefresh = True:
CompareValue := SystemCounter + WOR
WS0 := True
2) TimeoutRefresh is True again, WS0 == True:
WS1 = True
Quoted 3 lines
so once we enable watchdog, system reset, that is not what we want. this behavior is following SBSA spec.
Ok, I admit I am a bit slow ;-).
WS0 := True would be set the next time around, since
if ExplicitRefresh == True
WS0 = False
WS1 = False
but I see your point. Essentially, the specification is broken for all practical purposes, since, as you point out, enabling the watchdog overwrites and explicitly sets WCV. Effectively this means that just using WCV to program the timeout period is not really possible.
I am not really sure how to address this. We can either only use WOR, and forget about pretimeout, or we can enforce a minimum pretimeout. In the latter case, we'll have to write WCV after writing WOR.
Thanks,
Guenter
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
Quoted 11 lines · Guenter Roeck
but I see your point. Essentially, the specification is broken for all practical purposes, since, as you point out, enabling the watchdog overwrites and explicitly sets WCV. Effectively this means that just using WCV to program the timeout period is not really possible.
I am not really sure how to address this. We can either only use WOR, and forget about pretimeout, or we can enforce a minimum pretimeout. In the latter case, we'll have to write WCV after writing WOR.
In talking with our hardware engineers, using WCV to program the timeout period is not a valid operation. This is why I keep arguing against the pre-timeout feature, and I don't agree that servers should always use pre-timeout.
Signature · 7 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project. -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Guenter Roeck
maintainerRe: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
Quoted 9 lines · Timur Tabi
Quoted 8 lines · Guenter Roeck
but I see your point. Essentially, the specification is broken for all practical purposes, since, as you point out, enabling the watchdog overwrites and explicitly sets WCV. Effectively this means that just using WCV to program the timeout period is not really possible.
Quoted 6 lines
Quoted 3 lines
I am not really sure how to address this. We can either only use WOR, and forget about pretimeout, or we can enforce a minimum pretimeout. In the latter case, we'll have to write WCV after writing WOR.
In talking with our hardware engineers, using WCV to program the timeout period is not a valid operation. This is why I keep arguing against the pre-timeout feature, and I don't agree that servers should always use pre-timeout.
Not sure if "not valid" is correct - after all, it is mentioned in the specification. However, it is at the very least fragile.
I tend to agree that we should just forget about pretimeout and use your original approach, where the timeout value is used to program WOR. Everything else is really just asking for trouble.
Guenter
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
Quoted 3 lines · Guenter Roeck
I tend to agree that we should just forget about pretimeout and use your original approach, where the timeout value is used to program WOR. Everything else is really just asking for trouble.
The driver that I submitted is effectively the same as Fu's, except without pre-timeout support.
Signature · 7 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project. -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
In reply to Guenter RoeckHi Guenter,
Quoted 17 lines · Guenter Roeck
Quoted 16 lines · Timur Tabi
Quoted 12 lines · Guenter Roeck
but I see your point. Essentially, the specification is broken for all practical purposes, since, as you point out, enabling the watchdog overwrites and explicitly sets WCV. Effectively this means that just using WCV to program the timeout period is not really possible.
I am not really sure how to address this. We can either only use WOR, and forget about pretimeout, or we can enforce a minimum pretimeout. In the latter case, we'll have to write WCV after writing WOR.
Quoted 8 lines
Quoted 5 lines
In talking with our hardware engineers, using WCV to program the timeout period is not a valid operation. This is why I keep arguing against the pre-timeout feature, and I don't agree that servers should always use pre-timeout.
Not sure if "not valid" is correct - after all, it is mentioned in the specification. However, it is at the very least fragile.
I think we should focus on SBSA spec, but not a specific chip design, because this is SBSA watchdog, not a driver for an IP core from a specific chip vendor.
this operation is mentioned in the spec,
and I have tested my driver on Foundation model(from ARM) and a real hardware.
Quoted 4 lines
I tend to agree that we should just forget about pretimeout and use your original approach, where the timeout value is used to program WOR. Everything else is really just asking for trouble.
I don't mind if we give up pretimeout, The reason I use pretimeout is:
this concept matches the function of two stage timeouts.
but, If we give up pretimeout, could you give me a suggestion:
How to config the two stage timeouts
(1)from enabling watchdog to WS0
(2)the time from WS1 to WS0
If we only have one timeout parameter, How to config the two stage timeouts? Any suggestion ?
If we make the first stage timeout is timeout/2, this violates the definition of timeout.
I don't think users expect interrupt, panic or reboot at timeout/2.
And WS1 definitely isn't a backup of WS0.
Quoted 3 lines
Guenter
Signature · 14 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
Hi Guenter,
Quoted 26 lines · Fu Wei
Hi Guenter,
Quoted 23 lines · Guenter Roeck
Quoted 21 lines · Timur Tabi
Quoted 9 lines · Guenter Roeck
but I see your point. Essentially, the specification is broken for all practical purposes, since, as you point out, enabling the watchdog overwrites and explicitly sets WCV. Effectively this means that just using WCV to program the timeout period is not really possible.
Quoted 3 lines
I am not really sure how to address this. We can either only use WOR, and forget about pretimeout, or we can enforce a minimum pretimeout. In the latter case, we'll have to write WCV after writing WOR.
In talking with our hardware engineers, using WCV to program the timeout period is not a valid operation. This is why I keep arguing against the pre-timeout feature, and I don't agree that servers should always use pre-timeout.
Quoted 13 lines
Quoted 2 lines
Not sure if "not valid" is correct - after all, it is mentioned in the specification. However, it is at the very least fragile.
I think we should focus on SBSA spec, but not a specific chip design, because this is SBSA watchdog, not a driver for an IP core from a specific chip vendor.
this operation is mentioned in the spec,
and I have tested my driver on Foundation model(from ARM) and a real hardware.Quoted 4 lines
I tend to agree that we should just forget about pretimeout and use your original approach, where the timeout value is used to program WOR. Everything else is really just asking for trouble.
Another weakness of only using WOR is the timeout limited by this 32bit register.
10s @400MHz generic Timer
I don't think this limit is good for a server, once the server is in a heavy load
Quoted 36 lines
I don't mind if we give up pretimeout, The reason I use pretimeout is:
this concept matches the function of two stage timeouts.but, If we give up pretimeout, could you give me a suggestion:
How to config the two stage timeouts
(1)from enabling watchdog to WS0
(2)the time from WS1 to WS0If we only have one timeout parameter, How to config the two stage timeouts? Any suggestion ?
If we make the first stage timeout is timeout/2, this violates the definition of timeout.
I don't think users expect interrupt, panic or reboot at timeout/2.And WS1 definitely isn't a backup of WS0.
Quoted 3 lines
Guenter
--
Best regards,Fu Wei
Software Engineer
Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch
Ph: +86 21 61221326(direct)
Ph: +86 186 2020 4684 (mobile)
Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021
Signature · 10 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021
v5 cover Watchdog: introduce ARM SBSA watchdog driver
In reply to a message not in the archiveFrom: Fu Wei <[email protected]>
This patchset:
(1)Introduce Documentation/devicetree/bindings/watchdog/sbsa-gwdt.txt for FDT info of SBSA Generic Watchdog, and give two examples of adding SBSA Generic Watchdog device node into the dts files:
foundation-v8.dts and amd-seattle-soc.dtsi.
(2)Introduce ACPI GTDT parser: drivers/acpi/gtdt.c
Parse SBSA Generic Watchdog Structure in GTDT table of ACPI, and create a platform device with that information.
This platform device can be used by This Watchdog driver. drivers/clocksource/arm_arch_timer.c is simplified by this GTDT support.
(3)Introduce "pretimeout" into the watchdog framework, and update Documentation/watchdog/watchdog-kernel-api.txt to introduce:
(1)the new elements in the watchdog_device and watchdog_ops struct; (2)the new API "watchdog_init_timeouts".
(4)Introduce ARM SBSA watchdog driver:
a.Use linux kernel watchdog framework;
b.Work with FDT on ARM64;
c.Use "pretimeout" in watchdog framework;
d.In first timeout, do panic to save system context; e.Support getting timeout and pretimeout from parameter and FDT
at the driver init stage.
This patchset has been tested with watchdog daemon (ACPI/FDT, module/build-in) on the following platforms:
(1)ARM Foundation v8 model
Changelog:
v5: Improve pretimeout support:
(1)fix typo in documentation and comments.
(2)fix the timeout limits validation bug.
Simplify sbsa_gwdt driver:
(1)integrate all the registers access functions into caller.
v4: Refactor GTDT support code: remove it from arch/arm64/kernel/acpi.c,
put it into drivers/acpi/gtdt.c file.
Integrate the GTDT code of drivers/clocksource/arm_arch_timer.c into
drivers/acpi/gtdt.c.
Improve pretimeout support, fix "pretimeout == 0" problem.
Simplify sbsa_gwdt driver:
(1)timeout/pretimeout limits setup;
(2)keepalive function;
(3)delete "clk == 0" check;
(4)delete WS0 status bit check in interrupt routine;
(5)sbsa_gwdt_set_wcv function.v3: Delete "export arch_timer_get_rate" patch.
Driver back to use arch_timer_get_cntfrq.
Improve watchdog_init_timeouts function and update relevant documentation. Improve watchdog_timeout_invalid and watchdog_pretimeout_invalid. Improve foundation-v8.dts: delete the unnecessary tag of device node. Remove "ARM64 || COMPILE_TEST" from Kconfig.
Add comments in arch/arm64/kernel/acpi.c
Fix typoes and incorrect comments.
v2: Improve watchdog-kernel-api.txt documentation for pretimeout support.
Export "arch_timer_get_rate" in arm_arch_timer.c.
Add watchdog_init_timeouts API for pretimeout support in framework. Improve suspend and resume foundation in driver
Improve timeout/pretimeout values init code in driver. Delete unnecessary items of the sbsa_gwdt struct and #define. Delete all unnecessary debug info in driver.
Fix 64bit division bug.
Use the arch_timer interface to get watchdog clock rate. Add MODULE_DEVICE_TABLE for platform device id.
Fix typoes.
v1: The first version upstream patchset to linux mailing list.
Fu Wei (8):
Documentation: add sbsa-gwdt.txt documentation
ARM64: add SBSA Generic Watchdog device node in foundation-v8.dts
ARM64: add SBSA Generic Watchdog device node in amd-seattle-soc.dtsi
Watchdog: introdouce "pretimeout" into framework
Watchdog: introduce ARM SBSA watchdog driver
ACPI: add GTDT table parse driver into ACPI driver
Watchdog: enable ACPI GTDT support for ARM SBSA watchdog driver
clocksource: simplify ACPI code in arm_arch_timer.c
.../devicetree/bindings/watchdog/sbsa-gwdt.txt | 36 ++ Documentation/watchdog/watchdog-kernel-api.txt | 47 ++- arch/arm64/boot/dts/amd/amd-seattle-soc.dtsi | 11 + arch/arm64/boot/dts/arm/foundation-v8.dts | 10 + arch/arm64/kernel/time.c | 4 +- drivers/acpi/Kconfig | 9 + drivers/acpi/Makefile | 1 + drivers/acpi/gtdt.c | 180 +++++++++ drivers/clocksource/Kconfig | 1 + drivers/clocksource/arm_arch_timer.c | 60 +-- drivers/watchdog/Kconfig | 12 + drivers/watchdog/Makefile | 1 + drivers/watchdog/sbsa_gwdt.c | 409 +++++++++++++++++++++ drivers/watchdog/watchdog_core.c | 100 +++-- drivers/watchdog/watchdog_dev.c | 53 +++ include/clocksource/arm_arch_timer.h | 8 + include/linux/acpi.h | 5 + include/linux/clocksource.h | 4 +- include/linux/watchdog.h | 36 +- 19 files changed, 895 insertions(+), 92 deletions(-) create mode 100644 Documentation/devicetree/bindings/watchdog/sbsa-gwdt.txt create mode 100644 drivers/acpi/gtdt.c create mode 100644 drivers/watchdog/sbsa_gwdt.c
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v5 1/8 Documentation: add sbsa-gwdt.txt documentation
From: Fu Wei <[email protected]>
The sbsa-gwdt.txt documentation in devicetree/bindings/watchdog is for introducing SBSA(Server Base System Architecture) Generic Watchdog device node info into FDT.
--- .../devicetree/bindings/watchdog/sbsa-gwdt.txt | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/sbsa-gwdt.txt
Documentation/devicetree/bindings/watchdog/sbsa-gwdt.txt new file +36 -0
@@ -0,0 +1,36 @@ +* SBSA(Server Base System Architecture) Generic Watchdog + +The SBSA Generic Watchdog Timer is used for resetting the system after +two stages of timeout. +More details: ARM-DEN-0029 - Server Base System Architecture (SBSA) + +Required properties: +- compatible : Should at least contain "arm,sbsa-gwdt". + +- reg : base physical address of the frames and length of memory mapped region. + +- reg-names : Should contain the resource reg names to show the order of + the values in "reg". + Must include the following entries : "refresh", "control". + +- interrupts : Should at least contain WS0 interrupt, + the WS1 Signal is optional. + +- interrupt-names : Should contain the resource interrupt names. + Must include the following entries : "ws0". "ws1" is optional. + +Optional properties +- timeout-sec : Watchdog pre-timeout and timeout values (in seconds). + The first is timeout values, then pre-timeout. + +Example for FVP Foundation Model v8: + +watchdog@2a440000 { + compatible = "arm,sbsa-gwdt"; + reg = <0x0 0x2a440000 0 0x10000>, + <0x0 0x2a450000 0 0x10000>; + reg-names = "control", "refresh"; + interrupts = <0 27 4>; + interrupt-names = "ws0"; + timeout-sec = <10 5>; +};
Signature · 1 line
1.9.1
PATCH v5 2/8 ARM64: add SBSA Generic Watchdog device node in foundation-v8.dts
In reply to [email protected]From: Fu Wei <[email protected]>
This can be a example of adding SBSA Generic Watchdog device node into some dts files for the Soc which contains SBSA Generic Watchdog.
--- arch/arm64/boot/dts/arm/foundation-v8.dts | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/arm64/boot/dts/arm/foundation-v8.dts +10 -0
@@ -237,4 +237,14 @@ }; }; }; + watchdog@2a440000 { + compatible = "arm,sbsa-gwdt"; + reg = <0x0 0x2a440000 0 0x10000>, + <0x0 0x2a450000 0 0x10000>; + reg-names = "control", + "refresh"; + interrupts = <0 27 4>; + interrupt-names = "ws0"; + timeout-sec = <10 5>; + }; };
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v5 3/8 ARM64: add SBSA Generic Watchdog device node in amd-seattle-soc.dtsi
In reply to [email protected]From: Fu Wei <[email protected]>
This can be a example of adding SBSA Generic Watchdog device node into some dts files for the Soc which contains SBSA Generic Watchdog.
--- arch/arm64/boot/dts/amd/amd-seattle-soc.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/arm64/boot/dts/amd/amd-seattle-soc.dtsi +11 -0
@@ -84,6 +84,17 @@ clock-names = "uartclk", "apb_pclk"; }; + watchdog0: watchdog@e0bb0000 { + compatible = "arm,sbsa-gwdt"; + reg = <0x0 0xe0bb0000 0 0x10000>, + <0x0 0xe0bc0000 0 0x10000>; + reg-names = "refresh", + "control"; + interrupts = <0 337 4>; + interrupt-names = "ws0"; + timeout-sec = <10 5>; + }; + spi0: ssp@e1020000 { status = "disabled"; compatible = "arm,pl022", "arm,primecell";
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v5 4/8 Watchdog: introdouce "pretimeout" into framework
In reply to [email protected]From: Fu Wei <[email protected]>
Also update Documentation/watchdog/watchdog-kernel-api.txt to introduce:
(1)the new elements in the watchdog_device and watchdog_ops struct; (2)the new API "watchdog_init_timeouts"
Reasons:
(1)kernel already has two watchdog drivers are using "pretimeout":
drivers/char/ipmi/ipmi_watchdog.c drivers/watchdog/kempld_wdt.c(but the definition is different)
(2)some other drivers are going to use this: ARM SBSA Generic Watchdog
--- Documentation/watchdog/watchdog-kernel-api.txt | 47 ++++++++++-- drivers/watchdog/watchdog_core.c | 100 +++++++++++++++++-------- drivers/watchdog/watchdog_dev.c | 53 +++++++++++++ include/linux/watchdog.h | 36 ++++++++- 4 files changed, 197 insertions(+), 39 deletions(-)
Documentation/watchdog/watchdog-kernel-api.txt +42 -5
@@ -49,6 +49,9 @@ struct watchdog_device { unsigned int timeout; unsigned int min_timeout; unsigned int max_timeout; + unsigned int pretimeout; + unsigned int min_pretimeout; + unsigned int max_pretimeout; void *driver_data; struct mutex lock; unsigned long status;
@@ -70,6 +73,9 @@ It contains following fields: * timeout: the watchdog timer's timeout value (in seconds). * min_timeout: the watchdog timer's minimum timeout value (in seconds). * max_timeout: the watchdog timer's maximum timeout value (in seconds). +* pretimeout: the watchdog timer's pretimeout value (in seconds). +* min_pretimeout: the watchdog timer's minimum pretimeout value (in seconds). +* max_pretimeout: the watchdog timer's maximum pretimeout value (in seconds). * bootstatus: status of the device after booting (reported with watchdog WDIOF_* status bits). * driver_data: a pointer to the drivers private data of a watchdog device.
@@ -92,6 +98,7 @@ struct watchdog_ops { int (*ping)(struct watchdog_device *); unsigned int (*status)(struct watchdog_device *); int (*set_timeout)(struct watchdog_device *, unsigned int); + int (*set_pretimeout)(struct watchdog_device *, unsigned int); unsigned int (*get_timeleft)(struct watchdog_device *); void (*ref)(struct watchdog_device *); void (*unref)(struct watchdog_device *);
@@ -153,9 +160,19 @@ they are supported. These optional routines/operations are: and -EIO for "could not write value to the watchdog". On success this routine should set the timeout value of the watchdog_device to the achieved timeout value (which may be different from the requested one - because the watchdog does not necessarily has a 1 second resolution). + because the watchdog does not necessarily has a 1 second resolution; + If the driver supports pretimeout, then the timeout value must be greater + than that). (Note: the WDIOF_SETTIMEOUT needs to be set in the options field of the watchdog's info structure). +* set_pretimeout: this routine checks and changes the pretimeout of the + watchdog timer device. It returns 0 on success, -EINVAL for "parameter out of + range" and -EIO for "could not write value to the watchdog". On success this + routine should set the pretimeout value of the watchdog_device to the + achieved pretimeout value (which may be different from the requested one + because the watchdog does not necessarily has a 1 second resolution). + (Note: the WDIOF_PRETIMEOUT needs to be set in the options field of the + watchdog's info structure). * get_timeleft: this routines returns the time that's left before a reset. * ref: the operation that calls kref_get on the kref of a dynamically allocated watchdog_device struct.
@@ -219,8 +236,28 @@ extern int watchdog_init_timeout(struct watchdog_device *wdd, unsigned int timeout_parm, struct device *dev); The watchdog_init_timeout function allows you to initialize the timeout field -using the module timeout parameter or by retrieving the timeout-sec property from -the device tree (if the module timeout parameter is invalid). Best practice is -to set the default timeout value as timeout value in the watchdog_device and -then use this function to set the user "preferred" timeout value. +using the module timeout parameter or by retrieving the first element of +the timeout-sec property from the device tree (if the module timeout parameter +is invalid). Best practice is to set the default timeout value as timeout value +in the watchdog_device and then use this function to set the user "preferred" +timeout value. +This routine returns zero on success and a negative errno code for failure. + +Some watchdog timers have two stage of timeouts(timeout and pretimeout), +to initialize the timeout and pretimeout fields at the same time, the following +function can be used: + +extern int watchdog_init_timeouts(struct watchdog_device *wdd, + unsigned int pretimeout_parm, + unsigned int timeout_parm, + struct device *dev); + +The watchdog_init_timeouts function allows you to initialize the pretimeout and +timeout fields using the module pretimeout and timeout parameter or by +retrieving the elements in the timeout-sec property(the first element is for +timeout, the second one is for pretimeout) from the device tree(if the module +pretimeout and timeout parameter are invalid). +Best practice is to set the default pretimeout and timeout value as pretimeout +and timeout value in the watchdog_device and then use this function to set the +user "preferred" pretimeout value. This routine returns zero on success and a negative errno code for failure.
drivers/watchdog/watchdog_core.c +69 -31
136 lines not on this page · raw message
drivers/watchdog/watchdog_dev.c +53 -0
65 lines not on this page · raw message
include/linux/watchdog.h +33 -3
@@ -25,6 +25,7 @@ struct watchdog_device;* @ping: The routine that sends a keepalive ping to the watchdog device. * @status: The routine that shows the status of the watchdog device. * @set_timeout:The routine for setting the watchdog devices timeout value. +* @set_pretimeout:The routine for setting the watchdog devices pretimeout value * @get_timeleft:The routine that get's the time that's left before a reset. * @ref: The ref operation for dyn. allocated watchdog_device structs * @unref: The unref operation for dyn. allocated watchdog_device structs
@@ -44,6 +45,7 @@ struct watchdog_ops {int (*ping)(struct watchdog_device *);unsigned int (*status)(struct watchdog_device *);int (*set_timeout)(struct watchdog_device *,unsigned int ); +int (*set_pretimeout)(struct watchdog_device *,unsigned int );unsigned int (*get_timeleft)(struct watchdog_device *);void (*ref)(struct watchdog_device *);void (*unref)(struct watchdog_device *);
@@ -62,6 +64,9 @@ struct watchdog_ops {* @timeout: The watchdog devices timeout value. * @min_timeout:The watchdog devices minimum timeout value. * @max_timeout:The watchdog devices maximum timeout value. +* @pretimeout: The watchdog devices pretimeout value. +* @min_pretimeout:The watchdog devices minimum pretimeout value. +* @max_pretimeout:The watchdog devices maximum pretimeout value. * @driver-data:Pointer to the drivers private data. * @lock: Lock for watchdog core internal use only. * @status: Field that contains the devices internal status bits.
@@ -86,6 +91,9 @@ struct watchdog_device {unsigned int timeout;unsigned int min_timeout;unsigned int max_timeout; +unsigned int pretimeout; +unsigned int min_pretimeout; +unsigned int max_pretimeout;void *driver_data;struct mutex lock;unsigned long status;
@@ -117,7 +125,20 @@ static inline void watchdog_set_nowayout(struct watchdog_device *wdd, bool nowaystatic inline bool watchdog_timeout_invalid (struct watchdog_device *wdd,unsigned int t) {return ((wdd->max_timeout !=0 ) && - (t < wdd->min_timeout || t > wdd->max_timeout)); + (t < wdd->min_timeout || t > wdd->max_timeout || + t <= wdd->pretimeout)); +} + +/* +* Use the following function to check if a pretimeout value is invalid. +* It can be "0", that means we don't use pretimeout. +*/ +static inline bool watchdog_pretimeout_invalid (struct watchdog_device *wdd, +unsigned int t) +{ +return (wdd->pretimeout !=0 && wdd->max_pretimeout !=0 && + (t < wdd->min_pretimeout || t > wdd->max_pretimeout || + (wdd->timeout !=0 && t >= wdd->timeout))); }/* Use the following functions to manipulate watchdog driver specific data */
@@ -132,11 +153,20 @@ static inline void *watchdog_get_drvdata(struct watchdog_device *wdd) }/* drivers/watchdog/watchdog_core.c */ -extern int watchdog_init_timeout (struct watchdog_device *wdd, -unsigned int timeout_parm,struct device *dev); +int watchdog_init_timeouts (struct watchdog_device *wdd, +unsigned int pretimeout_parm, +unsigned int timeout_parm, +struct device *dev);extern int watchdog_register_device (struct watchdog_device *);extern void watchdog_unregister_device (struct watchdog_device *); +static inline int watchdog_init_timeout (struct watchdog_device *wdd, +unsigned int timeout_parm, +struct device *dev) +{ +return watchdog_init_timeouts (wdd,0 , timeout_parm, dev); +} +#ifdef CONFIG_HARDLOCKUP_DETECTOR void watchdog_nmi_disable_all (void );void watchdog_nmi_enable_all (void );
Signature · 1 line
1.9.1
PATCH v5 5/8 Watchdog: introduce ARM SBSA watchdog driver
In reply to [email protected]From: Fu Wei <[email protected]>
This driver bases on linux kernel watchdog framework, and use "pretimeout" in the framework. It supports getting timeout and pretimeout from parameter and FDT at the driver init stage. In first timeout, the interrupt routine run panic to save system context.
--- drivers/watchdog/Kconfig | 11 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/sbsa_gwdt.c | 409 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 421 insertions(+) create mode 100644 drivers/watchdog/sbsa_gwdt.c
drivers/watchdog/Kconfig +11 -0
@@ -152,6 +152,17 @@ config ARM_SP805_WATCHDOG ARM Primecell SP805 Watchdog timer. This will reboot your system when the timeout is reached. +config ARM_SBSA_WATCHDOG + tristate "ARM SBSA Generic Watchdog" + depends on ARM64 + depends on ARM_ARCH_TIMER + select WATCHDOG_CORE + help + ARM SBSA Generic Watchdog. This watchdog has two Watchdog timeouts. + The first timeout will trigger a panic; the second timeout will + trigger a system reset. + More details: ARM DEN0029B - Server Base System Architecture (SBSA) + config AT91RM9200_WATCHDOG tristate "AT91RM9200 watchdog" depends on SOC_AT91RM9200 && MFD_SYSCON
drivers/watchdog/Makefile +1 -0
@@ -30,6 +30,7 @@ obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o # ARM Architecture obj-$(CONFIG_ARM_SP805_WATCHDOG) += sp805_wdt.o +obj-$(CONFIG_ARM_SBSA_WATCHDOG) += sbsa_gwdt.o obj-$(CONFIG_AT91RM9200_WATCHDOG) += at91rm9200_wdt.o obj-$(CONFIG_AT91SAM9X_WATCHDOG) += at91sam9_wdt.o obj-$(CONFIG_CADENCE_WATCHDOG) += cadence_wdt.o
drivers/watchdog/sbsa_gwdt.c new file +409 -0
409 lines not on this page · raw message
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v5 6/8 ACPI: add GTDT table parse driver into ACPI driver
In reply to [email protected]From: Fu Wei <[email protected]>
This driver adds support for parsing SBSA Generic Watchdog Structure in GTDT, and creating a platform device with that information. This allows the operating system to obtain device data from the resource of platform device.
The platform device named "sbsa-gwdt" can be used by the ARM SBSA Generic Watchdog driver.
--- drivers/acpi/Kconfig | 9 ++++ drivers/acpi/Makefile | 1 + drivers/acpi/gtdt.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 drivers/acpi/gtdt.c
drivers/acpi/Kconfig +9 -0
@@ -433,4 +433,13 @@ config XPOWER_PMIC_OPREGION endif +config ACPI_GTDT + bool "ACPI GTDT Support" + depends on ARM64 + help + GTDT (Generic Timer Description Table) provides information + for per-processor timers and Platform (memory-mapped) timers + for ARM platforms. Select this option to provide information + needed for the timers init. + endif # ACPI
drivers/acpi/Makefile +1 -0
@@ -96,3 +96,4 @@ obj-$(CONFIG_ACPI_EXTLOG) += acpi_extlog.o obj-$(CONFIG_PMIC_OPREGION) += pmic/intel_pmic.o obj-$(CONFIG_CRC_PMIC_OPREGION) += pmic/intel_pmic_crc.o obj-$(CONFIG_XPOWER_PMIC_OPREGION) += pmic/intel_pmic_xpower.o +obj-$(CONFIG_ACPI_GTDT) += gtdt.o
drivers/acpi/gtdt.c new file +137 -0
137 lines not on this page · raw message
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v5 7/8 Watchdog: enable ACPI GTDT support for ARM SBSA watchdog driver
In reply to [email protected]From: Fu Wei <[email protected]>
This patch enables ACPI GTDT support for ARM SBSA watchdog driver automatically, if ACPI support is enabled.
--- drivers/watchdog/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/watchdog/Kconfig +1 -0
@@ -157,6 +157,7 @@ config ARM_SBSA_WATCHDOG depends on ARM64 depends on ARM_ARCH_TIMER select WATCHDOG_CORE + select ACPI_GTDT if ACPI help ARM SBSA Generic Watchdog. This watchdog has two Watchdog timeouts. The first timeout will trigger a panic; the second timeout will
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v5 8/8 clocksource: simplify ACPI code in arm_arch_timer.c
In reply to [email protected]From: Fu Wei <[email protected]>
The patch update arm_arch_timer driver to use the function provided by the new GTDT driver of ACPI.
By this way, arm_arch_timer.c can be simplified, and separate all the ACPI GTDT knowledge from this timer driver.
--- arch/arm64/kernel/time.c | 4 +-- drivers/acpi/gtdt.c | 43 ++++++++++++++++++++++++++ drivers/clocksource/Kconfig | 1 + drivers/clocksource/arm_arch_timer.c | 60 +++++++----------------------------- include/clocksource/arm_arch_timer.h | 8 +++++ include/linux/acpi.h | 5 +++ include/linux/clocksource.h | 4 +-- 7 files changed, 72 insertions(+), 53 deletions(-)
arch/arm64/kernel/time.c +2 -2
@@ -75,9 +75,9 @@ void __init time_init(void)/* * Since ACPI or FDT will only one be available in the system, -* we can use acpi_generic_timer_init() here safely +* we can use arch_timer_acpi_init() here safely */ -acpi_generic_timer_init (); +arch_timer_acpi_init (); arch_timer_rate =arch_timer_get_rate ();if (!arch_timer_rate)
drivers/acpi/gtdt.c +43 -0
55 lines not on this page · raw message
drivers/clocksource/Kconfig +1 -0
@@ -109,6 +109,7 @@ config CLKSRC_EFM32 config ARM_ARCH_TIMER bool select CLKSRC_OF if OF + select ACPI_GTDT if ACPI config ARM_ARCH_TIMER_EVTSTREAM bool "Support for ARM architected timer event stream generation"
drivers/clocksource/arm_arch_timer.c +11 -49
79 lines not on this page · raw message
include/clocksource/arm_arch_timer.h +8 -0
@@ -43,6 +43,14 @@ enum arch_timer_reg {#define ARCH_TIMER_EVT_STREAM_FREQ 10000/* 100us */ +struct arch_timer_data { +int phys_secure_ppi; +int phys_nonsecure_ppi; +int virt_ppi; +int hyp_ppi; +bool c3stop; +}; +#ifdef CONFIG_ARM_ARCH_TIMER extern u32 arch_timer_get_rate (void );
include/linux/acpi.h +5 -0
@@ -458,6 +458,11 @@ void acpi_walk_dep_device_list(acpi_handle handle);struct platform_device *acpi_create_platform_device (struct acpi_device *);#define ACPI_PTR (_ptr) (_ptr) +#ifdef CONFIG_ACPI_GTDT +struct arch_timer_data ; +int __init gtdt_arch_timer_data_init (struct arch_timer_data *data); +#endif +#else /* !CONFIG_ACPI */ #define acpi_disabled 1
include/linux/clocksource.h +2 -2
@@ -254,9 +254,9 @@ static inline void clocksource_of_init(void) {}#endif #ifdef CONFIG_ACPI -void acpi_generic_timer_init (void ); +void arch_timer_acpi_init (void );#else -static inline void acpi_generic_timer_init (void ) { } +static inline void arch_timer_acpi_init (void ) { }#endif #endif /* _LINUX_CLOCKSOURCE_H */
Signature · 1 line
1.9.1
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
In reply to Fu WeiQuoted 6 lines · Fu Wei
Another weakness of only using WOR is the timeout limited by this 32bit register.
10s @400MHz generic TimerI don't think this limit is good for a server, once the server is in a heavy load
Perhaps, but if that's the limitation of the hardware, then so be it.
Signature · 7 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation. -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
Quoted 11 lines · Timur Tabi
Quoted 7 lines · Fu Wei
Another weakness of only using WOR is the timeout limited by this 32bit register.
10s @400MHz generic TimerI don't think this limit is good for a server, once the server is in a heavy load
Perhaps, but if that's the limitation of the hardware, then so be it.
it is not the real limitation, if we use WCV, SBSA spec has mentioned that.
------ SBSA 2.3-------Page 23 ----------
Note: the watchdog offset register is 32 bits wide. This gives a maximum watch period of around 10s at a system
counter frequency of 400MHz. If a larger watch period is required then the compare value can be programmed
directly into the compare value register
------ SBSA 2.3-------Page 23 ----------
if some hardware doesn't support writing WCV, that means this hardware is non-standard SBSA watchdog.
Quoted 5 lines
--
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.
Signature · 14 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
Quoted 15 lines · Fu Wei
Quoted 11 lines · Timur Tabi
Quoted 7 lines · Fu Wei
Another weakness of only using WOR is the timeout limited by this 32bit register.
10s @400MHz generic TimerI don't think this limit is good for a server, once the server is in a heavy load
Perhaps, but if that's the limitation of the hardware, then so be it.
it is not the real limitation, if we use WCV, SBSA spec has mentioned that.
Quoted 7 lines
------ SBSA 2.3-------Page 23 ----------
Note: the watchdog offset register is 32 bits wide. This gives a maximum watch period of around 10s at a system
counter frequency of 400MHz. If a larger watch period is required then the compare value can be programmed
directly into the compare value register
------ SBSA 2.3-------Page 23 ----------
------ SBSA 2.3-------Page 24 ---------- 0x010 – 0x013 WCV[31:0]0x014 – 0x017 WCV[63:32]
Watchdog compare value.
*Read/Write* registers
containing the current value in the watchdog compare register.
------ SBSA 2.3-------Page 24 ----------
Quoted 23 lines
if some hardware doesn't support writing WCV, that means this hardware is non-standard SBSA watchdog.
Quoted 5 lines
--
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.--
Best regards,Fu Wei
Software Engineer
Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch
Ph: +86 21 61221326(direct)
Ph: +86 186 2020 4684 (mobile)
Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021
Signature · 14 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
In reply to Fu WeiHi Guenter,
Quoted 43 lines · Fu Wei
Hi Guenter,
Quoted 17 lines · Guenter Roeck
Quoted 16 lines · Timur Tabi
Quoted 12 lines · Guenter Roeck
but I see your point. Essentially, the specification is broken for all practical purposes, since, as you point out, enabling the watchdog overwrites and explicitly sets WCV. Effectively this means that just using WCV to program the timeout period is not really possible.
I am not really sure how to address this. We can either only use WOR, and forget about pretimeout, or we can enforce a minimum pretimeout. In the latter case, we'll have to write WCV after writing WOR.
Quoted 8 lines
Quoted 5 lines
In talking with our hardware engineers, using WCV to program the timeout period is not a valid operation. This is why I keep arguing against the pre-timeout feature, and I don't agree that servers should always use pre-timeout.
Not sure if "not valid" is correct - after all, it is mentioned in the specification. However, it is at the very least fragile.
I think we should focus on SBSA spec, but not a specific chip design, because this is SBSA watchdog, not a driver for an IP core from a specific chip vendor.
this operation is mentioned in the spec,
and I have tested my driver on Foundation model(from ARM) and a real hardware.Quoted 4 lines
I tend to agree that we should just forget about pretimeout and use your original approach, where the timeout value is used to program WOR. Everything else is really just asking for trouble.
I don't mind if we give up pretimeout, The reason I use pretimeout is:
this concept matches the function of two stage timeouts.
Quoted 8 lines
but, If we give up pretimeout, could you give me a suggestion:
How to config the two stage timeouts
(1)from enabling watchdog to WS0
(2)the time from WS1 to WS0If we only have one timeout parameter, How to config the two stage timeouts? Any suggestion ?
I have another thought for this, please allow me to sent anther patchset in a day. see if you like it.
Quoted 24 lines
If we make the first stage timeout is timeout/2, this violates the definition of timeout.
I don't think users expect interrupt, panic or reboot at timeout/2.And WS1 definitely isn't a backup of WS0.
Quoted 3 lines
Guenter
--
Best regards,Fu Wei
Software Engineer
Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch
Ph: +86 21 61221326(direct)
Ph: +86 186 2020 4684 (mobile)
Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021
Signature · 14 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Guenter Roeck
maintainerRe: [PATCH v5 4/8] Watchdog: introdouce "pretimeout" into framework
In reply to [email protected]Quoted 75 lines · On 06/10/2015 06:41 AM, [email protected] wrote:
From: Fu Wei <[email protected]>
Also update
Documentation/watchdog/watchdog-kernel-api.txtto introduce:
(1)the new elements in thewatchdog_deviceandwatchdog_opsstruct; (2)the new API "watchdog_init_timeouts"Reasons:
(1)kernel already has two watchdog drivers are using "pretimeout":
drivers/char/ipmi/ipmi_watchdog.cdrivers/watchdog/kempld_wdt.c(but the definition is different)
(2)some other drivers are going to use this: ARM SBSA Generic WatchdogSigned-off-by Fu Wei <[email protected]>--- Documentation/watchdog/watchdog-kernel-api.txt | 47 ++++++++++-- drivers/watchdog/watchdog_core.c | 100 +++++++++++++++++-------- drivers/watchdog/watchdog_dev.c | 53 +++++++++++++ include/linux/watchdog.h | 36 ++++++++- 4 files changed, 197 insertions(+), 39 deletions(-)Documentation/watchdog/watchdog-kernel-api.txt +18
-1@@ -49,6 +49,9 @@ struct watchdog_device { unsigned int timeout; unsigned int min_timeout; unsigned int max_timeout; + unsigned int pretimeout; + unsigned int min_pretimeout; + unsigned int max_pretimeout; void *driver_data; struct mutex lock; unsigned long status;@@ -70,6 +73,9 @@ It contains following fields: * timeout: the watchdog timer's timeout value (in seconds). * min_timeout: the watchdog timer's minimum timeout value (in seconds). * max_timeout: the watchdog timer's maximum timeout value (in seconds). +* pretimeout: the watchdog timer's pretimeout value (in seconds). +* min_pretimeout: the watchdog timer's minimum pretimeout value (in seconds). +* max_pretimeout: the watchdog timer's maximum pretimeout value (in seconds). * bootstatus: status of the device after booting (reported with watchdog WDIOF_* status bits). * driver_data: a pointer to the drivers private data of a watchdog device.@@ -92,6 +98,7 @@ struct watchdog_ops { int (*ping)(struct watchdog_device *); unsigned int (*status)(struct watchdog_device *); int (*set_timeout)(struct watchdog_device *, unsigned int); + int (*set_pretimeout)(struct watchdog_device *, unsigned int); unsigned int (*get_timeleft)(struct watchdog_device *); void (*ref)(struct watchdog_device *); void (*unref)(struct watchdog_device *);@@ -153,9 +160,19 @@ they are supported. These optional routines/operations are: and -EIO for "could not write value to the watchdog". On success this routine should set the timeout value of the watchdog_device to the achieved timeout value (which may be different from the requested one - because the watchdog does not necessarily has a 1 second resolution). + because the watchdog does not necessarily has a 1 second resolution; + If the driver supports pretimeout, then the timeout value must be greater + than that). (Note: the WDIOF_SETTIMEOUT needs to be set in the options field of the watchdog's info structure). +* set_pretimeout: this routine checks and changes the pretimeout of the + watchdog timer device. It returns 0 on success, -EINVAL for "parameter out of + range" and -EIO for "could not write value to the watchdog". On success this + routine should set the pretimeout value of the watchdog_device to the + achieved pretimeout value (which may be different from the requested one + because the watchdog does not necessarily has a 1 second resolution). + (Note: the WDIOF_PRETIMEOUT needs to be set in the options field of the + watchdog's info structure). * get_timeleft: this routines returns the time that's left before a reset. * ref: the operation that calls kref_get on the kref of a dynamically allocated watchdog_device struct.
Documentation/watchdog/watchdog-kernel-api.txt extern int watchdog_init_timeout(struct watchdog_device *wdd, · line 240
Quoted 9 lines
Documentation/watchdog/watchdog-kernel-api.txt +2
-4@@ -219,8 +236,28 @@ extern int watchdog_init_timeout(struct watchdog_device *wdd, unsigned int timeout_parm, struct device *dev); The watchdog_init_timeout function allows you to initialize the timeout field -using the module timeout parameter or by retrieving the timeout-sec property from -the device tree (if the module timeout parameter is invalid). Best practice is -to set the default timeout value as timeout value in the watchdog_device and -then use this function to set the user "preferred" timeout value. +using the module timeout parameter or by retrieving the first element of +the timeout-sec property from the device tree (if the module timeout parameter
Missing space before (.
Quoted 9 lines
Documentation/watchdog/watchdog-kernel-api.txt +9
-0+is invalid). Best practice is to set the default timeout value as timeout value +in the watchdog_device and then use this function to set the user "preferred" +timeout value. +This routine returns zero on success and a negative errno code for failure. + +Some watchdog timers have two stage of timeouts(timeout and pretimeout), +to initialize the timeout and pretimeout fields at the same time, the following +function can be used: +
Documentation/watchdog/watchdog-kernel-api.txt extern int watchdog_init_timeout(struct watchdog_device *wdd, · line 259
Quoted 10 lines
Documentation/watchdog/watchdog-kernel-api.txt +10
-0+extern int watchdog_init_timeouts(struct watchdog_device *wdd, + unsigned int pretimeout_parm, + unsigned int timeout_parm, + struct device *dev); + +The watchdog_init_timeouts function allows you to initialize the pretimeout and +timeout fields using the module pretimeout and timeout parameter or by +retrieving the elements in the timeout-sec property(the first element is for +timeout, the second one is for pretimeout) from the device tree(if the module +pretimeout and timeout parameter are invalid).
Missing spaces before (.
Quoted 9 lines
Documentation/watchdog/watchdog-kernel-api.txt +3
-0+Best practice is to set the default pretimeout and timeout value as pretimeout +and timeout value in the watchdog_device and then use this function to set the +user "preferred" pretimeout value. This routine returns zero on success and a negative errno code for failure.drivers/watchdog/watchdog_core.c +0
-0
drivers/watchdog/watchdog_core.c line 46
Quoted 5 lines
drivers/watchdog/watchdog_core.c +1
-1@@ -43,60 +43,98 @@static DEFINE_IDA (watchdog_ida);static struct class *watchdog_class; -static void watchdog_check_min_max_timeout (struct watchdog_device *wdd) +static void watchdog_check_min_max_timeouts (struct watchdog_device *wdd)
Please don't rename this function. This avoids conflicts with other pending patches.
Quoted 4 lines
drivers/watchdog/watchdog_core.c +0
-2{/* -* Check that we have valid min and max timeout values, if -* not reset them both to 0 (=not used or unknown)
drivers/watchdog/watchdog_core.c line 56
Quoted 10 lines
drivers/watchdog/watchdog_core.c +7
-2+* Check that we have valid min and max pretimeout and timeout values, +* if not, reset them all to 0 (=not used or unknown) */ -if (wdd->min_timeout > wdd->max_timeout) { -pr_info ("Invalid min and max timeout values, resetting to 0!\n" ); +if (wdd->min_pretimeout > wdd->max_pretimeout || + wdd->min_timeout > wdd->max_timeout || + wdd->min_timeout < wdd->min_pretimeout || + wdd->max_timeout < wdd->max_pretimeout) { +pr_info ("Invalid min and max timeouts, resetting to 0\n" );
timeouts or pretimeouts.
Quoted 47 lines
drivers/watchdog/watchdog_core.c +17
-15+ wdd->min_pretimeout =0 ; + wdd->max_pretimeout =0 ; wdd->min_timeout =0 ; wdd->max_timeout =0 ; } }/** -* watchdog_init_timeout() - initialize the timeout field +* watchdog_init_timeouts() - initialize the pretimeout and timeout field +* @pretimeout_parm: pretimeout module parameter * @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 -* 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 -* be the default timeout value. +* Initialize the pretimeout and timeout field of the watchdog_device struct +* with either the pretimeout and timeout module parameter (if it is valid) or +* the timeout-sec property (only if it is valid and the pretimeout_parm or +* timeout_parm is out of bounds). If none of them is valid, then we keep +* the old value (which should normally be the default timeout value). * * A zero is returned on success and -EINVAL for failure. */ -int watchdog_init_timeout (struct watchdog_device *wdd, -unsigned int timeout_parm,struct device *dev) +int watchdog_init_timeouts (struct watchdog_device *wdd, +unsigned int pretimeout_parm, +unsigned int timeout_parm, +struct device *dev) { -unsigned int t =0 ; -int ret =0 ; +int ret =0 , length =0 ; +u32 timeouts[2 ] = {0 }; +struct property *prop; -watchdog_check_min_max_timeout (wdd); +watchdog_check_min_max_timeouts (wdd); -/* try to get the timeout module parameter first */ -if (!watchdog_timeout_invalid (wdd, timeout_parm) && timeout_parm) { - wdd->timeout = timeout_parm; -return ret;
drivers/watchdog/watchdog_core.c line 96
Quoted 10 lines
drivers/watchdog/watchdog_core.c +8
-2- } -if (timeout_parm) +/* +* Try to get the pretimeout module parameter first +*/ +if (!watchdog_pretimeout_invalid (wdd, pretimeout_parm)) + timeouts[1 ] = pretimeout_parm; +else + ret = -EINVAL ;/* pretimeout_parm is invalid */ +
If I understand the code correctly, this permits for pretimeout being specified as module parameter and timeout as devicetree property. I don't think this is a good idea. Use either one or the other, but not both. So this can be simplified to
if (watchdog_pretimeout_invalid(wdd, pretimeout_parm) ret = _EINVAL;
if you use pretimeout directly below.
drivers/watchdog/watchdog_core.c line 102
Quoted 6 lines
drivers/watchdog/watchdog_core.c +6
-0+/* +* Try to get the timeout module parameter, +* if it's valid and pretimeout is valid(ret == 0), +* assignment and return zero. Otherwise, try dtb. +*/ +if (timeout_parm) {
You can use
if (timeout_parm && !ret) {drivers/watchdog/watchdog_core.c line 103
Quoted 1 line
drivers/watchdog/watchdog_core.c +1
-0+if (!watchdog_timeout_invalid (wdd, timeout_parm) && !ret) {
instead of checking ret here.
drivers/watchdog/watchdog_core.c line 105
Quoted 2 lines
drivers/watchdog/watchdog_core.c +2
-0+ wdd->timeout = timeout_parm; + wdd->pretimeout = timeouts[1 ];
This is really pretimeout_parm here, which should be used. Then you don't need timeouts[1].
drivers/watchdog/watchdog_core.c line 110
Quoted 5 lines
drivers/watchdog/watchdog_core.c +3
-0+return 0 ; + } ret = -EINVAL ; + }
Unfortunately this does not set wdd->pretimeout if pretimeout_parm is set but timeout_parm isn't. So I think you need
} else if (pretimeout_parm && !ret) {
wdd->pretimeout = pretimeout;
return 0;
}However, that actually won't work as we may try to set both timeout and pretimeout, but the current checks validate against the previous values. I'll need to think about that.
Also, this is getting a bit complicated. Wonder if the code can be simplified. Something else to think about.
Quoted 17 lines
drivers/watchdog/watchdog_core.c +7
-7-/* try to get the timeout_sec property */ +/* +* Either at least one of the module parameters is invalid, +* or timeout_parm is 0. Try to get the timeout_sec property. +*/ if (dev ==NULL || dev->of_node ==NULL )return ret; -of_property_read_u32 (dev->of_node,"timeout-sec" , &t); -if (!watchdog_timeout_invalid (wdd, t) && t) - wdd->timeout = t; -else - ret = -EINVAL ; -return ret; + prop =of_find_property (dev->of_node,"timeout-sec" , &length); +if (prop && length >0 && length <=sizeof (u32) *2 ) { + of_property_read_u32_array(dev->of_node,
drivers/watchdog/watchdog_core.c line 130
Quoted 10 lines
drivers/watchdog/watchdog_core.c +10
-0+"timeout-sec" , timeouts, + length / sizeof(u32)); +if (length ==sizeof (u32) *2 && +watchdog_pretimeout_invalid (wdd, timeouts[1 ])) +return -EINVAL ; + +if (!watchdog_timeout_invalid (wdd, timeouts[0 ]) && + timeouts[0 ]) { + wdd->timeout = timeouts[0 ]; + wdd->pretimeout = timeouts[1 ];
Please only set pretimeout here if specified in devicetree.
Quoted 132 lines
drivers/watchdog/watchdog_core.c +7
-2+return 0 ; + } + } + +return -EINVAL ; } -EXPORT_SYMBOL_GPL (watchdog_init_timeout); +EXPORT_SYMBOL_GPL (watchdog_init_timeouts);/** * watchdog_register_device() - register a watchdog device @@ -119,7 +157,7 @@ int watchdog_register_device(struct watchdog_device *wdd)if (wdd->ops->start ==NULL || wdd->ops->stop ==NULL )return -EINVAL ; -watchdog_check_min_max_timeout (wdd); +watchdog_check_min_max_timeouts (wdd);/* * Note: now that all watchdog_device data has been verified, we drivers/watchdog/watchdog_dev.c +53
-0@@ -218,6 +218,38 @@ out_timeout: }/* +* watchdog_set_pretimeout: set the watchdog timer pretimeout +* @wddev: the watchdog device to set the timeout for +* @pretimeout: pretimeout to set in seconds +*/ + +static int watchdog_set_pretimeout (struct watchdog_device *wddev, +unsigned int pretimeout) +{ +int err; + +if (!wddev->ops->set_pretimeout || + !(wddev->info->options &WDIOF_PRETIMEOUT )) +return -EOPNOTSUPP ; + +if (watchdog_pretimeout_invalid (wddev, pretimeout)) +return -EINVAL ; + +mutex_lock (&wddev->lock); + +if (test_bit (WDOG_UNREGISTERED , &wddev->status)) { + err = -ENODEV ; + goto out_pretimeout; + } + + err = wddev->ops->set_pretimeout (wddev, pretimeout); + +out_pretimeout: +mutex_unlock (&wddev->lock); +return err; +} + +/* * watchdog_get_timeleft: wrapper to get the time left before a reboot * @wddev: the watchdog device to get the remaining time from * @timeleft: the time that's left @@ -388,6 +420,27 @@ static long watchdog_ioctl(struct file *file, unsigned int cmd,if (wdd->timeout ==0 )return -EOPNOTSUPP ;return put_user (wdd->timeout, p); +case WDIOC_SETPRETIMEOUT : +/* check if we support the pretimeout */ +if (!(wdd->info->options &WDIOF_PRETIMEOUT )) +return -EOPNOTSUPP ; +if (get_user (val, p)) +return -EFAULT ; + err =watchdog_set_pretimeout (wdd, val); +if (err <0 ) +return err; +/* +* If the watchdog is active then we send a keepalive ping +* to make sure that the watchdog keeps running (and if +* possible that it takes the new pretimeout) +*/ +watchdog_ping (wdd); +/* Fall */ +case WDIOC_GETPRETIMEOUT : +/* check if we support the pretimeout */ +if (wdd->info->options &WDIOF_PRETIMEOUT ) +return put_user (wdd->pretimeout, p); +return -EOPNOTSUPP ;case WDIOC_GETTIMELEFT : err =watchdog_get_timeleft (wdd, &val);if (err)include/linux/watchdog.h +8
-0@@ -25,6 +25,7 @@ struct watchdog_device;* @ping: The routine that sends a keepalive ping to the watchdog device. * @status: The routine that shows the status of the watchdog device. * @set_timeout:The routine for setting the watchdog devices timeout value. +* @set_pretimeout:The routine for setting the watchdog devices pretimeout value * @get_timeleft:The routine that get's the time that's left before a reset. * @ref: The ref operation for dyn. allocated watchdog_device structs * @unref: The unref operation for dyn. allocated watchdog_device structs @@ -44,6 +45,7 @@ struct watchdog_ops {int (*ping)(struct watchdog_device *);unsigned int (*status)(struct watchdog_device *);int (*set_timeout)(struct watchdog_device *,unsigned int ); +int (*set_pretimeout)(struct watchdog_device *,unsigned int );unsigned int (*get_timeleft)(struct watchdog_device *);void (*ref)(struct watchdog_device *);void (*unref)(struct watchdog_device *);@@ -62,6 +64,9 @@ struct watchdog_ops {* @timeout: The watchdog devices timeout value. * @min_timeout:The watchdog devices minimum timeout value. * @max_timeout:The watchdog devices maximum timeout value. +* @pretimeout: The watchdog devices pretimeout value. +* @min_pretimeout:The watchdog devices minimum pretimeout value. +* @max_pretimeout:The watchdog devices maximum pretimeout value. * @driver-data:Pointer to the drivers private data. * @lock: Lock for watchdog core internal use only. * @status: Field that contains the devices internal status bits. @@ -86,6 +91,9 @@ struct watchdog_device {unsigned int timeout;unsigned int min_timeout;unsigned int max_timeout; +unsigned int pretimeout; +unsigned int min_pretimeout; +unsigned int max_pretimeout;void *driver_data;struct mutex lock;unsigned long status;
include/linux/watchdog.h static inline void watchdog_set_nowayout(struct watchdog_device *wdd, bool noway · line 129
Quoted 6 lines
include/linux/watchdog.h +2
-1@@ -117,7 +125,20 @@ static inline void watchdog_set_nowayout(struct watchdog_device *wdd, bool nowaystatic inline bool watchdog_timeout_invalid (struct watchdog_device *wdd,unsigned int t) {return ((wdd->max_timeout !=0 ) && - (t < wdd->min_timeout || t > wdd->max_timeout)); + (t < wdd->min_timeout || t > wdd->max_timeout || + t <= wdd->pretimeout));
pretimeout can be 0, and t needs to be evaluated against pretimeout even if max_timeout is 0.
Try
return (wdd->max_timeout && (t < wdd->min_timeout || t > wdd->max_timeout)) || (wdd->pretimeout && t <= wdd->pretimeout);
include/linux/watchdog.h static inline void watchdog_set_nowayout(struct watchdog_device *wdd, bool noway · line 141
Quoted 12 lines
include/linux/watchdog.h +12
-0+} + +/* +* Use the following function to check if a pretimeout value is invalid. +* It can be "0", that means we don't use pretimeout. +*/ +static inline bool watchdog_pretimeout_invalid (struct watchdog_device *wdd, +unsigned int t) +{ +return (wdd->pretimeout !=0 && wdd->max_pretimeout !=0 && + (t < wdd->min_pretimeout || t > wdd->max_pretimeout || + (wdd->timeout !=0 && t >= wdd->timeout)));
The check for wdd->pretimeout doesn't make much sense here, as this is the value we are trying to set. Effectively the above accepts every pretimeout if wdd->pretimeout is 0. It also accepts every pretimeout if max_pretimeout == 0, even if wdd->timeout is set and t >= wdd->timeout.
Try
return (wdd->max_pretimeout && (t < wdd->min_pretimeout || t > wdd->max_pretimeout)) || (wdd->timeout && t >= wdd->timeout);
include/linux/watchdog.h static inline void *watchdog_get_drvdata(struct watchdog_device *wdd) · line 159
Quoted 13 lines
include/linux/watchdog.h +4
-2}/* Use the following functions to manipulate watchdog driver specific data */ @@ -132,11 +153,20 @@ static inline void *watchdog_get_drvdata(struct watchdog_device *wdd) }/* drivers/watchdog/watchdog_core.c */ -extern int watchdog_init_timeout (struct watchdog_device *wdd, -unsigned int timeout_parm,struct device *dev); +int watchdog_init_timeouts (struct watchdog_device *wdd, +unsigned int pretimeout_parm, +unsigned int timeout_parm, +struct device *dev);
Please align continuation lines with '('.
Quoted 4 lines
include/linux/watchdog.h +0
-0extern int watchdog_register_device (struct watchdog_device *);extern void watchdog_unregister_device (struct watchdog_device *);
include/linux/watchdog.h static inline void *watchdog_get_drvdata(struct watchdog_device *wdd) · line 172
Quoted 10 lines
include/linux/watchdog.h +7
-0+static inline int watchdog_init_timeout (struct watchdog_device *wdd, +unsigned int timeout_parm, +struct device *dev) +{ +return watchdog_init_timeouts (wdd,0 , timeout_parm, dev); +} +#ifdef CONFIG_HARDLOCKUP_DETECTOR void watchdog_nmi_disable_all (void );void watchdog_nmi_enable_all (void );
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
cover Watchdog: introduce ARM SBSA watchdog driver
In reply to a message not in the archiveFrom: Fu Wei <[email protected]>
This patchset:
(1)Introduce Documentation/devicetree/bindings/watchdog/sbsa-gwdt.txt for FDT info of SBSA Generic Watchdog, and give two examples of adding SBSA Generic Watchdog device node into the dts files:
foundation-v8.dts and amd-seattle-soc.dtsi.
(2)Introduce ACPI GTDT parser: drivers/acpi/gtdt.c
Parse SBSA Generic Watchdog Structure in GTDT table of ACPI, and create a platform device with that information.
This platform device can be used by This Watchdog driver. drivers/clocksource/arm_arch_timer.c is simplified by this GTDT support.
(3)Introduce ARM SBSA watchdog driver:
a.Use linux kernel watchdog framework;
b.Work with FDT on ARM64;
c.In first timeout, do panic to save system context; d.Support getting timeout from parameter and FDT at the driver init stage.
This patchset has been tested with watchdog daemon (ACPI/FDT, module/build-in) on the following platforms:
(1)ARM Foundation v8 model
Changelog:non_pretimeout: Delete all pretimeout code
The time from enabling watchdog to WS0 is the same with the time from WS0 to WS1, they are both timeout value.
v5: Improve pretimeout support:
(1)fix typo in documentation and comments.
(2)fix the timeout limits validation bug.
Simplify sbsa_gwdt driver:
(1)integrate all the registers access functions into caller.
v4: Refactor GTDT support code: remove it from arch/arm64/kernel/acpi.c,
put it into drivers/acpi/gtdt.c file.
Integrate the GTDT code of drivers/clocksource/arm_arch_timer.c into
drivers/acpi/gtdt.c.
Improve pretimeout support, fix "pretimeout == 0" problem.
Simplify sbsa_gwdt driver:
(1)timeout/pretimeout limits setup;
(2)keepalive function;
(3)delete "clk == 0" check;
(4)delete WS0 status bit check in interrupt routine;
(5)sbsa_gwdt_set_wcv function.v3: Delete "export arch_timer_get_rate" patch.
Driver back to use arch_timer_get_cntfrq.
Improve watchdog_init_timeouts function and update relevant documentation. Improve watchdog_timeout_invalid and watchdog_pretimeout_invalid. Improve foundation-v8.dts: delete the unnecessary tag of device node. Remove "ARM64 || COMPILE_TEST" from Kconfig.
Add comments in arch/arm64/kernel/acpi.c
Fix typoes and incorrect comments.
v2: Improve watchdog-kernel-api.txt documentation for pretimeout support.
Export "arch_timer_get_rate" in arm_arch_timer.c.
Add watchdog_init_timeouts API for pretimeout support in framework. Improve suspend and resume foundation in driver
Improve timeout/pretimeout values init code in driver. Delete unnecessary items of the sbsa_gwdt struct and #define. Delete all unnecessary debug info in driver.
Fix 64bit division bug.
Use the arch_timer interface to get watchdog clock rate. Add MODULE_DEVICE_TABLE for platform device id.
Fix typoes.
v1: The first version upstream patchset to linux mailing list.
Fu Wei (7):
Documentation: add sbsa-gwdt.txt documentation
ARM64: add SBSA Generic Watchdog device node in foundation-v8.dts
ARM64: add SBSA Generic Watchdog device node in amd-seattle-soc.dtsi
Watchdog: introduce ARM SBSA watchdog driver
ACPI: add GTDT table parse driver into ACPI driver
Watchdog: enable ACPI GTDT support for ARM SBSA watchdog driver
clocksource: simplify ACPI code in arm_arch_timer.c
.../devicetree/bindings/watchdog/sbsa-gwdt.txt | 35 ++ arch/arm64/boot/dts/amd/amd-seattle-soc.dtsi | 11 + arch/arm64/boot/dts/arm/foundation-v8.dts | 10 + arch/arm64/kernel/time.c | 4 +- drivers/acpi/Kconfig | 9 + drivers/acpi/Makefile | 1 + drivers/acpi/gtdt.c | 180 ++++++++++ drivers/clocksource/Kconfig | 1 + drivers/clocksource/arm_arch_timer.c | 60 +--- drivers/watchdog/Kconfig | 12 + drivers/watchdog/Makefile | 1 + drivers/watchdog/sbsa_gwdt.c | 383 +++++++++++++++++++++ include/clocksource/arm_arch_timer.h | 8 + include/linux/acpi.h | 5 + include/linux/clocksource.h | 4 +- 15 files changed, 671 insertions(+), 53 deletions(-) create mode 100644 Documentation/devicetree/bindings/watchdog/sbsa-gwdt.txt create mode 100644 drivers/acpi/gtdt.c create mode 100644 drivers/watchdog/sbsa_gwdt.c
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/7 Documentation: add sbsa-gwdt.txt documentation
From: Fu Wei <[email protected]>
The sbsa-gwdt.txt documentation in devicetree/bindings/watchdog is for introducing SBSA(Server Base System Architecture) Generic Watchdog device node info into FDT.
--- .../devicetree/bindings/watchdog/sbsa-gwdt.txt | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/sbsa-gwdt.txt
Documentation/devicetree/bindings/watchdog/sbsa-gwdt.txt new file +35 -0
@@ -0,0 +1,35 @@ +* SBSA(Server Base System Architecture) Generic Watchdog + +The SBSA Generic Watchdog Timer is used for resetting the system after +two stages of timeout. +More details: ARM-DEN-0029 - Server Base System Architecture (SBSA) + +Required properties: +- compatible : Should at least contain "arm,sbsa-gwdt". + +- reg : base physical address of the frames and length of memory mapped region. + +- reg-names : Should contain the resource reg names to show the order of + the values in "reg". + Must include the following entries : "refresh", "control". + +- interrupts : Should at least contain WS0 interrupt, + the WS1 Signal is optional. + +- interrupt-names : Should contain the resource interrupt names. + Must include the following entries : "ws0". "ws1" is optional. + +Optional properties +- timeout-sec : Watchdog timeout value (in seconds). + +Example for FVP Foundation Model v8: + +watchdog@2a440000 { + compatible = "arm,sbsa-gwdt"; + reg = <0x0 0x2a440000 0 0x10000>, + <0x0 0x2a450000 0 0x10000>; + reg-names = "control", "refresh"; + interrupts = <0 27 4>; + interrupt-names = "ws0"; + timeout-sec = <10>; +};
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/7 ARM64: add SBSA Generic Watchdog device node in foundation-v8.dts
In reply to [email protected]From: Fu Wei <[email protected]>
This can be a example of adding SBSA Generic Watchdog device node into some dts files for the Soc which contains SBSA Generic Watchdog.
--- arch/arm64/boot/dts/arm/foundation-v8.dts | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/arm64/boot/dts/arm/foundation-v8.dts +10 -0
@@ -237,4 +237,14 @@ }; }; }; + watchdog@2a440000 { + compatible = "arm,sbsa-gwdt"; + reg = <0x0 0x2a440000 0 0x10000>, + <0x0 0x2a450000 0 0x10000>; + reg-names = "control", + "refresh"; + interrupts = <0 27 4>; + interrupt-names = "ws0"; + timeout-sec = <10>; + }; };
Signature · 1 line
1.9.1
PATCH 3/7 ARM64: add SBSA Generic Watchdog device node in amd-seattle-soc.dtsi
In reply to [email protected]From: Fu Wei <[email protected]>
This can be a example of adding SBSA Generic Watchdog device node into some dts files for the Soc which contains SBSA Generic Watchdog.
--- arch/arm64/boot/dts/amd/amd-seattle-soc.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/arm64/boot/dts/amd/amd-seattle-soc.dtsi +11 -0
@@ -84,6 +84,17 @@ clock-names = "uartclk", "apb_pclk"; }; + watchdog0: watchdog@e0bb0000 { + compatible = "arm,sbsa-gwdt"; + reg = <0x0 0xe0bb0000 0 0x10000>, + <0x0 0xe0bc0000 0 0x10000>; + reg-names = "refresh", + "control"; + interrupts = <0 337 4>; + interrupt-names = "ws0"; + timeout-sec = <10>; + }; + spi0: ssp@e1020000 { status = "disabled"; compatible = "arm,pl022", "arm,primecell";
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 4/7 Watchdog: introduce ARM SBSA watchdog driver
In reply to [email protected]From: Fu Wei <[email protected]>
This driver bases on linux kernel watchdog framework. It supports getting timeout from parameter and FDT at the driver init stage.
The first timeout period expires, the interrupt routine got another timeout period to run panic for saving system context.
--- drivers/watchdog/Kconfig | 11 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/sbsa_gwdt.c | 383 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 395 insertions(+) create mode 100644 drivers/watchdog/sbsa_gwdt.c
drivers/watchdog/Kconfig +11 -0
@@ -152,6 +152,17 @@ config ARM_SP805_WATCHDOG ARM Primecell SP805 Watchdog timer. This will reboot your system when the timeout is reached. +config ARM_SBSA_WATCHDOG + tristate "ARM SBSA Generic Watchdog" + depends on ARM64 + depends on ARM_ARCH_TIMER + select WATCHDOG_CORE + help + ARM SBSA Generic Watchdog. This watchdog has two Watchdog timeouts. + The first timeout will trigger a panic; the second timeout will + trigger a system reset. + More details: ARM DEN0029B - Server Base System Architecture (SBSA) + config AT91RM9200_WATCHDOG tristate "AT91RM9200 watchdog" depends on SOC_AT91RM9200 && MFD_SYSCON
drivers/watchdog/Makefile +1 -0
@@ -30,6 +30,7 @@ obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o # ARM Architecture obj-$(CONFIG_ARM_SP805_WATCHDOG) += sp805_wdt.o +obj-$(CONFIG_ARM_SBSA_WATCHDOG) += sbsa_gwdt.o obj-$(CONFIG_AT91RM9200_WATCHDOG) += at91rm9200_wdt.o obj-$(CONFIG_AT91SAM9X_WATCHDOG) += at91sam9_wdt.o obj-$(CONFIG_CADENCE_WATCHDOG) += cadence_wdt.o
drivers/watchdog/sbsa_gwdt.c new file +383 -0
383 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH 5/7 ACPI: add GTDT table parse driver into ACPI driver
In reply to [email protected]From: Fu Wei <[email protected]>
This driver adds support for parsing SBSA Generic Watchdog Structure in GTDT, and creating a platform device with that information. This allows the operating system to obtain device data from the resource of platform device.
The platform device named "sbsa-gwdt" can be used by the ARM SBSA Generic Watchdog driver.
--- drivers/acpi/Kconfig | 9 ++++ drivers/acpi/Makefile | 1 + drivers/acpi/gtdt.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 drivers/acpi/gtdt.c
drivers/acpi/Kconfig +9 -0
@@ -433,4 +433,13 @@ config XPOWER_PMIC_OPREGION endif +config ACPI_GTDT + bool "ACPI GTDT Support" + depends on ARM64 + help + GTDT (Generic Timer Description Table) provides information + for per-processor timers and Platform (memory-mapped) timers + for ARM platforms. Select this option to provide information + needed for the timers init. + endif # ACPI
drivers/acpi/Makefile +1 -0
@@ -96,3 +96,4 @@ obj-$(CONFIG_ACPI_EXTLOG) += acpi_extlog.o obj-$(CONFIG_PMIC_OPREGION) += pmic/intel_pmic.o obj-$(CONFIG_CRC_PMIC_OPREGION) += pmic/intel_pmic_crc.o obj-$(CONFIG_XPOWER_PMIC_OPREGION) += pmic/intel_pmic_xpower.o +obj-$(CONFIG_ACPI_GTDT) += gtdt.o
drivers/acpi/gtdt.c new file +137 -0
137 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH 6/7 Watchdog: enable ACPI GTDT support for ARM SBSA watchdog driver
In reply to [email protected]From: Fu Wei <[email protected]>
This patch enables ACPI GTDT support for ARM SBSA watchdog driver automatically, if ACPI support is enabled.
--- drivers/watchdog/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/watchdog/Kconfig +1 -0
@@ -157,6 +157,7 @@ config ARM_SBSA_WATCHDOG depends on ARM64 depends on ARM_ARCH_TIMER select WATCHDOG_CORE + select ACPI_GTDT if ACPI help ARM SBSA Generic Watchdog. This watchdog has two Watchdog timeouts. The first timeout will trigger a panic; the second timeout will
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 7/7 clocksource: simplify ACPI code in arm_arch_timer.c
In reply to [email protected]From: Fu Wei <[email protected]>
The patch update arm_arch_timer driver to use the function provided by the new GTDT driver of ACPI.
By this way, arm_arch_timer.c can be simplified, and separate all the ACPI GTDT knowledge from this timer driver.
--- arch/arm64/kernel/time.c | 4 +-- drivers/acpi/gtdt.c | 43 ++++++++++++++++++++++++++ drivers/clocksource/Kconfig | 1 + drivers/clocksource/arm_arch_timer.c | 60 +++++++----------------------------- include/clocksource/arm_arch_timer.h | 8 +++++ include/linux/acpi.h | 5 +++ include/linux/clocksource.h | 4 +-- 7 files changed, 72 insertions(+), 53 deletions(-)
arch/arm64/kernel/time.c +2 -2
@@ -75,9 +75,9 @@ void __init time_init(void)/* * Since ACPI or FDT will only one be available in the system, -* we can use acpi_generic_timer_init() here safely +* we can use arch_timer_acpi_init() here safely */ -acpi_generic_timer_init (); +arch_timer_acpi_init (); arch_timer_rate =arch_timer_get_rate ();if (!arch_timer_rate)
drivers/acpi/gtdt.c +43 -0
55 lines not on this page · raw message
drivers/clocksource/Kconfig +1 -0
@@ -109,6 +109,7 @@ config CLKSRC_EFM32 config ARM_ARCH_TIMER bool select CLKSRC_OF if OF + select ACPI_GTDT if ACPI config ARM_ARCH_TIMER_EVTSTREAM bool "Support for ARM architected timer event stream generation"
drivers/clocksource/arm_arch_timer.c +11 -49
79 lines not on this page · raw message
include/clocksource/arm_arch_timer.h +8 -0
@@ -43,6 +43,14 @@ enum arch_timer_reg {#define ARCH_TIMER_EVT_STREAM_FREQ 10000/* 100us */ +struct arch_timer_data { +int phys_secure_ppi; +int phys_nonsecure_ppi; +int virt_ppi; +int hyp_ppi; +bool c3stop; +}; +#ifdef CONFIG_ARM_ARCH_TIMER extern u32 arch_timer_get_rate (void );
include/linux/acpi.h +5 -0
@@ -458,6 +458,11 @@ void acpi_walk_dep_device_list(acpi_handle handle);struct platform_device *acpi_create_platform_device (struct acpi_device *);#define ACPI_PTR (_ptr) (_ptr) +#ifdef CONFIG_ACPI_GTDT +struct arch_timer_data ; +int __init gtdt_arch_timer_data_init (struct arch_timer_data *data); +#endif +#else /* !CONFIG_ACPI */ #define acpi_disabled 1
include/linux/clocksource.h +2 -2
@@ -254,9 +254,9 @@ static inline void clocksource_of_init(void) {}#endif #ifdef CONFIG_ACPI -void acpi_generic_timer_init (void ); +void arch_timer_acpi_init (void );#else -static inline void acpi_generic_timer_init (void ) { } +static inline void arch_timer_acpi_init (void ) { }#endif #endif /* _LINUX_CLOCKSOURCE_H */
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
In reply to Fu WeiHi Guenter,
Quoted 53 lines · Fu Wei
Hi Guenter,
Quoted 49 lines · Fu Wei
Hi Guenter,
Quoted 17 lines · Guenter Roeck
Quoted 16 lines · Timur Tabi
Quoted 12 lines · Guenter Roeck
but I see your point. Essentially, the specification is broken for all practical purposes, since, as you point out, enabling the watchdog overwrites and explicitly sets WCV. Effectively this means that just using WCV to program the timeout period is not really possible.
I am not really sure how to address this. We can either only use WOR, and forget about pretimeout, or we can enforce a minimum pretimeout. In the latter case, we'll have to write WCV after writing WOR.
Quoted 8 lines
Quoted 5 lines
In talking with our hardware engineers, using WCV to program the timeout period is not a valid operation. This is why I keep arguing against the pre-timeout feature, and I don't agree that servers should always use pre-timeout.
Not sure if "not valid" is correct - after all, it is mentioned in the specification. However, it is at the very least fragile.
I think we should focus on SBSA spec, but not a specific chip design, because this is SBSA watchdog, not a driver for an IP core from a specific chip vendor.
this operation is mentioned in the spec,
and I have tested my driver on Foundation model(from ARM) and a real hardware.Quoted 4 lines
I tend to agree that we should just forget about pretimeout and use your original approach, where the timeout value is used to program WOR. Everything else is really just asking for trouble.
I don't mind if we give up pretimeout, The reason I use pretimeout is:
this concept matches the function of two stage timeouts.but, If we give up pretimeout, could you give me a suggestion:
How to config the two stage timeouts
(1)from enabling watchdog to WS0
(2)the time from WS1 to WS0
Quoted 5 lines
Quoted 2 lines
If we only have one timeout parameter, How to config the two stage timeouts? Any suggestion ?
I have another thought for this, please allow me to sent anther patchset in a day. see if you like it.
I have sent a non-pretimeout version patchset, please let me know if you like the non-pretimeout version more.
Great thanks for your time. :-)
Quoted 39 lines
Quoted 17 lines
If we make the first stage timeout is timeout/2, this violates the definition of timeout.
I don't think users expect interrupt, panic or reboot at timeout/2.And WS1 definitely isn't a backup of WS0.
Quoted 3 lines
Guenter
--
Best regards,Quoted 8 lines
Fu Wei
Software Engineer
Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch
Ph: +86 21 61221326(direct)
Ph: +86 186 2020 4684 (mobile)
Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021--
Best regards,Fu Wei
Software Engineer
Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch
Ph: +86 21 61221326(direct)
Ph: +86 186 2020 4684 (mobile)
Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021
Signature · 14 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
In reply to Fu WeiQuoted 2 lines · Fu Wei
If we make the first stage timeout is timeout/2, this violates the definition of timeout.
The documentation says that the hardware needs to reset after the timeout expires. If you program the hardware to timeout/2, the driver can ignore WS0 and allow WS1 to reset the hardware. That conforms to the documentation.
Signature · 3 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
Quoted 8 lines · Timur Tabi
Quoted 3 lines · Fu Wei
If we make the first stage timeout is timeout/2, this violates the definition of timeout.
The documentation says that the hardware needs to reset after the timeout expires.
yes , you are absolutely on this. Great thanks for point out this. my patch is doing this way: trigger WS1 at the timeout expires Before that, using pretimeout for WS0 as an warning.
Quoted 3 lines
If you program the hardware to timeout/2, the driver can ignore WS0 and allow WS1 to reset the hardware. That conforms to the documentation.
yes, technically we can do nothing in WS0, and just wait for WS1. So SBSA watchdog become a one stage timeout watchdog, right? So if user want the WS0 warning, How to make driver know that, and do something in WS0 routine?
I think by this way, two stage timeouts, WS0 "alert" will be meaningless.
Could you suggest a good way to use WS0, so we can follow SBSA spec?
Quoted 5 lines
--
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.
Signature · 10 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
Quoted 1 line · Fu Wei
Could you suggest a good way to use WS0, so we can follow SBSA spec?
To avoid the timeout/2 problem, WS0 calls panic, which is the "real" timeout/reset. WS1 is then a "backup" that is ignored by the driver. That is, the driver doesn't do anything with WS1 and it doesn't tell the kernel about WS1.
I know you don't like the idea of WS1 as a backup timeout, but this is one way to solve the problem.
Signature · 3 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.
Guenter Roeck
maintainerRe: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
Quoted 7 lines · Timur Tabi
Quoted 1 line · Fu Wei
Could you suggest a good way to use WS0, so we can follow SBSA spec?
To avoid the timeout/2 problem, WS0 calls panic, which is the "real" timeout/reset. WS1 is then a "backup" that is ignored by the driver. That is, the driver doesn't do anything with WS1 and it doesn't tell the kernel about WS1.
I know you don't like the idea of WS1 as a backup timeout, but this is one way to solve the problem.
This is what I would do.
Guenter
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
In reply to Timur TabiQuoted 9 lines · Timur Tabi
Quoted 2 lines · Fu Wei
Could you suggest a good way to use WS0, so we can follow SBSA spec?
To avoid the timeout/2 problem, WS0 calls panic, which is the "real" timeout/reset. WS1 is then a "backup" that is ignored by the driver. That is, the driver doesn't do anything with WS1 and it doesn't tell the kernel about WS1.
could you suggestion :
(1) how to config the time from WS0 to WS1 without touching timeout.
(2) if we don't config the time from WS0 to WS1, what is the better time for ALL server and ALL situation
Quoted 3 lines
I know you don't like the idea of WS1 as a backup timeout, but this is one way to solve the problem.
It is not "I don't like"
WS1 is not a backup in SBSA spec. Page 21 :
"The initial signal is typically wired to an interrupt and alerts the system. "
If this is the backup, it should say "reset the system"
Quoted 6 lines
--
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.
Signature · 14 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 5/7] Watchdog: introduce ARM SBSA watchdog driver
In reply to Guenter RoeckHi Guenter
Quoted 12 lines · Guenter Roeck
Quoted 11 lines · Timur Tabi
Quoted 2 lines · Fu Wei
Could you suggest a good way to use WS0, so we can follow SBSA spec?
To avoid the timeout/2 problem, WS0 calls panic, which is the "real" timeout/reset. WS1 is then a "backup" that is ignored by the driver. That is, the driver doesn't do anything with WS1 and it doesn't tell the kernel about WS1.
Quoted 4 lines
Quoted 3 lines
I know you don't like the idea of WS1 as a backup timeout, but this is one way to solve the problem.
This is what I would do.
If so, Please check the non-pretimeout version. Thanks
Quoted 3 lines
Guenter
Signature · 10 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021
Guenter Roeck
maintainerRe: [PATCH non-pretimeout 4/7] Watchdog: introduce ARM SBSA watchdog driver
In reply to [email protected]Quoted 82 lines · On 06/10/2015 10:47 AM, [email protected] wrote:
From: Fu Wei <[email protected]>
This driver bases on linux kernel watchdog framework. It supports getting timeout from parameter and FDT at the driver init stage.
The first timeout period expires, the interrupt routine got another timeout period to run panic for saving system context.Signed-off-by Fu Wei <[email protected]>--- drivers/watchdog/Kconfig | 11 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/sbsa_gwdt.c | 383 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 395 insertions(+)create mode 100644
drivers/watchdog/sbsa_gwdt.cdrivers/watchdog/Kconfig +11
-0@@ -152,6 +152,17 @@ config ARM_SP805_WATCHDOG ARM Primecell SP805 Watchdog timer. This will reboot your system when the timeout is reached. +config ARM_SBSA_WATCHDOG + tristate "ARM SBSA Generic Watchdog" + depends on ARM64 + depends on ARM_ARCH_TIMER + select WATCHDOG_CORE + help + ARM SBSA Generic Watchdog. This watchdog has two Watchdog timeouts. + The first timeout will trigger a panic; the second timeout will + trigger a system reset. + More details: ARM DEN0029B - Server Base System Architecture (SBSA) + config AT91RM9200_WATCHDOG tristate "AT91RM9200 watchdog" depends on SOC_AT91RM9200 && MFD_SYSCONdrivers/watchdog/Makefile +1
-0@@ -30,6 +30,7 @@ obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o # ARM Architecture obj-$(CONFIG_ARM_SP805_WATCHDOG) += sp805_wdt.o +obj-$(CONFIG_ARM_SBSA_WATCHDOG) += sbsa_gwdt.o obj-$(CONFIG_AT91RM9200_WATCHDOG) += at91rm9200_wdt.o obj-$(CONFIG_AT91SAM9X_WATCHDOG) += at91sam9_wdt.o obj-$(CONFIG_CADENCE_WATCHDOG) += cadence_wdt.odrivers/watchdog/sbsa_gwdt.c new file +25
-0@@ -0,0 +1,383 @@ +/* +* SBSA(Server Base System Architecture) Generic Watchdog driver +* +* Copyright (c) 2015, Linaro Ltd. +* Author: Fu Wei <[email protected]> +* Suravee Suthikulpanit <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License 2 as published +* by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* Note: This SBSA Generic watchdog has two stage timeouts, +* When the first timeout occurs, WS0(SPI or LPI) is triggered, +* the second timeout period(as long as the first timeout period) starts. +* In WS0 interrupt routine, panic() will be called for collecting +* crashdown info. +* If system can not recover from WS0 interrupt routine, then second +* timeout occurs, WS1(reset or higher level interrupt) is triggered. +* The two timeout period can be set by WOR(32bit). +* WOR gives a maximum watch period of around 10s at the maximum
drivers/watchdog/sbsa_gwdt.c line 35
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+* system counter frequency. +* The System Counter shall run at maximum of 400MHz. +* +* But If we need a larger timeout period, this driver will programme WCV +* directly. That can support more than 10s timeout at the maximum +* system counter frequency. +* More details: ARM DEN0029B - Server Base System Architecture (SBSA) +* +* SBSA GWDT: |---WOR(or WCV)---WS0---WOR(or WCV)---WS1 +* |-----timeout-----WS0-----timeout-----WS1
If we use WCV at all, I would like to see something like
* SBSA GWDT: |---WOR(or WCV)---WS0--------WOR------WS1
* |-----timeout-----WS0-----------------WS1
* panic hw reset
where WOR would be used up to its maximum, to be replaced by WCV (but kept at maximum) if the selected timeout is larger than the maximum timeout selectable with WOR. Would this be possible ?
Guenter
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH non-pretimeout 4/7] Watchdog: introduce ARM SBSA watchdog driver
Hi Guenter,
Quoted 107 lines · Guenter Roeck
Quoted 98 lines · On 06/10/2015 10:47 AM, [email protected] wrote:
From: Fu Wei <[email protected]>
This driver bases on linux kernel watchdog framework. It supports getting timeout from parameter and FDT at the driver init stage.
The first timeout period expires, the interrupt routine got another timeout period to run panic for saving system context.Signed-off-by Fu Wei <[email protected]>--- drivers/watchdog/Kconfig | 11 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/sbsa_gwdt.c | 383 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 395 insertions(+)create mode 100644
drivers/watchdog/sbsa_gwdt.cdrivers/watchdog/Kconfig +0
-0@@ -152,6 +152,17 @@ config ARM_SP805_WATCHDOG ARM Primecell SP805 Watchdog timer. This will reboot your systemwhen
the timeout is reached.drivers/watchdog/Kconfig +7
-0+config ARM_SBSA_WATCHDOG + tristate "ARM SBSA Generic Watchdog" + depends on ARM64 + depends on ARM_ARCH_TIMER + select WATCHDOG_CORE + help + ARM SBSA Generic Watchdog. This watchdog has two Watchdogtimeouts.
drivers/watchdog/Kconfig +3
-0+ The first timeout will trigger a panic; the second timeout will + trigger a system reset. + More details: ARM DEN0029B - Server Base System Architecture(SBSA)
drivers/watchdog/Kconfig +1
-0+ config AT91RM9200_WATCHDOG tristate "AT91RM9200 watchdog" depends on SOC_AT91RM9200 && MFD_SYSCONdrivers/watchdog/Makefile +1
-0@@ -30,6 +30,7 @@ obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o # ARM Architecture obj-$(CONFIG_ARM_SP805_WATCHDOG) += sp805_wdt.o +obj-$(CONFIG_ARM_SBSA_WATCHDOG) += sbsa_gwdt.o obj-$(CONFIG_AT91RM9200_WATCHDOG) += at91rm9200_wdt.o obj-$(CONFIG_AT91SAM9X_WATCHDOG) += at91sam9_wdt.o obj-$(CONFIG_CADENCE_WATCHDOG) += cadence_wdt.odrivers/watchdog/sbsa_gwdt.c new file +19
-0@@ -0,0 +1,383 @@ +/* +* SBSA(Server Base System Architecture) Generic Watchdog driver +* +* Copyright (c) 2015, Linaro Ltd. +* Author: Fu Wei <[email protected]> +* Suravee Suthikulpanit <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License 2 as published +* by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* Note: This SBSA Generic watchdog has two stage timeouts, +* When the first timeout occurs, WS0(SPI or LPI) is triggered, +* the second timeout period(as long as the first timeout period) starts.
+ * In WS0 interrupt routine, panic() will be called for collecting + * crashdown info. + * If system can not recover from WS0 interrupt routine, then second + * timeout occurs, WS1(reset or higher level interrupt) is triggered. + * The two timeout period can be set by WOR(32bit). + * WOR gives a maximum watch period of around 10s at the maximum + * system counter frequency. + * The System Counter shall run at maximum of 400MHz. + * + * But If we need a larger timeout period, this driver will programme WCV + * directly. That can support more than 10s timeout at the maximum + * system counter frequency. + * More details: ARM DEN0029B - Server Base System ArchitectureQuoted 4 lines
(SBSA)
+ *
+ * SBSA GWDT: |---WOR(or WCV)---WS0---WOR(or WCV)---WS1
+ * |-----timeout-----WS0-----timeout-----WS1If we use WCV at all, I would like to see something like
Quoted 7 lines
* SBSA GWDT: |---WOR(or WCV)---WS0--------WOR------WS1
* |-----timeout-----WS0-----------------WS1
* panic hw resetwhere WOR would be used up to its maximum, to be replaced by WCV (but kept at maximum) if the selected timeout is larger than the maximum timeout selectable with WOR. Would this be possible ?
for this part |-----timeout-----WS0, I am doing this way in non-pretimeout version.
but for WS0-----------------WS1, do you mean WOR would always be used up to its maximum???
I don't see any variable attached on it. So I would like to confirm what is this value
Quoted 3 lines
Guenter
Signature · 10 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021
Guenter Roeck
maintainerRe: [PATCH non-pretimeout 4/7] Watchdog: introduce ARM SBSA watchdog driver
Quoted 118 lines · Fu Wei
Hi Guenter,
Quoted 107 lines · Guenter Roeck
Quoted 98 lines · On 06/10/2015 10:47 AM, [email protected] wrote:
From: Fu Wei <[email protected]>
This driver bases on linux kernel watchdog framework. It supports getting timeout from parameter and FDT at the driver init stage.
The first timeout period expires, the interrupt routine got another timeout period to run panic for saving system context.Signed-off-by Fu Wei <[email protected]>--- drivers/watchdog/Kconfig | 11 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/sbsa_gwdt.c | 383 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 395 insertions(+)create mode 100644
drivers/watchdog/sbsa_gwdt.cdrivers/watchdog/Kconfig +0
-0@@ -152,6 +152,17 @@ config ARM_SP805_WATCHDOG ARM Primecell SP805 Watchdog timer. This will reboot your systemwhen
the timeout is reached.drivers/watchdog/Kconfig +7
-0+config ARM_SBSA_WATCHDOG + tristate "ARM SBSA Generic Watchdog" + depends on ARM64 + depends on ARM_ARCH_TIMER + select WATCHDOG_CORE + help + ARM SBSA Generic Watchdog. This watchdog has two Watchdogtimeouts.
drivers/watchdog/Kconfig +3
-0+ The first timeout will trigger a panic; the second timeout will + trigger a system reset. + More details: ARM DEN0029B - Server Base System Architecture(SBSA)
drivers/watchdog/Kconfig +1
-0+ config AT91RM9200_WATCHDOG tristate "AT91RM9200 watchdog" depends on SOC_AT91RM9200 && MFD_SYSCONdrivers/watchdog/Makefile +1
-0@@ -30,6 +30,7 @@ obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o # ARM Architecture obj-$(CONFIG_ARM_SP805_WATCHDOG) += sp805_wdt.o +obj-$(CONFIG_ARM_SBSA_WATCHDOG) += sbsa_gwdt.o obj-$(CONFIG_AT91RM9200_WATCHDOG) += at91rm9200_wdt.o obj-$(CONFIG_AT91SAM9X_WATCHDOG) += at91sam9_wdt.o obj-$(CONFIG_CADENCE_WATCHDOG) += cadence_wdt.odrivers/watchdog/sbsa_gwdt.c new file +19
-0@@ -0,0 +1,383 @@ +/* +* SBSA(Server Base System Architecture) Generic Watchdog driver +* +* Copyright (c) 2015, Linaro Ltd. +* Author: Fu Wei <[email protected]> +* Suravee Suthikulpanit <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License 2 as published +* by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* Note: This SBSA Generic watchdog has two stage timeouts, +* When the first timeout occurs, WS0(SPI or LPI) is triggered, +* the second timeout period(as long as the first timeout period) starts.
+ * In WS0 interrupt routine, panic() will be called for collecting + * crashdown info. + * If system can not recover from WS0 interrupt routine, then second + * timeout occurs, WS1(reset or higher level interrupt) is triggered. + * The two timeout period can be set by WOR(32bit). + * WOR gives a maximum watch period of around 10s at the maximum + * system counter frequency. + * The System Counter shall run at maximum of 400MHz. + * + * But If we need a larger timeout period, this driver will programme WCV + * directly. That can support more than 10s timeout at the maximum + * system counter frequency. + * More details: ARM DEN0029B - Server Base System ArchitectureQuoted 4 lines
(SBSA)
+ *
+ * SBSA GWDT: |---WOR(or WCV)---WS0---WOR(or WCV)---WS1
+ * |-----timeout-----WS0-----timeout-----WS1If we use WCV at all, I would like to see something like
Quoted 7 lines
* SBSA GWDT: |---WOR(or WCV)---WS0--------WOR------WS1
* |-----timeout-----WS0-----------------WS1
* panic hw resetwhere WOR would be used up to its maximum, to be replaced by WCV (but kept at maximum) if the selected timeout is larger than the maximum timeout selectable with WOR. Would this be possible ?
Quoted 5 lines
for this part |-----timeout-----WS0, I am doing this way in non-pretimeout version.
but for WS0-----------------WS1, do you mean WOR would always be used up to its maximum???
yes
Quoted 3 lines
I don't see any variable attached on it. So I would like to confirm what is this value
min(timeout, max_wor_timeout)
Guenter
Re: [PATCH non-pretimeout 4/7] Watchdog: introduce ARM SBSA watchdog driver
Hi Guenter,
Quoted 135 lines · Guenter Roeck
Quoted 127 lines · Fu Wei
Hi Guenter,
Quoted 114 lines · Guenter Roeck
Quoted 96 lines · On 06/10/2015 10:47 AM, [email protected] wrote:
From: Fu Wei <[email protected]>
This driver bases on linux kernel watchdog framework. It supports getting timeout from parameter and FDT at the driver init stage.
The first timeout period expires, the interrupt routine got another timeout period to run panic for saving system context.Signed-off-by Fu Wei <[email protected]>--- drivers/watchdog/Kconfig | 11 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/sbsa_gwdt.c | 383 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 395 insertions(+)create mode 100644
drivers/watchdog/sbsa_gwdt.cdrivers/watchdog/Kconfig +0
-0@@ -152,6 +152,17 @@ config ARM_SP805_WATCHDOG ARM Primecell SP805 Watchdog timer. This will reboot yoursystem
when
the timeout is reached.drivers/watchdog/Kconfig +7
-0+config ARM_SBSA_WATCHDOG + tristate "ARM SBSA Generic Watchdog" + depends on ARM64 + depends on ARM_ARCH_TIMER + select WATCHDOG_CORE + help + ARM SBSA Generic Watchdog. This watchdog has two Watchdogtimeouts.
+ The first timeout will trigger a panic; the second timeout
willdrivers/watchdog/Kconfig +2
-0+ trigger a system reset. + More details: ARM DEN0029B - Server Base System Architecture(SBSA)
drivers/watchdog/Kconfig +1
-0+ config AT91RM9200_WATCHDOG tristate "AT91RM9200 watchdog" depends on SOC_AT91RM9200 && MFD_SYSCONdrivers/watchdog/Makefile +1
-0@@ -30,6 +30,7 @@ obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o # ARM Architecture obj-$(CONFIG_ARM_SP805_WATCHDOG) += sp805_wdt.o +obj-$(CONFIG_ARM_SBSA_WATCHDOG) += sbsa_gwdt.o obj-$(CONFIG_AT91RM9200_WATCHDOG) += at91rm9200_wdt.o obj-$(CONFIG_AT91SAM9X_WATCHDOG) += at91sam9_wdt.o obj-$(CONFIG_CADENCE_WATCHDOG) += cadence_wdt.odrivers/watchdog/sbsa_gwdt.c new file +19
-0@@ -0,0 +1,383 @@ +/* +* SBSA(Server Base System Architecture) Generic Watchdog driver +* +* Copyright (c) 2015, Linaro Ltd. +* Author: Fu Wei <[email protected]> +* Suravee Suthikulpanit <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License 2 as published +* by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* Note: This SBSA Generic watchdog has two stage timeouts, +* When the first timeout occurs, WS0(SPI or LPI) is triggered, +* the second timeout period(as long as the first timeout period) starts.
+ * In WS0 interrupt routine,panic()will be called for
collecting
+ * crashdown info.
+ * If system can not recover from WS0 interrupt routine, then
second
+ * timeout occurs, WS1(reset or higher level interrupt) is
triggered.+ * The two timeout period can be set by WOR(32bit). + * WOR gives a maximum watch period of around 10s at the maximum + * system counter frequency. + * The System Counter shall run at maximum of 400MHz.Quoted 11 lines
+ *
+ * But If we need a larger timeout period, this driver will
programme WCV
+ * directly. That can support more than 10s timeout at the
maximum
+ * system counter frequency.
+ * More details: ARM DEN0029B - Server Base System Architecture
(SBSA)
+ *
+ * SBSA GWDT: |---WOR(or WCV)---WS0---WOR(or WCV)---WS1
+ * |-----timeout-----WS0-----timeout-----WS1If we use WCV at all, I would like to see something like
Quoted 7 lines
* SBSA GWDT: |---WOR(or WCV)---WS0--------WOR------WS1
* |-----timeout-----WS0-----------------WS1
* panic hw resetwhere WOR would be used up to its maximum, to be replaced by WCV (but kept at maximum) if the selected timeout is larger than the maximum timeout selectable with WOR. Would this be possible ?
Quoted 5 lines
for this part |-----timeout-----WS0, I am doing this way in non-pretimeout version.
but for WS0-----------------WS1, do you mean WOR would always be used up to its maximum???
Quoted 7 lines
yes
Quoted 3 lines
I don't see any variable attached on it. So I would like to confirm what is this value
min(timeout, max_wor_timeout)
Sure, no problem. just need a very little fix in non-pretimout version
Just delete several lines in "sbsa_gwdt_interrupt", become like this:
+static irqreturn_t sbsa_gwdt_interrupt(int irq, void *dev_id) +{
+ panic("SBSA Watchdog pre-timeout");
+
+ return IRQ_HANDLED;
+}
this matches your thought.
Any other code I need to improve ? If It is OK for you, I can sent a new patchset soon.
Please let me know anything else I need to improve.
Great thanks for your time
Quoted 3 lines
Guenter
Signature · 14 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH non-pretimeout 5/7] ACPI: add GTDT table parse driver into ACPI driver
In reply to [email protected]Hi Rafael,
Any comments on patch 5,6,7/7 of this patch set?
Thanks
Hanjun
Quoted 190 lines · On 06/11/2015 01:47 AM, [email protected] wrote:
From: Fu Wei <[email protected]>
This driver adds support for parsing SBSA Generic Watchdog Structure in GTDT, and creating a platform device with that information. This allows the operating system to obtain device data from the resource of platform device.
The platform device named "sbsa-gwdt" can be used by the ARM SBSA Generic Watchdog driver.
Signed-off-by Fu Wei <[email protected]>Signed-off-by Hanjun Guo <[email protected]>--- drivers/acpi/Kconfig | 9 ++++ drivers/acpi/Makefile | 1 + drivers/acpi/gtdt.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+)create mode 100644
drivers/acpi/gtdt.cdrivers/acpi/Kconfig +9
-0@@ -433,4 +433,13 @@ config XPOWER_PMIC_OPREGION endif +config ACPI_GTDT + bool "ACPI GTDT Support" + depends on ARM64 + help + GTDT (Generic Timer Description Table) provides information + for per-processor timers and Platform (memory-mapped) timers + for ARM platforms. Select this option to provide information + needed for the timers init. + endif # ACPIdrivers/acpi/Makefile +1
-0@@ -96,3 +96,4 @@ obj-$(CONFIG_ACPI_EXTLOG) += acpi_extlog.o obj-$(CONFIG_PMIC_OPREGION) += pmic/intel_pmic.o obj-$(CONFIG_CRC_PMIC_OPREGION) += pmic/intel_pmic_crc.o obj-$(CONFIG_XPOWER_PMIC_OPREGION) += pmic/intel_pmic_xpower.o +obj-$(CONFIG_ACPI_GTDT) += gtdt.odrivers/acpi/gtdt.c new file +137
-0@@ -0,0 +1,137 @@ +/* +* ARM Specific GTDT table Support +* +* Copyright (C) 2015, Linaro Ltd. +* Author: Fu Wei <[email protected]> +* Hanjun Guo <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/acpi.h> +#include <linux/device.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +static int __init map_generic_timer_interrupt (u32 interrupt,u32 flags) +{ +int trigger, polarity; + +if (!interrupt) +return 0 ; + + trigger = (flags &ACPI_GTDT_INTERRUPT_MODE ) ?ACPI_EDGE_SENSITIVE + :ACPI_LEVEL_SENSITIVE ; + + polarity = (flags &ACPI_GTDT_INTERRUPT_POLARITY ) ?ACPI_ACTIVE_LOW + :ACPI_ACTIVE_HIGH ; + +return acpi_register_gsi (NULL , interrupt, trigger, polarity); +} + +/* +* Initialize a SBSA generic Watchdog platform device info from GTDT +* According to SBSA specification the size of refresh and control +* frames of SBSA Generic Watchdog is SZ_4K(Offset 0x000 – 0xFFF). +*/ +static int __init gtdt_import_sbsa_gwdt (struct acpi_gtdt_watchdog *wd, +int index) +{ +struct platform_device *pdev; +int irq =map_generic_timer_interrupt (wd->timer_interrupt, + wd->timer_flags); +struct resource res[] = { +DEFINE_RES_IRQ_NAMED (irq,"ws0" ), +DEFINE_RES_MEM_NAMED (wd->refresh_frame_address,SZ_4K , +"refresh" ), +DEFINE_RES_MEM_NAMED (wd->control_frame_address,SZ_4K , +"control" ), + }; + +pr_debug ("GTDT: a Watchdog GT(0x%llx/0x%llx gsi:%u flags:0x%x)\n" , + wd->refresh_frame_address, wd->control_frame_address, + wd->timer_interrupt, wd->timer_flags); + +if (!(wd->refresh_frame_address && + wd->control_frame_address && + wd->timer_interrupt)) { +pr_err ("GTDT: failed geting the device info.\n" ); +return -EINVAL ; + } + +if (irq <0 ) { +pr_err ("GTDT: failed to register GSI of the Watchdog GT.\n" ); +return -EINVAL ; + } + +/* +* Add a platform device named "sbsa-gwdt" to match the platform driver. +* "sbsa-gwdt": SBSA(Server Base System Architecture) Generic Watchdog +* The platform driver (like drivers/watchdog/sbsa_gwdt.c)can get device +* info below by matching this name. +*/ + pdev =platform_device_register_simple ("sbsa-gwdt" , index, res, +ARRAY_SIZE (res)); +if (IS_ERR (pdev)) { +acpi_unregister_gsi (wd->timer_interrupt); +return PTR_ERR (pdev); + } + +return 0 ; +} + +static int __init gtdt_platform_timer_parse (struct acpi_table_header *table) +{ +struct acpi_gtdt_header *header; +struct acpi_table_gtdt *gtdt; +void *gtdt_subtable; +int i, gwdt_index; +int ret =0 ; + +if (table->revision <2 ) { +pr_warn ("GTDT: Revision:%d doesn't support Platform Timers.\n" , + table->revision); +return 0 ; + } + + gtdt = container_of(table, struct acpi_table_gtdt, header); +if (!gtdt->platform_timer_count) { +pr_info ("GTDT: No Platform Timer structures.\n" ); +return 0 ; + } + + gtdt_subtable = (void *)gtdt + gtdt->platform_timer_offset; + +for (i =0 , gwdt_index =0 ; i < gtdt->platform_timer_count; i++) { +if (gtdt_subtable > (void *)table + table->length) { +pr_err ("GTDT: subtable pointer overflows, bad table\n" ); +return -EINVAL ; + } + header = (struct acpi_gtdt_header *)gtdt_subtable; +if (header->type ==ACPI_GTDT_TYPE_WATCHDOG ) { + ret =gtdt_import_sbsa_gwdt (gtdt_subtable, gwdt_index); +if (ret) +pr_err ("GTDT: failed to import subtable %d\n" , + i); +else + gwdt_index++; + } + gtdt_subtable += header->length; + } + +return ret; +} + +static int __init gtdt_platform_timer_init (void ) +{ +if (acpi_disabled) +return 0 ; + +return acpi_table_parse (ACPI_SIG_GTDT , gtdt_platform_timer_parse); +} + +device_initcall (gtdt_platform_timer_init);
Re: [PATCH v5 4/8] Watchdog: introdouce "pretimeout" into framework
In reply to Guenter RoeckHi Guenter,
Great thanks for your time.
Quoted 130 lines · Guenter Roeck
Quoted 103 lines · On 06/10/2015 06:41 AM, [email protected] wrote:
From: Fu Wei <[email protected]>
Also update
Documentation/watchdog/watchdog-kernel-api.txtto introduce:
(1)the new elements in thewatchdog_deviceandwatchdog_opsstruct; (2)the new API "watchdog_init_timeouts"Reasons:
(1)kernel already has two watchdog drivers are using "pretimeout":
drivers/char/ipmi/ipmi_watchdog.cdrivers/watchdog/kempld_wdt.c(but the definition is different)
(2)some other drivers are going to use this: ARM SBSA Generic WatchdogSigned-off-by Fu Wei <[email protected]>--- Documentation/watchdog/watchdog-kernel-api.txt | 47 ++++++++++-- drivers/watchdog/watchdog_core.c | 100 +++++++++++++++++-------- drivers/watchdog/watchdog_dev.c | 53 +++++++++++++ include/linux/watchdog.h | 36 ++++++++- 4 files changed, 197 insertions(+), 39 deletions(-)Documentation/watchdog/watchdog-kernel-api.txt +5
-0@@ -49,6 +49,9 @@ struct watchdog_device { unsigned int timeout; unsigned int min_timeout; unsigned int max_timeout; + unsigned int pretimeout; + unsigned int min_pretimeout; + unsigned int max_pretimeout; void *driver_data; struct mutex lock; unsigned long status;@@ -70,6 +73,9 @@ It contains following fields: * timeout: the watchdog timer's timeout value (in seconds). * min_timeout: the watchdog timer's minimum timeout value (in seconds). * max_timeout: the watchdog timer's maximum timeout value (in seconds). +* pretimeout: the watchdog timer's pretimeout value (in seconds). +* min_pretimeout: the watchdog timer's minimum pretimeout value (inseconds).
+*max_pretimeout: the watchdog timer's maximum pretimeout value (in seconds).
* bootstatus: status of the device after booting (reported with watchdog WDIOF_* status bits).
*driver_data: a pointer to the drivers private data of a watchdog
device.Documentation/watchdog/watchdog-kernel-api.txt +1
-0@@ -92,6 +98,7 @@ struct watchdog_ops { int (*ping)(struct watchdog_device *); unsigned int (*status)(struct watchdog_device *); int (*set_timeout)(struct watchdog_device *, unsigned int); + int (*set_pretimeout)(struct watchdog_device *, unsigned int); unsigned int (*get_timeleft)(struct watchdog_device *); void (*ref)(struct watchdog_device *); void (*unref)(struct watchdog_device *);@@ -153,9 +160,19 @@ they are supported. These optionalroutines/operations are:
and-EIOfor "could not write value to the watchdog". On success this routine should set the timeout value of thewatchdog_deviceto the achieved timeout value (which may be different from the requested oneDocumentation/watchdog/watchdog-kernel-api.txt +2
-1- because the watchdog does not necessarily has a 1 second resolution). + because the watchdog does not necessarily has a 1 second resolution; + If the driver supports pretimeout, then the timeout value must begreater
+ than that).
(Note: theWDIOF_SETTIMEOUTneeds to be set in the options field of
the
watchdog's info structure).Documentation/watchdog/watchdog-kernel-api.txt +2
-0+* set_pretimeout: this routine checks and changes the pretimeout of the + watchdog timer device. It returns 0 on success, -EINVAL for "parameterout of
+ range" and-EIOfor "could not write value to the watchdog". On success thisDocumentation/watchdog/watchdog-kernel-api.txt +2
-0+ routine should set the pretimeout value of the watchdog_device to the + achieved pretimeout value (which may be different from the requestedone
Documentation/watchdog/watchdog-kernel-api.txt +3
-0+ because the watchdog does not necessarily has a 1 second resolution). + (Note: the WDIOF_PRETIMEOUT needs to be set in the options field of the + watchdog's info structure). * get_timeleft: this routines returns the time that's left before areset.
* ref: the operation that callskref_geton the kref of a dynamically allocatedwatchdog_devicestruct.Documentation/watchdog/watchdog-kernel-api.txt +0
-0@@ -219,8 +236,28 @@ extern int watchdog_init_timeout(struct watchdog_device *wdd, unsigned int timeout_parm, struct device *dev); The watchdog_init_timeout function allows you to initialize the timeoutfield
-using the module timeout parameter or by retrieving the timeout-sec property from
-the device tree (if the module timeout parameter is invalid). Best practice is
-to set the default timeout value as timeout value in thewatchdog_deviceandDocumentation/watchdog/watchdog-kernel-api.txt +2
-1-then use this function to set the user "preferred" timeout value. +using the module timeout parameter or by retrieving the first element of +the timeout-sec property from the device tree (if the module timeoutQuoted 1 line
parameter
Missing space before (.
Quoted 21 lines
+is invalid). Best practice is to set the default timeout value as timeout value
+in thewatchdog_deviceand then use this function to set the user "preferred"Documentation/watchdog/watchdog-kernel-api.txt +2
-0+timeout value. +This routine returns zero on success and a negative errno code forfailure.
Documentation/watchdog/watchdog-kernel-api.txt +3
-0+ +Some watchdog timers have two stage of timeouts(timeout and pretimeout), +to initialize the timeout and pretimeout fields at the same time, thefollowing
Documentation/watchdog/watchdog-kernel-api.txt +8
-0+function can be used: + +extern int watchdog_init_timeouts(struct watchdog_device *wdd, + unsigned int pretimeout_parm, + unsigned int timeout_parm, + struct device *dev); + +The watchdog_init_timeouts function allows you to initialize thepretimeout and
+timeout fields using the module pretimeout and timeout parameter or by
Quoted 8 lines
Quoted 5 lines
+retrieving the elements in the timeout-sec property(the first element is for
+timeout, the second one is for pretimeout) from the device tree(if the module
+pretimeout and timeout parameter are invalid).Missing spaces before (.
Fixed these problem above , thanks
Quoted 17 lines
Quoted 17 lines
+Best practice is to set the default pretimeout and timeout value as pretimeout
+and timeout value in thewatchdog_deviceand then use this function to set the
+user "preferred" pretimeout value.
This routine returns zero on success and a negative errno code for
failure.drivers/watchdog/watchdog_core.c +0
-0@@ -43,60 +43,98 @@static DEFINE_IDA (watchdog_ida);static struct class *watchdog_class;
Quoted 6 lines
drivers/watchdog/watchdog_core.c line 46
Quoted 2 lines
drivers/watchdog/watchdog_core.c +1
-1-static void watchdog_check_min_max_timeout (struct watchdog_device *wdd) +static void watchdog_check_min_max_timeouts (struct watchdog_device *wdd)Please don't rename this function. This avoids conflicts with other pending patches.
OK, changed it back. Fixed.
Quoted 19 lines
Quoted 7 lines
drivers/watchdog/watchdog_core.c +1
-2{/* -* Check that we have valid min and max timeout values, if -* not reset them both to 0 (=not used or unknown) +* Check that we have valid min and max pretimeout and timeout values, drivers/watchdog/watchdog_core.c line 56
Quoted 10 lines
drivers/watchdog/watchdog_core.c +6
-2+* if not, reset them all to 0 (=not used or unknown) */ -if (wdd->min_timeout > wdd->max_timeout) { -pr_info ("Invalid min and max timeout values, resetting to 0!\n"); + if (wdd->min_pretimeout > wdd->max_pretimeout || + wdd->min_timeout > wdd->max_timeout || + wdd->min_timeout < wdd->min_pretimeout || + wdd->max_timeout < wdd->max_pretimeout) { +pr_info ("Invalid min and max timeouts, resetting to 0\n" );
Quoted 1 line
timeouts or pretimeouts.
OK , thanks
Quoted 94 lines
Quoted 57 lines
drivers/watchdog/watchdog_core.c +4
-2+ wdd->min_pretimeout =0 ; + wdd->max_pretimeout =0 ; wdd->min_timeout =0 ; wdd->max_timeout =0 ; } }/** -* watchdog_init_timeout() - initialize the timeout field +* watchdog_init_timeouts() - initialize the pretimeout and timeout field +* @pretimeout_parm: pretimeout module parameter * @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
- * timeout module parameter (if it is valid value) or the timeout-sec property
- * (only if it is a valid value and thetimeout_parmis out of bounds).
- * If none of them are valid then we keep the old value (which should normally
- * be the default timeout value.
+ * Initialize the pretimeout and timeout field of thewatchdog_devicestruct
+ * with either the pretimeout and timeout module parameter (if it is valid) or
+ * the timeout-sec property (only if it is valid and thepretimeout_parmor
+ *timeout_parmis out of bounds). If none of them is valid, then we keep
+ * the old value (which should normally be the default timeout value). *
* A zero is returned on success and-EINVALfor failure.
*/drivers/watchdog/watchdog_core.c +0
-2-int watchdog_init_timeout (struct watchdog_device *wdd, - unsigned int timeout_parm, struct device*dev)
drivers/watchdog/watchdog_core.c +8
-5+int watchdog_init_timeouts (struct watchdog_device *wdd, +unsigned int pretimeout_parm, +unsigned int timeout_parm, +struct device *dev) { -unsigned int t =0 ; -int ret =0 ; +int ret =0 , length =0 ; +u32 timeouts[2 ] = {0 }; +struct property *prop; -watchdog_check_min_max_timeout (wdd); +watchdog_check_min_max_timeouts (wdd); -/* try to get the timeout module parameter first */ -if (!watchdog_timeout_invalid (wdd, timeout_parm) && timeout_parm){
drivers/watchdog/watchdog_core.c +0
-2- wdd->timeout = timeout_parm; -return ret;drivers/watchdog/watchdog_core.c line 96
Quoted 10 lines
drivers/watchdog/watchdog_core.c +8
-2- } -if (timeout_parm) +/* +* Try to get the pretimeout module parameter first +*/ +if (!watchdog_pretimeout_invalid (wdd, pretimeout_parm)) + timeouts[1 ] = pretimeout_parm; +else + ret = -EINVAL ;/* pretimeout_parm is invalid */ +If I understand the code correctly, this permits for pretimeout being specified
as module parameter and timeout as devicetree property. I don't think this is a good idea. Use either one or the other, but not both. So this can be simplified toif (
watchdog_pretimeout_invalid(wdd, pretimeout_parm)
ret =_EINVAL;if you use pretimeout directly below.
drivers/watchdog/watchdog_core.c line 102
Quoted 6 lines
drivers/watchdog/watchdog_core.c +6
-0+/* +* Try to get the timeout module parameter, +* if it's valid and pretimeout is valid(ret == 0), +* assignment and return zero. Otherwise, try dtb. +*/ +if (timeout_parm) {You can use
if (timeout_parm && !ret) {Quoted 2 lines
+ if (!watchdog_timeout_invalid(wdd,
timeout_parm) && !ret)
{
Quoted 8 lines
instead of checking ret here.
drivers/watchdog/watchdog_core.c
Quoted 2 lines
drivers/watchdog/watchdog_core.c +2
-0+ wdd->timeout = timeout_parm; + wdd->pretimeout = timeouts[1 ];This is really
pretimeout_parmhere, which should be used. Then you don't need timeouts[1].
yes, you are right on this, I have improved it :-)
Quoted 15 lines
drivers/watchdog/watchdog_core.c line 109
Quoted 6 lines
drivers/watchdog/watchdog_core.c +3
-0+return 0 ; + } ret = -EINVAL ; + }Unfortunately this does not set
wdd->pretimeoutifpretimeout_parmis set buttimeout_parmisn't. So I think you need} else if (pretimeout_parm && !ret) { wdd->pretimeout = pretimeout; return 0; }
Quoted 7 lines
However, that actually won't work as we may try to set both timeout and pretimeout, but the current checks validate against the previous values. I'll need to think about that.
Also, this is getting a bit complicated. Wonder if the code can be simplified.
Something else to think about.
I think we don't need this, because only if both parameters are valid, we can update the wdd->pretimeout and wdd->timeout. otherwise we ret = -EINVAL; then try devicetree.
Quoted 31 lines
Quoted 19 lines
drivers/watchdog/watchdog_core.c +7
-7-/* try to get the timeout_sec property */ +/* +* Either at least one of the module parameters is invalid, +* or timeout_parm is 0. Try to get the timeout_sec property. +*/ if (dev ==NULL || dev->of_node ==NULL )return ret; -of_property_read_u32 (dev->of_node,"timeout-sec" , &t); -if (!watchdog_timeout_invalid (wdd, t) && t) - wdd->timeout = t; -else - ret = -EINVAL ; -return ret; + prop =of_find_property (dev->of_node,"timeout-sec" , &length); +if (prop && length >0 && length <=sizeof (u32) *2 ) { + of_property_read_u32_array(dev->of_node,drivers/watchdog/watchdog_core.c line 130
Quoted 10 lines
drivers/watchdog/watchdog_core.c +10
-0+"timeout-sec" , timeouts, + length / sizeof(u32)); +if (length ==sizeof (u32) *2 && +watchdog_pretimeout_invalid (wdd, timeouts[1 ])) +return -EINVAL ; + +if (!watchdog_timeout_invalid (wdd, timeouts[0 ]) && + timeouts[0 ]) { + wdd->timeout = timeouts[0 ]; + wdd->pretimeout = timeouts[1 ];
Quoted 1 line
Please only set pretimeout here if specified in devicetree.
yes , fixed this problem
Quoted 157 lines
Quoted 149 lines
drivers/watchdog/watchdog_core.c +7
-2+return 0 ; + } + } + +return -EINVAL ; } -EXPORT_SYMBOL_GPL (watchdog_init_timeout); +EXPORT_SYMBOL_GPL (watchdog_init_timeouts);/** * watchdog_register_device() - register a watchdog device @@ -119,7 +157,7 @@ int watchdog_register_device(struct watchdog_device *wdd)if (wdd->ops->start ==NULL || wdd->ops->stop ==NULL )return -EINVAL ; -watchdog_check_min_max_timeout (wdd); +watchdog_check_min_max_timeouts (wdd);/* * Note: now that all
watchdog_devicedata has been verified, wedrivers/watchdog/watchdog_dev.c +32
-0@@ -218,6 +218,38 @@ out_timeout: }/* +* watchdog_set_pretimeout: set the watchdog timer pretimeout +* @wddev: the watchdog device to set the timeout for +* @pretimeout: pretimeout to set in seconds +*/ + +static int watchdog_set_pretimeout (struct watchdog_device *wddev, +unsigned int pretimeout) +{ +int err; + +if (!wddev->ops->set_pretimeout || + !(wddev->info->options &WDIOF_PRETIMEOUT )) +return -EOPNOTSUPP ; + +if (watchdog_pretimeout_invalid (wddev, pretimeout)) +return -EINVAL ; + +mutex_lock (&wddev->lock); + +if (test_bit (WDOG_UNREGISTERED , &wddev->status)) { + err = -ENODEV ; + goto out_pretimeout; + } + + err = wddev->ops->set_pretimeout (wddev, pretimeout); + +out_pretimeout: +mutex_unlock (&wddev->lock); +return err; +} + +/* * watchdog_get_timeleft: wrapper to get the time left before a reboot
* @wddev: the watchdog device to get the remaining time from
* @timeleft: the time that's leftdrivers/watchdog/watchdog_dev.c +21
-0@@ -388,6 +420,27 @@ static long watchdog_ioctl(struct file *file, unsigned int cmd, if (wdd->timeout == 0) return -EOPNOTSUPP;return put_user (wdd->timeout, p); +case WDIOC_SETPRETIMEOUT : +/* check if we support the pretimeout */ +if (!(wdd->info->options &WDIOF_PRETIMEOUT )) +return -EOPNOTSUPP ; +if (get_user (val, p)) +return -EFAULT ; + err =watchdog_set_pretimeout (wdd, val); +if (err <0 ) +return err; +/* +* If the watchdog is active then we send a keepalive ping +* to make sure that the watchdog keeps running (and if +* possible that it takes the new pretimeout) +*/ +watchdog_ping (wdd); +/* Fall */ +case WDIOC_GETPRETIMEOUT : +/* check if we support the pretimeout */ +if (wdd->info->options &WDIOF_PRETIMEOUT ) +return put_user (wdd->pretimeout, p); +return -EOPNOTSUPP ;case WDIOC_GETTIMELEFT : err =watchdog_get_timeleft (wdd, &val);if (err)
include/linux/watchdog.h +0
-0@@ -25,6 +25,7 @@ struct watchdog_device;* @ping: The routine that sends a keepalive ping to the watchdog device.
* @status: The routine that shows the status of the watchdog device.
* @set_timeout:The routine for setting the watchdog devices timeout
value.
+ * @set_pretimeout:The routine for setting the watchdog devices pretimeout value
* @get_timeleft:The routine that get's the time that's left before a
reset.
* @ref: The ref operation for dyn. allocatedwatchdog_device
structs
* @unref: The unref operation for dyn. allocatedwatchdog_device
structsinclude/linux/watchdog.h +7
-0@@ -44,6 +45,7 @@ struct watchdog_ops {int (*ping)(struct watchdog_device *);unsigned int (*status)(struct watchdog_device *);int (*set_timeout)(struct watchdog_device *,unsigned int ); +int (*set_pretimeout)(struct watchdog_device *,unsigned int );unsigned int (*get_timeleft)(struct watchdog_device *);void (*ref)(struct watchdog_device *);void (*unref)(struct watchdog_device *);@@ -62,6 +64,9 @@ struct watchdog_ops {* @timeout: The watchdog devices timeout value. * @min_timeout:The watchdog devices minimum timeout value. * @max_timeout:The watchdog devices maximum timeout value. +* @pretimeout: The watchdog devices pretimeout value. +* @min_pretimeout:The watchdog devices minimum pretimeout value. +* @max_pretimeout:The watchdog devices maximum pretimeout value. * @driver-data:Pointer to the drivers private data. * @lock: Lock for watchdog core internal use only. * @status: Field that contains the devices internal status bits. @@ -86,6 +91,9 @@ struct watchdog_device {unsigned int timeout;unsigned int min_timeout;unsigned int max_timeout; +unsigned int pretimeout; +unsigned int min_pretimeout; +unsigned int max_pretimeout;void *driver_data;struct mutex lock;unsigned long status;@@ -117,7 +125,20 @@ static inline void watchdog_set_nowayout(struct
watchdog_device*wdd, bool noway
static inline bool watchdog_timeout_invalid(structwatchdog_device*wdd,
unsigned int t){ return ((wdd->max_timeout != 0) &&include/linux/watchdog.h static inline void watchdog_set_nowayout(struct watchdog_device *wdd, bool noway · line 129
Quoted 3 lines
include/linux/watchdog.h +2
-1- (t < wdd->min_timeout || t > wdd->max_timeout)); + (t < wdd->min_timeout || t > wdd->max_timeout || + t <= wdd->pretimeout));pretimeout can be 0, and t needs to be evaluated against pretimeout even if
max_timeoutis 0.
Quoted 4 lines
Try
return (wdd->max_timeout && (t < wdd->min_timeout || t > wdd->max_timeout)) || (wdd->pretimeout && t <= wdd->pretimeout);
yes, you are right . fixed.
Quoted 17 lines
Quoted 9 lines
include/linux/watchdog.h +7
-0+} + +/* +* Use the following function to check if a pretimeout value is invalid. +* It can be "0", that means we don't use pretimeout. +*/ +static inline bool watchdog_pretimeout_invalid(struct watchdog_device*wdd,
include/linux/watchdog.h static inline void watchdog_set_nowayout(struct watchdog_device *wdd, bool noway · line 141
Quoted 5 lines
include/linux/watchdog.h +5
-0+ unsigned int t) +{ +return (wdd->pretimeout !=0 && wdd->max_pretimeout !=0 && + (t < wdd->min_pretimeout || t > wdd->max_pretimeout || + (wdd->timeout !=0 && t >= wdd->timeout)));The check for
wdd->pretimeoutdoesn't make much sense here, as this is the
sorry , that is typo, I mean "t" here.
if t == 0 , return 0. because 0 is a valid value of pretimeout.
Quoted 11 lines
value we are trying to set. Effectively the above accepts every pretimeout if
wdd->pretimeoutis 0. It also accepts every pretimeout ifmax_pretimeout== 0, even ifwdd->timeoutis set and t >=wdd->timeout.Try
return (wdd->max_pretimeout && (t < wdd->min_pretimeout || t > wdd->max_pretimeout)) || (wdd->timeout && t >= wdd->timeout);Quoted 1 line
}
/*
* Use the following function to check if a pretimeout value is invalid.
* It can be "0", that means we don't use pretimeout.
* This function returns 0, when pretimeout is 0.
*/
static inline bool watchdog_pretimeout_invalid(struct watchdog_device *wdd,
unsigned int t)
{
return t && (wdd->max_pretimeout &&
(t < wdd->min_pretimeout || t > wdd->max_pretimeout)) ||
(wdd->timeout && t >= wdd->timeout);
}Quoted 7 lines
Quoted 7 lines
/* Use the following functions to manipulate watchdog driver specific
data */include/linux/watchdog.h +0
-0@@ -132,11 +153,20 @@ static inline void *watchdog_get_drvdata(struct watchdog_device *wdd) }
Quoted 11 lines
include/linux/watchdog.h static inline void *watchdog_get_drvdata(struct watchdog_device *wdd) · line 159
Quoted 8 lines
include/linux/watchdog.h +4
-2/* drivers/watchdog/watchdog_core.c */ -extern int watchdog_init_timeout (struct watchdog_device *wdd, -unsigned int timeout_parm,struct device *dev); +int watchdog_init_timeouts (struct watchdog_device *wdd, +unsigned int pretimeout_parm, +unsigned int timeout_parm, +struct device *dev);Please align continuation lines with '('.
Fixed , thanks
Quoted 17 lines
Quoted 16 lines
include/linux/watchdog.h +7
-0extern int watchdog_register_device (struct watchdog_device *);extern void watchdog_unregister_device (struct watchdog_device *); +static inline int watchdog_init_timeout (struct watchdog_device *wdd, +unsigned int timeout_parm, +struct device *dev) +{ +return watchdog_init_timeouts (wdd,0 , timeout_parm, dev); +} +#ifdef CONFIG_HARDLOCKUP_DETECTOR void watchdog_nmi_disable_all(void); void watchdog_nmi_enable_all(void);
Signature · 10 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021
Guenter Roeck
maintainerRe: [non-pretimeout,4/7] Watchdog: introduce ARM SBSA watchdog driver
In reply to [email protected]Quoted 9 lines · On Thu, Jun 11, 2015 at 01:47:29AM +0800, [email protected] wrote:
From: Fu Wei <[email protected]>
This driver bases on linux kernel watchdog framework. It supports getting timeout from parameter and FDT at the driver init stage.
The first timeout period expires, the interrupt routine got another timeout period to run panic for saving system context.
Comments inline.
Thanks,
Guenter
Quoted 17 lines
Signed-off-by Fu Wei <[email protected]>--- drivers/watchdog/Kconfig | 11 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/sbsa_gwdt.c | 383 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 395 insertions(+) create mode 100644 drivers/watchdog/sbsa_gwdt.cdrivers/watchdog/Kconfig +1
-0@@ -152,6 +152,17 @@ config ARM_SP805_WATCHDOG ARM Primecell SP805 Watchdog timer. This will reboot your system when the timeout is reached. +config ARM_SBSA_WATCHDOG
drivers/watchdog/Kconfig config ARM_SP805_WATCHDOG · line 165
Quoted 10 lines
drivers/watchdog/Kconfig +10
-0+ tristate "ARM SBSA Generic Watchdog" + depends on ARM64 + depends on ARM_ARCH_TIMER + select WATCHDOG_CORE + help + ARM SBSA Generic Watchdog. This watchdog has two Watchdog timeouts. + The first timeout will trigger a panic; the second timeout will + trigger a system reset. + More details: ARM DEN0029B - Server Base System Architecture (SBSA) +
To compile this driver as module, choose M here: The module will be called sbsa_gwdt.
Quoted 28 lines
drivers/watchdog/Kconfig +0
-0config AT91RM9200_WATCHDOG tristate "AT91RM9200 watchdog" depends on SOC_AT91RM9200 && MFD_SYSCONdrivers/watchdog/Makefile +1
-0@@ -30,6 +30,7 @@ obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o # ARM Architecture obj-$(CONFIG_ARM_SP805_WATCHDOG) += sp805_wdt.o +obj-$(CONFIG_ARM_SBSA_WATCHDOG) += sbsa_gwdt.o obj-$(CONFIG_AT91RM9200_WATCHDOG) += at91rm9200_wdt.o obj-$(CONFIG_AT91SAM9X_WATCHDOG) += at91sam9_wdt.o obj-$(CONFIG_CADENCE_WATCHDOG) += cadence_wdt.odrivers/watchdog/sbsa_gwdt.c new file +7
-0@@ -0,0 +1,383 @@ +/* +* SBSA(Server Base System Architecture) Generic Watchdog driver +* +* Copyright (c) 2015, Linaro Ltd. +* Author: Fu Wei <[email protected]> +* Suravee Suthikulpanit <[email protected]> +*
drivers/watchdog/sbsa_gwdt.c line 17
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License 2 as published +* by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* Note: This SBSA Generic watchdog has two stage timeouts,
s/This/The/
"has two stages".
I would suggest to drop "Note:", but that is up to you.
drivers/watchdog/sbsa_gwdt.c line 19
Quoted 2 lines
drivers/watchdog/sbsa_gwdt.c new file +2
-0+* When the first timeout occurs, WS0(SPI or LPI) is triggered, +* the second timeout period(as long as the first timeout period) starts.
no longer accurate if WOR is used for the second period.
drivers/watchdog/sbsa_gwdt.c line 24
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +5
-0+* In WS0 interrupt routine, panic() will be called for collecting +* crashdown info. +* If system can not recover from WS0 interrupt routine, then second +* timeout occurs, WS1(reset or higher level interrupt) is triggered. +* The two timeout period can be set by WOR(32bit).
The second timeout period is determined by ...
drivers/watchdog/sbsa_gwdt.c line 27
Quoted 3 lines
drivers/watchdog/sbsa_gwdt.c new file +3
-0+* WOR gives a maximum watch period of around 10s at the maximum +* system counter frequency. +* The System Counter shall run at maximum of 400MHz.
"... at the maximum system counter frequency of 400 MHz.", and drop the last sentence.
Please uses spaces before '('.
drivers/watchdog/sbsa_gwdt.c line 29
Quoted 2 lines
drivers/watchdog/sbsa_gwdt.c new file +2
-0+* +* But If we need a larger timeout period, this driver will programme WCV
s/But //
s/this/the/
s/programme/program/
drivers/watchdog/sbsa_gwdt.c line 31
Quoted 2 lines
drivers/watchdog/sbsa_gwdt.c new file +2
-0+* directly. That can support more than 10s timeout at the maximum +* system counter frequency.
Drop the last sentence.
Quoted 102 lines
drivers/watchdog/sbsa_gwdt.c new file +102
-0+* More details: ARM DEN0029B - Server Base System Architecture (SBSA) +* +* SBSA GWDT: |---WOR(or WCV)---WS0---WOR(or WCV)---WS1 +* |-----timeout-----WS0-----timeout-----WS1 +*/ + +#include <linux/io.h> +#include <linux/interrupt.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/of.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/uaccess.h> +#include <linux/watchdog.h> +#include <asm/arch_timer.h> + +/* SBSA Generic Watchdog register definitions */ +/* refresh frame */ +#define SBSA_GWDT_WRR 0x000 + +/* control frame */ +#define SBSA_GWDT_WCS 0x000 +#define SBSA_GWDT_WOR 0x008 +#define SBSA_GWDT_WCV_LO 0x010 +#define SBSA_GWDT_WCV_HI 0x014 + +/* refresh/control frame */ +#define SBSA_GWDT_W_IIDR 0xfcc +#define SBSA_GWDT_IDR 0xfd0 + +/* Watchdog Control and Status Register */ +#define SBSA_GWDT_WCS_EN BIT(0) +#define SBSA_GWDT_WCS_WS0 BIT(1) +#define SBSA_GWDT_WCS_WS1 BIT(2) + +/** +* struct sbsa_gwdt - Internal representation of the SBSA GWDT +* @wdd: kernel watchdog_device structure +* @clk: store the System Counter clock frequency, in Hz. +* @max_wor_timeout: the maximum timeout value for WOR (in seconds). +* @refresh_base: Virtual address of the watchdog refresh frame +* @control_base: Virtual address of the watchdog control frame +*/ +struct sbsa_gwdt { +struct watchdog_device wdd; +u32 clk; +int max_wor_timeout; +void __iomem *refresh_base; +void __iomem *control_base; +}; + +#define to_sbsa_gwdt (e) container_of(e, struct sbsa_gwdt, wdd) + +#define DEFAULT_TIMEOUT 30/* seconds */ + +static unsigned int timeout; +module_param (timeout, uint,0 ); +MODULE_PARM_DESC (timeout, + "Watchdog timeout in seconds. (>=0, default=" + __MODULE_STRING(DEFAULT_TIMEOUT) ")"); + +static bool nowayout =WATCHDOG_NOWAYOUT ; +module_param (nowayout, bool,S_IRUGO ); +MODULE_PARM_DESC (nowayout, + "Watchdog cannot be stopped once started (default=" + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +/* +* help functions for accessing 64bit WCV register +*/ +static u64 sbsa_gwdt_get_wcv (struct watchdog_device *wdd) +{ +u32 wcv_lo, wcv_hi; +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +do { + wcv_hi =readl_relaxed (gwdt->control_base +SBSA_GWDT_WCV_HI ); + wcv_lo =readl_relaxed (gwdt->control_base +SBSA_GWDT_WCV_LO ); + }while (wcv_hi !=readl_relaxed (gwdt->control_base + +SBSA_GWDT_WCV_HI )); + +return (((u64 )wcv_hi <<32 ) | wcv_lo); +} + +static void reload_timeout_to_wcv (struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); +u64 wcv; + + wcv =arch_counter_get_cntvct () + (u64 )wdd->timeout * gwdt->clk; + +writel_relaxed (upper_32_bits (wcv), + gwdt->control_base +SBSA_GWDT_WCV_HI ); +writel_relaxed (lower_32_bits (wcv), + gwdt->control_base +SBSA_GWDT_WCV_LO ); +} + +static int sbsa_gwdt_set_timeout (struct watchdog_device *wdd, +unsigned int timeout) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd);
drivers/watchdog/sbsa_gwdt.c line 143
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+ + wdd->timeout = timeout; + +if (timeout <= gwdt->max_wor_timeout) +writel_relaxed (timeout * gwdt->clk, + gwdt->control_base +SBSA_GWDT_WOR ); +else +writel_relaxed (gwdt->max_wor_timeout * gwdt->clk, + gwdt->control_base +SBSA_GWDT_WOR ); +
This can be simplified a bit to
if (timeout > gwdt->max_wor_timeout) timeout = gwdt->max_wor_timeout; writel_relaxed(timeout * gwdt->clk, gwdt->control_base + SBSA_GWDT_WOR);
Quoted 23 lines
drivers/watchdog/sbsa_gwdt.c new file +23
-0+return 0 ; +} + +static unsigned int sbsa_gwdt_get_timeleft (struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); +u64 timeleft =sbsa_gwdt_get_wcv (wdd) -arch_counter_get_cntvct (); + +do_div (timeleft, gwdt->clk); + +return timeleft; +} + +static int sbsa_gwdt_keepalive (struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +if (wdd->timeout <= gwdt->max_wor_timeout) +/* +* Writing WRR for an explicit watchdog refresh. +* You can write anyting(like 0xc0ffee). +*/ +writel_relaxed (0xc0ffee , gwdt->refresh_base +SBSA_GWDT_WRR );
drivers/watchdog/sbsa_gwdt.c line 176
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+else +reload_timeout_to_wcv (wdd); + +return 0 ; +} + +static int sbsa_gwdt_start (struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); +/* Force refresh due to hardware bug found in certain Soc. */
Can you specify which SOC(s) are known to need this, and explain the bug a bit better ?
Quoted 14 lines
drivers/watchdog/sbsa_gwdt.c new file +14
-0+writel_relaxed (0xc0ffee , gwdt->refresh_base +SBSA_GWDT_WRR ); +/* writing WCS will cause an explicit watchdog refresh */ +writel_relaxed (SBSA_GWDT_WCS_EN , gwdt->control_base +SBSA_GWDT_WCS ); + +return sbsa_gwdt_keepalive (wdd); +} + +static int sbsa_gwdt_stop (struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (0 , gwdt->control_base +SBSA_GWDT_WCS ); + +return 0 ;
drivers/watchdog/sbsa_gwdt.c line 200
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+} + +static irqreturn_t sbsa_gwdt_interrupt (int irq,void *dev_id) +{ +struct sbsa_gwdt *gwdt = (struct sbsa_gwdt *)dev_id; +struct watchdog_device *wdd = &gwdt->wdd; + +if (wdd->timeout > gwdt->max_wor_timeout) +reload_timeout_to_wcv (wdd); +
Please drop the above.
Quoted 72 lines
drivers/watchdog/sbsa_gwdt.c new file +72
-0+panic ("SBSA Watchdog pre-timeout" ); + +return IRQ_HANDLED ; +} + +static struct watchdog_info sbsa_gwdt_info = { + .identity ="SBSA Generic Watchdog" , + .options =WDIOF_SETTIMEOUT | +WDIOF_KEEPALIVEPING | +WDIOF_MAGICCLOSE | +WDIOF_CARDRESET , +}; + +static struct watchdog_ops sbsa_gwdt_ops = { + .owner =THIS_MODULE , + .start = sbsa_gwdt_start, + .stop = sbsa_gwdt_stop, + .ping = sbsa_gwdt_keepalive, + .set_timeout = sbsa_gwdt_set_timeout, + .get_timeleft = sbsa_gwdt_get_timeleft, +}; + +static int sbsa_gwdt_probe (struct platform_device *pdev) +{ +u64 first_period_max =U64_MAX ; +struct device *dev = &pdev->dev; +struct watchdog_device *wdd; +struct sbsa_gwdt *gwdt; +struct resource *res; +void *rf_base, *cf_base; +int ret, irq; +u32 status; + + gwdt =devm_kzalloc (dev,sizeof (*gwdt),GFP_KERNEL ); +if (!gwdt) +return -ENOMEM ; +platform_set_drvdata (pdev, gwdt); + + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"refresh" ); + rf_base =devm_ioremap_resource (dev, res); +if (IS_ERR (rf_base)) +return PTR_ERR (rf_base); + + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"control" ); + cf_base =devm_ioremap_resource (dev, res); +if (IS_ERR (cf_base)) +return PTR_ERR (cf_base); + + irq =platform_get_irq_byname (pdev,"ws0" ); +if (irq <0 ) { +dev_err (dev,"unable to get ws0 interrupt.\n" ); +return irq; + } + +/* +* Get the frequency of system counter from the cp15 interface of ARM +* Generic timer. We don't need to check it, because if it returns "0", +* system would panic in very early stage. +*/ + gwdt->clk =arch_timer_get_cntfrq (); + gwdt->refresh_base = rf_base; + gwdt->control_base = cf_base; + gwdt->max_wor_timeout =U32_MAX / gwdt->clk; + + wdd = &gwdt->wdd; + wdd->parent = dev; + wdd->info = &sbsa_gwdt_info; + wdd->ops = &sbsa_gwdt_ops; +watchdog_set_drvdata (wdd, gwdt); +watchdog_set_nowayout (wdd, nowayout); + + wdd->min_timeout =1 ;
drivers/watchdog/sbsa_gwdt.c line 282
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+do_div (first_period_max, gwdt->clk); + wdd->max_timeout = first_period_max; + + wdd->timeout =DEFAULT_TIMEOUT ; +watchdog_init_timeout (wdd, timeout, dev); + + status =readl_relaxed (gwdt->control_base +SBSA_GWDT_WCS ); +if (status &SBSA_GWDT_WCS_WS1 ) { +dev_warn (dev,"System reset by WDT(WCV: %llx)\n" , +sbsa_gwdt_get_wcv (wdd));
WCV here only tells us how many clock cycles were executed since the system started (or something like that). So I still don't understand why it is valuable to print that number.
drivers/watchdog/sbsa_gwdt.c line 289
Quoted 7 lines
drivers/watchdog/sbsa_gwdt.c new file +7
-0+ wdd->bootstatus |=WDIOF_CARDRESET ; + } +/* Check if watchdog is already enabled */ +if (status &SBSA_GWDT_WCS_EN ) { +dev_warn (dev,"already enabled\n" ); +sbsa_gwdt_keepalive (wdd); + }
Can you merge the message with the info message below ? Something like
dev_info(dev, "Initialized with %ds timeout @ %u Hz%s\n", wdd->timeout, gwdt->clk, status & SBSA_GWDT_WCS_EN ? " [enabled]" : "");
I don't think that should be a warning.
drivers/watchdog/sbsa_gwdt.c line 293
Quoted 4 lines
drivers/watchdog/sbsa_gwdt.c new file +4
-0+ +/* update timeout to WOR */ +sbsa_gwdt_set_timeout (wdd, wdd->timeout); +
That will trigger a refresh if the watchdog is active, meaning the timeout will occur at time + WOR, not at time + timeout. I think keepalive has to be called later, preferrably after calling watchdog_register_device().
Quoted 77 lines
drivers/watchdog/sbsa_gwdt.c new file +77
-0+ ret =devm_request_irq (dev, irq, sbsa_gwdt_interrupt,0 , + pdev->name, gwdt); +if (ret) { +dev_err (dev,"unable to request IRQ %d\n" , irq); +return ret; + } + + ret =watchdog_register_device (wdd); +if (ret) +return ret; + +dev_info (dev,"Initialized with %ds timeout @ %u Hz\n" , wdd->timeout, + gwdt->clk); + +return 0 ; +} + +static void sbsa_gwdt_shutdown (struct platform_device *pdev) +{ +struct sbsa_gwdt *gwdt =platform_get_drvdata (pdev); + +sbsa_gwdt_stop (&gwdt->wdd); +} + +static int sbsa_gwdt_remove (struct platform_device *pdev) +{ +struct sbsa_gwdt *gwdt =platform_get_drvdata (pdev); + +watchdog_unregister_device (&gwdt->wdd); + +return 0 ; +} + +/* Disable watchdog if it is active during suspend */ +static int __maybe_unused sbsa_gwdt_suspend (struct device *dev) +{ +struct sbsa_gwdt *gwdt =dev_get_drvdata (dev); + +if (watchdog_active (&gwdt->wdd)) +sbsa_gwdt_stop (&gwdt->wdd); + +return 0 ; +} + +/* Enable watchdog and configure it if necessary */ +static int __maybe_unused sbsa_gwdt_resume (struct device *dev) +{ +struct sbsa_gwdt *gwdt =dev_get_drvdata (dev); + +if (watchdog_active (&gwdt->wdd)) +sbsa_gwdt_start (&gwdt->wdd); + +return 0 ; +} + +static const struct dev_pm_ops sbsa_gwdt_pm_ops = { +SET_SYSTEM_SLEEP_PM_OPS (sbsa_gwdt_suspend, sbsa_gwdt_resume) +}; + +static const struct of_device_id sbsa_gwdt_of_match[] = { + { .compatible ="arm,sbsa-gwdt" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, sbsa_gwdt_of_match); + +static const struct platform_device_id sbsa_gwdt_pdev_match[] = { + { .name ="sbsa-gwdt" , }, + {}, +}; +MODULE_DEVICE_TABLE (platform, sbsa_gwdt_pdev_match); + +static struct platform_driver sbsa_gwdt_driver = { + .driver = { + .name ="sbsa-gwdt" , + .pm = &sbsa_gwdt_pm_ops, + .of_match_table = sbsa_gwdt_of_match, + },
drivers/watchdog/sbsa_gwdt.c line 380
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+ .probe = sbsa_gwdt_probe, + .remove = sbsa_gwdt_remove, + .shutdown = sbsa_gwdt_shutdown, + .id_table = sbsa_gwdt_pdev_match, +}; + +module_platform_driver (sbsa_gwdt_driver); + +MODULE_DESCRIPTION ("SBSA Generic Watchdog Driver" ); +MODULE_VERSION ("v1.0" );
Version numbers tend to be out of date constantly, and there is no well defined mechanism or protocol when increase them. I would suggest to drop it.
Quoted 3 lines
drivers/watchdog/sbsa_gwdt.c new file +3
-0+MODULE_AUTHOR ("Fu Wei <[email protected]>" ); +MODULE_AUTHOR ("Suravee Suthikulpanit <[email protected]>" ); +MODULE_LICENSE ("GPL v2" );
Guenter Roeck
maintainerRe: [PATCH v5 4/8] Watchdog: introdouce "pretimeout" into framework
In reply to Fu WeiQuoted 2 lines · Fu Wei
Hi Guenter,
[ ... ]
Quoted 11 lines
Quoted 11 lines
value we are trying to set. Effectively the above accepts every pretimeout if
wdd->pretimeoutis 0. It also accepts every pretimeout ifmax_pretimeout== 0, even ifwdd->timeoutis set and t >=wdd->timeout.Try
return (wdd->max_pretimeout && (t < wdd->min_pretimeout || t > wdd->max_pretimeout)) || (wdd->timeout && t >= wdd->timeout);
Quoted 6 lines
Quoted 1 line
Quoted 1 line
}/*
* Use the following function to check if a pretimeout value is invalid.
* It can be "0", that means we don't use pretimeout.
* This function returns 0, when pretimeout is 0.
returns false if pretimeout is 0.
Quoted 9 lines
*/
static inline bool watchdog_pretimeout_invalid(structwatchdog_device*wdd,
unsigned int t){ return t && (wdd->max_pretimeout && (t < wdd->min_pretimeout || t > wdd->max_pretimeout)) || (wdd->timeout && t >= wdd->timeout); }
Makes sense. Be careful with (), though. This evaluates to
return t && (...) || (wdd->timeout && t >= wdd->timeout);
but it should probably be
return t && ((...) || (wdd->timeout && t >= wdd->timeout));
That doesn't make a difference in practice (if t == 0, it is never >= timeout if timeout is > 0), but it would be a bit cleaner.
Quoted 27 lines
Quoted 8 lines
Quoted 8 lines
/* Use the following functions to manipulate watchdog driver specific
data */(quoted diff) +0
-0@@ -132,11 +153,20 @@ static inline void *watchdog_get_drvdata(struct watchdog_device *wdd) }Quoted 11 lines
include/linux/watchdog.h static inline void *watchdog_get_drvdata(struct watchdog_device *wdd) · line 159
Quoted 8 lines
include/linux/watchdog.h +4
-2/* drivers/watchdog/watchdog_core.c */ -extern int watchdog_init_timeout (struct watchdog_device *wdd, -unsigned int timeout_parm,struct device *dev); +int watchdog_init_timeouts (struct watchdog_device *wdd, +unsigned int pretimeout_parm, +unsigned int timeout_parm, +struct device *dev);Please align continuation lines with '('.
Fixed , thanks
Quoted 5 lines
Quoted 5 lines
include/linux/watchdog.h +0
-0extern int watchdog_register_device (struct watchdog_device *);extern void watchdog_unregister_device (struct watchdog_device *);
Quoted 26 lines
Quoted 12 lines
Quoted 11 lines
include/linux/watchdog.h +7
-0+static inline int watchdog_init_timeout (struct watchdog_device *wdd, +unsigned int timeout_parm, +struct device *dev) +{ +return watchdog_init_timeouts (wdd,0 , timeout_parm, dev); +} +#ifdef CONFIG_HARDLOCKUP_DETECTOR void watchdog_nmi_disable_all(void); void watchdog_nmi_enable_all(void);Signature · 10 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH non-pretimeout 4/7] Watchdog: introduce ARM SBSA watchdog driver
In reply to [email protected]drivers/watchdog/sbsa_gwdt.c line 142
Quoted 6 lines · [email protected] wrote:
drivers/watchdog/sbsa_gwdt.c new file +6
-0+if (timeout <= gwdt->max_wor_timeout) +writel_relaxed (timeout * gwdt->clk, + gwdt->control_base +SBSA_GWDT_WOR ); +else +writel_relaxed (gwdt->max_wor_timeout * gwdt->clk, + gwdt->control_base +SBSA_GWDT_WOR );
You pre-calculate the maximum timeout possible already, so why do you need the if-statement?
Frankly, your non-pretimeout driver is almost identical to mine, which was posted weeks ago. At this point, you're really just copying my driver but putting your name on it.
Signature · 7 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation. -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH non-pretimeout 6/7] Watchdog: enable ACPI GTDT support for ARM SBSA watchdog driver
In reply to [email protected]Quoted 2 lines · [email protected] wrote:
This patch enables ACPI GTDT support for ARM SBSA watchdog driver automatically, if ACPI support is enabled.
You don't need this patch if you reorder your patches, like this:
#4 ACPI: add GTDT table parse driver into ACPI driver #5 Watchdog: introduce ARM SBSA watchdog driver
And then this patch becomes part of patch #5.
Signature · 3 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.
Re: [PATCH non-pretimeout 3/7] ARM64: add SBSA Generic Watchdog device node in amd-seattle-soc.dtsi
In reply to [email protected]arch/arm64/boot/dts/amd/amd-seattle-soc.dtsi line 90
Quoted 2 lines · On 06/10/2015 12:47 PM, [email protected] wrote:
arch/arm64/boot/dts/amd/amd-seattle-soc.dtsi +2
-0+ reg = <0x0 0xe0bb0000 0 0x10000>, + <0x0 0xe0bc0000 0 0x10000>;
I think the sizes are wrong. They should be 0x1000 instead of 0x10000.
Signature · 7 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project. -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH non-pretimeout 3/7] ARM64: add SBSA Generic Watchdog device node in amd-seattle-soc.dtsi
Quoted 7 lines · Timur Tabi
arch/arm64/boot/dts/amd/amd-seattle-soc.dtsi line 90
Quoted 3 lines · On 06/10/2015 12:47 PM, [email protected] wrote:
arch/arm64/boot/dts/amd/amd-seattle-soc.dtsi +2
-0+ reg = <0x0 0xe0bb0000 0 0x10000>, + <0x0 0xe0bc0000 0 0x10000>;I think the sizes are wrong. They should be
0x1000instead of0x10000.
This has been proved by test, it works well on Seattle Foundation model has same value. So I don't think it is wrong
otherwise someone has the data sheet of Seattle B0, and it shows that is wrong.
Quoted 5 lines
--
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Signature · 10 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021
Re: [PATCH non-pretimeout 4/7] Watchdog: introduce ARM SBSA watchdog driver
In reply to Timur TabiHi Timur
Quoted 10 lines · Timur Tabi
drivers/watchdog/sbsa_gwdt.c line 142
Quoted 7 lines · [email protected] wrote:
drivers/watchdog/sbsa_gwdt.c new file +6
-0+if (timeout <= gwdt->max_wor_timeout) +writel_relaxed (timeout * gwdt->clk, + gwdt->control_base +SBSA_GWDT_WOR ); +else +writel_relaxed (gwdt->max_wor_timeout * gwdt->clk, + gwdt->control_base +SBSA_GWDT_WOR );
Quoted 2 lines
You pre-calculate the maximum timeout possible already, so why do you need the if-statement?
Have took Guenter's suggestion on this.
Quoted 4 lines
Frankly, your non-pretimeout driver is almost identical to mine, which was posted weeks ago. At this point, you're really just copying my driver but putting your name on it.
Everyone can see how this driver become to this one gradually. For non-pretimeout, if there is not pretimeout variable, I can only use timeout to config both of them.
This is definitely not the copy of yours(check yours again, you never programme WCV, and from the comment from you , you didn't believe driver can do that. you use panic because of my patch), and I posted my patchset(with pretimeout) to linaro-acpi list before you posted yours to linux mailing list. And I always focus on mine.
Let people judge from all these patchset, I don't want to argue with you on this any more.
Quoted 6 lines
--
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.
Signature · 14 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH non-pretimeout 3/7] ARM64: add SBSA Generic Watchdog device node in amd-seattle-soc.dtsi
In reply to Fu WeiQuoted 5 lines · Fu Wei
Quoted 1 line
Quoted 1 line
I think the sizes are wrong. They should be
0x1000instead of0x10000.This has been proved by test, it works well on Seattle Foundation model has same value. So I don't think it is wrong
otherwise someone has the data sheet of Seattle B0, and it shows that is wrong.
The registers block is only 0x1000 bytes long. So you're wasting 63KB of virtual address space for each block.
Signature · 7 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation. -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Guenter Roeck
maintainerRe: [PATCH non-pretimeout 3/7] ARM64: add SBSA Generic Watchdog device node in amd-seattle-soc.dtsi
In reply to Fu WeiQuoted 7 lines · Fu Wei
Quoted 6 lines · Timur Tabi
Quoted 3 lines · On 06/10/2015 12:47 PM, [email protected] wrote:
arch/arm64/boot/dts/amd/amd-seattle-soc.dtsi +2
-0+ reg = <0x0 0xe0bb0000 0 0x10000>, + <0x0 0xe0bc0000 0 0x10000>;
Quoted 7 lines
Quoted 1 line
I think the sizes are wrong. They should be
0x1000instead of0x10000.This has been proved by test, it works well on Seattle Foundation model has same value. So I don't think it is wrong
otherwise someone has the data sheet of Seattle B0, and it shows that is wrong.
If only 0x1000 is used, why would you have to reserve 0x10000 ? You never access any higher addresses, so no matter what the datasheet says, 0x1000 should be sufficient. What matters is what the driver uses.
Guenter
Re: [PATCH non-pretimeout 3/7] ARM64: add SBSA Generic Watchdog device node in amd-seattle-soc.dtsi
Hi Guenter,
Quoted 18 lines · Guenter Roeck
Quoted 17 lines · Fu Wei
Quoted 10 lines · Timur Tabi
arch/arm64/boot/dts/amd/amd-seattle-soc.dtsi line 90
Quoted 4 lines · On 06/10/2015 12:47 PM, [email protected] wrote:
arch/arm64/boot/dts/amd/amd-seattle-soc.dtsi +2
-0+ reg = <0x0 0xe0bb0000 0 0x10000>, + <0x0 0xe0bc0000 0 0x10000>;I think the sizes are wrong. They should be
0x1000instead of0x10000.This has been proved by test, it works well on Seattle Foundation model has same value. So I don't think it is wrong
Quoted 7 lines
Quoted 3 lines
otherwise someone has the data sheet of Seattle B0, and it shows that is wrong.
If only
0x1000is used, why would you have to reserve0x10000? You never access any higher addresses, so no matter what the datasheet says,0x1000should be sufficient. What matters is what the driver uses.
the reason for using 0x10000 before is :
(1)in <ARM v8-A Foundation Platform User Guide(Version: 9.1)> page 20 0x00_2A44_0000 0x00_2A44_FFFF - EL2 Generic Watchdog Control 64KB S/NS 0x00_2A45_0000 0x00_2A45_FFFF - EL2 Generic Watchdog Refresh 64KB S/NS (2)It is also confirmed by Suravee, in Seattle, the size is 64KB also.
(3) these configuration has passed the test in Foundation model and Seattle B0.
Not sure the reason, maybe because of the 64KB page size.
But, yes, in SBSA, the device only has 4KB register area, and the driver only need to use 4KB.
So you are right, "What matters is what the driver uses." , so will use 0x1000. I think there is not problem, because ACPI uses this size.
Quoted 4 lines
Guenter
Signature · 10 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021
Re: [non-pretimeout,4/7] Watchdog: introduce ARM SBSA watchdog driver
In reply to Guenter RoeckHi Guenter,
Quoted 31 lines · Guenter Roeck
Quoted 9 lines · On Thu, Jun 11, 2015 at 01:47:29AM +0800, [email protected] wrote:
From: Fu Wei <[email protected]>
This driver bases on linux kernel watchdog framework. It supports getting timeout from parameter and FDT at the driver init stage.
The first timeout period expires, the interrupt routine got another timeout period to run panic for saving system context.Comments inline.
Thanks,
GuenterQuoted 16 lines
Signed-off-by Fu Wei <[email protected]>--- drivers/watchdog/Kconfig | 11 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/sbsa_gwdt.c | 383 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 395 insertions(+) create mode 100644 drivers/watchdog/sbsa_gwdt.cdrivers/watchdog/Kconfig +0
-0@@ -152,6 +152,17 @@ config ARM_SP805_WATCHDOG ARM Primecell SP805 Watchdog timer. This will reboot your system when the timeout is reached.
Quoted 13 lines
drivers/watchdog/Kconfig config ARM_SP805_WATCHDOG · line 165
Quoted 11 lines
drivers/watchdog/Kconfig +11
-0+config ARM_SBSA_WATCHDOG + tristate "ARM SBSA Generic Watchdog" + depends on ARM64 + depends on ARM_ARCH_TIMER + select WATCHDOG_CORE + help + ARM SBSA Generic Watchdog. This watchdog has two Watchdog timeouts. + The first timeout will trigger a panic; the second timeout will + trigger a system reset. + More details: ARM DEN0029B - Server Base System Architecture (SBSA) +To compile this driver as module, choose M here: The module will be called
sbsa_gwdt.
Thanks! added it.
Quoted 42 lines
Quoted 29 lines
drivers/watchdog/Kconfig +0
-0config AT91RM9200_WATCHDOG tristate "AT91RM9200 watchdog" depends on SOC_AT91RM9200 && MFD_SYSCONdrivers/watchdog/Makefile +1
-0@@ -30,6 +30,7 @@ obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o # ARM Architecture obj-$(CONFIG_ARM_SP805_WATCHDOG) += sp805_wdt.o +obj-$(CONFIG_ARM_SBSA_WATCHDOG) += sbsa_gwdt.o obj-$(CONFIG_AT91RM9200_WATCHDOG) += at91rm9200_wdt.o obj-$(CONFIG_AT91SAM9X_WATCHDOG) += at91sam9_wdt.o obj-$(CONFIG_CADENCE_WATCHDOG) += cadence_wdt.odrivers/watchdog/sbsa_gwdt.c new file +7
-0@@ -0,0 +1,383 @@ +/* +* SBSA(Server Base System Architecture) Generic Watchdog driver +* +* Copyright (c) 2015, Linaro Ltd. +* Author: Fu Wei <[email protected]> +* Suravee Suthikulpanit <[email protected]> +* drivers/watchdog/sbsa_gwdt.c line 17
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License 2 as published +* by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* Note: This SBSA Generic watchdog has two stage timeouts, s/This/The/
Quoted 3 lines
"has two stages".
I would suggest to drop "Note:", but that is up to you.
Thanks :-) fixed it
Quoted 12 lines
drivers/watchdog/sbsa_gwdt.c line 19
Quoted 3 lines
drivers/watchdog/sbsa_gwdt.c new file +2
-0+* When the first timeout occurs, WS0(SPI or LPI) is triggered, +* the second timeout period(as long as the first timeout period) starts. no longer accurate if WOR is used for the second period.
drivers/watchdog/sbsa_gwdt.c line 24
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +5
-0+* In WS0 interrupt routine, panic() will be called for collecting +* crashdown info. +* If system can not recover from WS0 interrupt routine, then second +* timeout occurs, WS1(reset or higher level interrupt) is triggered. +* The two timeout period can be set by WOR(32bit).
Quoted 8 lines
The second timeout period is determined by ...
drivers/watchdog/sbsa_gwdt.c line 27
Quoted 3 lines
drivers/watchdog/sbsa_gwdt.c new file +3
-0+* WOR gives a maximum watch period of around 10s at the maximum +* system counter frequency. +* The System Counter shall run at maximum of 400MHz. "... at the maximum system counter frequency of 400 MHz.", and drop the last sentence.
For the second timeout period, I have discussed with a kdump developers, (1)10s maybe not good enough for all the case of panic + kdump, so maybe we still need to use WCV in the second timeout period (2)in the second timeout period, maybe we need to programme WCV for two reason: a, trigger WS1 to reboot system ASAP; b, feed the watchdog without cleanning WS0 flag.
WHY we want to feed the watchdog (keepalive) without cleanning WS0 flag?? REASON:
(1)if the system context is large, we may need to feed the dog until we get all the things backed up.
(2)if system goes wrong, WS0 triggered, then panic--> kdump. if we feed the dog by WRR or programming WOR, WS0 flag will be cleaned. Once system goes wrong again, then panic again.....
So this system will be in a panic--kdump--panic--kdump loop, have not chance to reset.
So if we are in the second timeout period, we may need to always programme WCV.
Quoted 6 lines
Please uses spaces before '('.
drivers/watchdog/sbsa_gwdt.c line 29
Quoted 2 lines
drivers/watchdog/sbsa_gwdt.c new file +2
-0+* +* But If we need a larger timeout period, this driver will programme WCV
Quoted 8 lines
s/But //
s/this/the/
s/programme/program/drivers/watchdog/sbsa_gwdt.c line 31
Quoted 2 lines
drivers/watchdog/sbsa_gwdt.c new file +2
-0+* directly. That can support more than 10s timeout at the maximum +* system counter frequency. Drop the last sentence.
Thanks , fixed it
Quoted 115 lines
Quoted 103 lines
drivers/watchdog/sbsa_gwdt.c new file +102
-0+* More details: ARM DEN0029B - Server Base System Architecture (SBSA) +* +* SBSA GWDT: |---WOR(or WCV)---WS0---WOR(or WCV)---WS1 +* |-----timeout-----WS0-----timeout-----WS1 +*/ + +#include <linux/io.h> +#include <linux/interrupt.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/of.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/uaccess.h> +#include <linux/watchdog.h> +#include <asm/arch_timer.h> + +/* SBSA Generic Watchdog register definitions */ +/* refresh frame */ +#define SBSA_GWDT_WRR 0x000 + +/* control frame */ +#define SBSA_GWDT_WCS 0x000 +#define SBSA_GWDT_WOR 0x008 +#define SBSA_GWDT_WCV_LO 0x010 +#define SBSA_GWDT_WCV_HI 0x014 + +/* refresh/control frame */ +#define SBSA_GWDT_W_IIDR 0xfcc +#define SBSA_GWDT_IDR 0xfd0 + +/* Watchdog Control and Status Register */ +#define SBSA_GWDT_WCS_EN BIT(0) +#define SBSA_GWDT_WCS_WS0 BIT(1) +#define SBSA_GWDT_WCS_WS1 BIT(2) + +/** +* struct sbsa_gwdt - Internal representation of the SBSA GWDT +* @wdd: kernel watchdog_device structure +* @clk: store the System Counter clock frequency, in Hz. +* @max_wor_timeout: the maximum timeout value for WOR (in seconds). +* @refresh_base: Virtual address of the watchdog refresh frame +* @control_base: Virtual address of the watchdog control frame +*/ +struct sbsa_gwdt { +struct watchdog_device wdd; +u32 clk; +int max_wor_timeout; +void __iomem *refresh_base; +void __iomem *control_base; +}; + +#define to_sbsa_gwdt (e) container_of(e, struct sbsa_gwdt, wdd) + +#define DEFAULT_TIMEOUT 30/* seconds */ + +static unsigned int timeout; +module_param (timeout, uint,0 ); +MODULE_PARM_DESC (timeout, + "Watchdog timeout in seconds. (>=0, default=" + __MODULE_STRING(DEFAULT_TIMEOUT) ")"); + +static bool nowayout =WATCHDOG_NOWAYOUT ; +module_param (nowayout, bool,S_IRUGO ); +MODULE_PARM_DESC (nowayout, + "Watchdog cannot be stopped once started (default=" + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +/* +* help functions for accessing 64bit WCV register +*/ +static u64 sbsa_gwdt_get_wcv (struct watchdog_device *wdd) +{ +u32 wcv_lo, wcv_hi; +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +do { + wcv_hi =readl_relaxed (gwdt->control_base +SBSA_GWDT_WCV_HI ); + wcv_lo =readl_relaxed (gwdt->control_base +SBSA_GWDT_WCV_LO ); + }while (wcv_hi !=readl_relaxed (gwdt->control_base + +SBSA_GWDT_WCV_HI )); + +return (((u64 )wcv_hi <<32 ) | wcv_lo); +} + +static void reload_timeout_to_wcv (struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); +u64 wcv; + + wcv =arch_counter_get_cntvct () + (u64 )wdd->timeout * gwdt->clk; + +writel_relaxed (upper_32_bits (wcv), + gwdt->control_base +SBSA_GWDT_WCV_HI ); +writel_relaxed (lower_32_bits (wcv), + gwdt->control_base +SBSA_GWDT_WCV_LO ); +} + +static int sbsa_gwdt_set_timeout (struct watchdog_device *wdd, +unsigned int timeout) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd);drivers/watchdog/sbsa_gwdt.c line 143
Quoted 10 lines
drivers/watchdog/sbsa_gwdt.c new file +10
-0+ + wdd->timeout = timeout; + +if (timeout <= gwdt->max_wor_timeout) +writel_relaxed (timeout * gwdt->clk, + gwdt->control_base +SBSA_GWDT_WOR ); +else +writel_relaxed (gwdt->max_wor_timeout * gwdt->clk, + gwdt->control_base +SBSA_GWDT_WOR ); +This can be simplified a bit to
Quoted 4 lines
if (timeout > gwdt->max_wor_timeout)
timeout = gwdt->max_wor_timeout;
writel_relaxed(timeout * gwdt->clk,
gwdt->control_base + SBSA_GWDT_WOR);yes, good idea, thanks , fixed
Quoted 29 lines
Quoted 29 lines
drivers/watchdog/sbsa_gwdt.c new file +28
-0+return 0 ; +} + +static unsigned int sbsa_gwdt_get_timeleft (struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); +u64 timeleft =sbsa_gwdt_get_wcv (wdd) -arch_counter_get_cntvct (); + +do_div (timeleft, gwdt->clk); + +return timeleft; +} + +static int sbsa_gwdt_keepalive (struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +if (wdd->timeout <= gwdt->max_wor_timeout) +/* +* Writing WRR for an explicit watchdog refresh. +* You can write anyting(like 0xc0ffee). +*/ +writel_relaxed (0xc0ffee , gwdt->refresh_base +SBSA_GWDT_WRR ); +else +reload_timeout_to_wcv (wdd); + +return 0 ; +}
Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c line 176
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +5
-0+ +static int sbsa_gwdt_start (struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); +/* Force refresh due to hardware bug found in certain Soc. */ Can you specify which SOC(s) are known to need this, and explain the bug a bit better ?
please ignore this, I have deleted it after discussing this with the engineer of that chip vendor.
we don't need it now.
Quoted 18 lines
Quoted 18 lines
drivers/watchdog/sbsa_gwdt.c new file +17
-0+writel_relaxed (0xc0ffee , gwdt->refresh_base +SBSA_GWDT_WRR ); +/* writing WCS will cause an explicit watchdog refresh */ +writel_relaxed (SBSA_GWDT_WCS_EN , gwdt->control_base +SBSA_GWDT_WCS ); + +return sbsa_gwdt_keepalive (wdd); +} + +static int sbsa_gwdt_stop (struct watchdog_device *wdd) +{ +struct sbsa_gwdt *gwdt =to_sbsa_gwdt (wdd); + +writel_relaxed (0 , gwdt->control_base +SBSA_GWDT_WCS ); + +return 0 ; +} + +static irqreturn_t sbsa_gwdt_interrupt (int irq,void *dev_id)
Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c line 200
Quoted 7 lines
drivers/watchdog/sbsa_gwdt.c new file +7
-0+{ +struct sbsa_gwdt *gwdt = (struct sbsa_gwdt *)dev_id; +struct watchdog_device *wdd = &gwdt->wdd; + +if (wdd->timeout > gwdt->max_wor_timeout) +reload_timeout_to_wcv (wdd); +Please drop the above.
as I mentioned above, I thinks we can keep this.
But please check my new patchset for this support
Quoted 79 lines
Quoted 79 lines
drivers/watchdog/sbsa_gwdt.c new file +78
-0+panic ("SBSA Watchdog pre-timeout" ); + +return IRQ_HANDLED ; +} + +static struct watchdog_info sbsa_gwdt_info = { + .identity ="SBSA Generic Watchdog" , + .options =WDIOF_SETTIMEOUT | +WDIOF_KEEPALIVEPING | +WDIOF_MAGICCLOSE | +WDIOF_CARDRESET , +}; + +static struct watchdog_ops sbsa_gwdt_ops = { + .owner =THIS_MODULE , + .start = sbsa_gwdt_start, + .stop = sbsa_gwdt_stop, + .ping = sbsa_gwdt_keepalive, + .set_timeout = sbsa_gwdt_set_timeout, + .get_timeleft = sbsa_gwdt_get_timeleft, +}; + +static int sbsa_gwdt_probe (struct platform_device *pdev) +{ +u64 first_period_max =U64_MAX ; +struct device *dev = &pdev->dev; +struct watchdog_device *wdd; +struct sbsa_gwdt *gwdt; +struct resource *res; +void *rf_base, *cf_base; +int ret, irq; +u32 status; + + gwdt =devm_kzalloc (dev,sizeof (*gwdt),GFP_KERNEL ); +if (!gwdt) +return -ENOMEM ; +platform_set_drvdata (pdev, gwdt); + + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"refresh" ); + rf_base =devm_ioremap_resource (dev, res); +if (IS_ERR (rf_base)) +return PTR_ERR (rf_base); + + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"control" ); + cf_base =devm_ioremap_resource (dev, res); +if (IS_ERR (cf_base)) +return PTR_ERR (cf_base); + + irq =platform_get_irq_byname (pdev,"ws0" ); +if (irq <0 ) { +dev_err (dev,"unable to get ws0 interrupt.\n" ); +return irq; + } + +/* +* Get the frequency of system counter from the cp15 interface of ARM +* Generic timer. We don't need to check it, because if it returns "0", +* system would panic in very early stage. +*/ + gwdt->clk =arch_timer_get_cntfrq (); + gwdt->refresh_base = rf_base; + gwdt->control_base = cf_base; + gwdt->max_wor_timeout =U32_MAX / gwdt->clk; + + wdd = &gwdt->wdd; + wdd->parent = dev; + wdd->info = &sbsa_gwdt_info; + wdd->ops = &sbsa_gwdt_ops; +watchdog_set_drvdata (wdd, gwdt); +watchdog_set_nowayout (wdd, nowayout); + + wdd->min_timeout =1 ; +do_div (first_period_max, gwdt->clk); + wdd->max_timeout = first_period_max; + + wdd->timeout =DEFAULT_TIMEOUT ; +watchdog_init_timeout (wdd, timeout, dev); +
Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c line 282
Quoted 4 lines
drivers/watchdog/sbsa_gwdt.c new file +4
-0+ status =readl_relaxed (gwdt->control_base +SBSA_GWDT_WCS ); +if (status &SBSA_GWDT_WCS_WS1 ) { +dev_warn (dev,"System reset by WDT(WCV: %llx)\n" , +sbsa_gwdt_get_wcv (wdd));WCV here only tells us how many clock cycles were executed since the system started (or something like that). So I still don't understand why it is valuable to print that number.
this number provides the time of system reset, I thinks that may help admin to analyse the system failure.
Quoted 9 lines
drivers/watchdog/sbsa_gwdt.c line 289
Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c new file +7
-0+ wdd->bootstatus |=WDIOF_CARDRESET ; + } +/* Check if watchdog is already enabled */ +if (status &SBSA_GWDT_WCS_EN ) { +dev_warn (dev,"already enabled\n" ); +sbsa_gwdt_keepalive (wdd); + }
Quoted 6 lines
Can you merge the message with the info message below ? Something like
dev_info(dev, "Initialized with %ds timeout @ %u Hz%s\n", wdd->timeout, gwdt->clk, status & SBSA_GWDT_WCS_EN ? " [enabled]" : "");I don't think that should be a warning.
yes, good idea, will do
Quoted 9 lines
drivers/watchdog/sbsa_gwdt.c line 293
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +4
-0+ +/* update timeout to WOR */ +sbsa_gwdt_set_timeout (wdd, wdd->timeout); +That will trigger a refresh if the watchdog is active, meaning the timeout will occur at time + WOR, not at time + timeout. I think keepalive has to be called later, preferrably after calling
watchdog_register_device().
yes, you are right, will fix it
Quoted 83 lines
Quoted 83 lines
drivers/watchdog/sbsa_gwdt.c new file +82
-0+ ret =devm_request_irq (dev, irq, sbsa_gwdt_interrupt,0 , + pdev->name, gwdt); +if (ret) { +dev_err (dev,"unable to request IRQ %d\n" , irq); +return ret; + } + + ret =watchdog_register_device (wdd); +if (ret) +return ret; + +dev_info (dev,"Initialized with %ds timeout @ %u Hz\n" , wdd->timeout, + gwdt->clk); + +return 0 ; +} + +static void sbsa_gwdt_shutdown (struct platform_device *pdev) +{ +struct sbsa_gwdt *gwdt =platform_get_drvdata (pdev); + +sbsa_gwdt_stop (&gwdt->wdd); +} + +static int sbsa_gwdt_remove (struct platform_device *pdev) +{ +struct sbsa_gwdt *gwdt =platform_get_drvdata (pdev); + +watchdog_unregister_device (&gwdt->wdd); + +return 0 ; +} + +/* Disable watchdog if it is active during suspend */ +static int __maybe_unused sbsa_gwdt_suspend (struct device *dev) +{ +struct sbsa_gwdt *gwdt =dev_get_drvdata (dev); + +if (watchdog_active (&gwdt->wdd)) +sbsa_gwdt_stop (&gwdt->wdd); + +return 0 ; +} + +/* Enable watchdog and configure it if necessary */ +static int __maybe_unused sbsa_gwdt_resume (struct device *dev) +{ +struct sbsa_gwdt *gwdt =dev_get_drvdata (dev); + +if (watchdog_active (&gwdt->wdd)) +sbsa_gwdt_start (&gwdt->wdd); + +return 0 ; +} + +static const struct dev_pm_ops sbsa_gwdt_pm_ops = { +SET_SYSTEM_SLEEP_PM_OPS (sbsa_gwdt_suspend, sbsa_gwdt_resume) +}; + +static const struct of_device_id sbsa_gwdt_of_match[] = { + { .compatible ="arm,sbsa-gwdt" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, sbsa_gwdt_of_match); + +static const struct platform_device_id sbsa_gwdt_pdev_match[] = { + { .name ="sbsa-gwdt" , }, + {}, +}; +MODULE_DEVICE_TABLE (platform, sbsa_gwdt_pdev_match); + +static struct platform_driver sbsa_gwdt_driver = { + .driver = { + .name ="sbsa-gwdt" , + .pm = &sbsa_gwdt_pm_ops, + .of_match_table = sbsa_gwdt_of_match, + }, + .probe = sbsa_gwdt_probe, + .remove = sbsa_gwdt_remove, + .shutdown = sbsa_gwdt_shutdown, + .id_table = sbsa_gwdt_pdev_match, +};
Quoted 8 lines
drivers/watchdog/sbsa_gwdt.c line 380
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +5
-0+ +module_platform_driver (sbsa_gwdt_driver); + +MODULE_DESCRIPTION ("SBSA Generic Watchdog Driver" ); +MODULE_VERSION ("v1.0" );Version numbers tend to be out of date constantly, and there is no well defined mechanism or protocol when increase them. I would suggest to drop it.
Ok, will drop it
Quoted 4 lines
Quoted 4 lines
drivers/watchdog/sbsa_gwdt.c new file +3
-0+MODULE_AUTHOR ("Fu Wei <[email protected]>" ); +MODULE_AUTHOR ("Suravee Suthikulpanit <[email protected]>" ); +MODULE_LICENSE ("GPL v2" );
Signature · 10 lines
Best regards, Fu Wei Software Engineer Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch Ph: +86 21 61221326(direct) Ph: +86 186 2020 4684 (mobile) Room 1512, Regus One Corporate Avenue,Level 15, One Corporate Avenue,222 Hubin Road,Huangpu District, Shanghai,China 200021
v6 cover Watchdog: introduce ARM SBSA watchdog driver
In reply to a message not in the archiveFrom: Fu Wei <[email protected]>
This patchset:
(1)Introduce Documentation/devicetree/bindings/watchdog/sbsa-gwdt.txt for FDT info of SBSA Generic Watchdog, and give two examples of adding SBSA Generic Watchdog device node into the dts files:
foundation-v8.dts and amd-seattle-soc.dtsi.
(2)Introduce "pretimeout" into the watchdog framework, and update Documentation/watchdog/watchdog-kernel-api.txt to introduce:
(1)the new elements in the watchdog_device and watchdog_ops struct; (2)the new API "watchdog_init_timeouts".
(3)Introduce ARM SBSA watchdog driver:
a.Use linux kernel watchdog framework;
b.Work with FDT on ARM64;
c.Use "pretimeout" in watchdog framework;
d.Support getting timeout and pretimeout from parameter and FDT
at the driver init stage.
e.In the first timeout, do panic to save system context; f.In the second stage, user can still feed the dog without
cleaning WS0. By this feature, we can avoid the panic infinite loops, while backing up a large system context in a server.
g.In the second stage, can trigger WS1 by setting pretimeout = 0
if necessary.
(4)Introduce ACPI GTDT parser: drivers/acpi/gtdt.c
Parse SBSA Generic Watchdog Structure in GTDT table of ACPI, and create a platform device with that information.
This platform device can be used by This Watchdog driver. drivers/clocksource/arm_arch_timer.c is simplified by this GTDT support.
This patchset has been tested with watchdog daemon (ACPI/FDT, module/build-in) on the following platforms:
(1)ARM Foundation v8 model
Changelog:
v6: Improve the dtb example files: reduce the register frame size to 4K.
Improve pretimeout support:
(1) improve watchdog_init_timeouts function
(2) rename watchdog_check_min_max_timeouts back to the original name
(1) improve watchdog_timeout_invalid/watchdog_pretimeout_invalid
Add the new features in the sbsa_gwdt driver:
(1) In the second stage, user can feed the dog without cleaning WS0.
(2) In the second stage, user can trigger WS1 by setting pretimeout = 0.
(3) expand the max value of pretimeout, in case 10 second is not enough for a kdump kernel reboot in panic.
v5: Improve pretimeout support:
(1)fix typo in documentation and comments.
(2)fix the timeout limits validation bug.
Simplify sbsa_gwdt driver:
(1)integrate all the registers access functions into caller.
v4: Refactor GTDT support code: remove it from arch/arm64/kernel/acpi.c,
put it into drivers/acpi/gtdt.c file.
Integrate the GTDT code of drivers/clocksource/arm_arch_timer.c into
drivers/acpi/gtdt.c.
Improve pretimeout support, fix "pretimeout == 0" problem.
Simplify sbsa_gwdt driver:
(1)timeout/pretimeout limits setup;
(2)keepalive function;
(3)delete "clk == 0" check;
(4)delete WS0 status bit check in interrupt routine;
(5)sbsa_gwdt_set_wcv function.v3: Delete "export arch_timer_get_rate" patch.
Driver back to use arch_timer_get_cntfrq.
Improve watchdog_init_timeouts function and update relevant documentation. Improve watchdog_timeout_invalid and watchdog_pretimeout_invalid. Improve foundation-v8.dts: delete the unnecessary tag of device node. Remove "ARM64 || COMPILE_TEST" from Kconfig.
Add comments in arch/arm64/kernel/acpi.c
Fix typoes and incorrect comments.
v2: Improve watchdog-kernel-api.txt documentation for pretimeout support.
Export "arch_timer_get_rate" in arm_arch_timer.c.
Add watchdog_init_timeouts API for pretimeout support in framework. Improve suspend and resume foundation in driver
Improve timeout/pretimeout values init code in driver. Delete unnecessary items of the sbsa_gwdt struct and #define. Delete all unnecessary debug info in driver.
Fix 64bit division bug.
Use the arch_timer interface to get watchdog clock rate. Add MODULE_DEVICE_TABLE for platform device id.
Fix typoes.
v1: The first version upstream patchset to linux mailing list.
Fu Wei (8):
Documentation: add sbsa-gwdt.txt documentation
ARM64: add SBSA Generic Watchdog device node in foundation-v8.dts
ARM64: add SBSA Generic Watchdog device node in amd-seattle-soc.dtsi
Watchdog: introdouce "pretimeout" into framework
Watchdog: introduce ARM SBSA watchdog driver
ACPI: add GTDT table parse driver into ACPI driver
Watchdog: enable ACPI GTDT support for ARM SBSA watchdog driver
clocksource: simplify ACPI code in arm_arch_timer.c
.../devicetree/bindings/watchdog/sbsa-gwdt.txt | 36 ++ Documentation/watchdog/watchdog-kernel-api.txt | 47 ++- arch/arm64/boot/dts/amd/amd-seattle-soc.dtsi | 11 + arch/arm64/boot/dts/arm/foundation-v8.dts | 10 + arch/arm64/kernel/time.c | 4 +- drivers/acpi/Kconfig | 9 + drivers/acpi/Makefile | 1 + drivers/acpi/gtdt.c | 180 ++++++++ drivers/clocksource/Kconfig | 1 + drivers/clocksource/arm_arch_timer.c | 60 +-- drivers/watchdog/Kconfig | 15 + drivers/watchdog/Makefile | 1 + drivers/watchdog/sbsa_gwdt.c | 455 +++++++++++++++++++++ drivers/watchdog/watchdog_core.c | 98 +++-- drivers/watchdog/watchdog_dev.c | 53 +++ include/clocksource/arm_arch_timer.h | 8 + include/linux/acpi.h | 5 + include/linux/clocksource.h | 4 +- include/linux/watchdog.h | 39 +- 19 files changed, 947 insertions(+), 90 deletions(-) create mode 100644 Documentation/devicetree/bindings/watchdog/sbsa-gwdt.txt create mode 100644 drivers/acpi/gtdt.c create mode 100644 drivers/watchdog/sbsa_gwdt.c
Signature · 1 line
1.9.1
PATCH v6 1/8 Documentation: add sbsa-gwdt.txt documentation
From: Fu Wei <[email protected]>
The sbsa-gwdt.txt documentation in devicetree/bindings/watchdog is for introducing SBSA(Server Base System Architecture) Generic Watchdog device node info into FDT.
--- .../devicetree/bindings/watchdog/sbsa-gwdt.txt | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/sbsa-gwdt.txt
Documentation/devicetree/bindings/watchdog/sbsa-gwdt.txt new file +36 -0
@@ -0,0 +1,36 @@ +* SBSA(Server Base System Architecture) Generic Watchdog + +The SBSA Generic Watchdog Timer is used for resetting the system after +two stages of timeout. +More details: ARM-DEN-0029 - Server Base System Architecture (SBSA) + +Required properties: +- compatible : Should at least contain "arm,sbsa-gwdt". + +- reg : base physical address of the frames and length of memory mapped region. + +- reg-names : Should contain the resource reg names to show the order of + the values in "reg". + Must include the following entries : "refresh", "control". + +- interrupts : Should at least contain WS0 interrupt, + the WS1 Signal is optional. + +- interrupt-names : Should contain the resource interrupt names. + Must include the following entries : "ws0". "ws1" is optional. + +Optional properties +- timeout-sec : Watchdog pre-timeout and timeout values (in seconds). + The first is timeout values, then pre-timeout. + +Example for FVP Foundation Model v8: + +watchdog@2a440000 { + compatible = "arm,sbsa-gwdt"; + reg = <0x0 0x2a440000 0 0x1000>, + <0x0 0x2a450000 0 0x1000>; + reg-names = "control", "refresh"; + interrupts = <0 27 4>; + interrupt-names = "ws0"; + timeout-sec = <10 5>; +};
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v6 2/8 ARM64: add SBSA Generic Watchdog device node in foundation-v8.dts
In reply to [email protected]From: Fu Wei <[email protected]>
This can be a example of adding SBSA Generic Watchdog device node into some dts files for the Soc which contains SBSA Generic Watchdog.
--- arch/arm64/boot/dts/arm/foundation-v8.dts | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/arm64/boot/dts/arm/foundation-v8.dts +10 -0
@@ -237,4 +237,14 @@ }; }; }; + watchdog@2a440000 { + compatible = "arm,sbsa-gwdt"; + reg = <0x0 0x2a440000 0 0x1000>, + <0x0 0x2a450000 0 0x1000>; + reg-names = "control", + "refresh"; + interrupts = <0 27 4>; + interrupt-names = "ws0"; + timeout-sec = <10 5>; + }; };
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v6 3/8 ARM64: add SBSA Generic Watchdog device node in amd-seattle-soc.dtsi
In reply to [email protected]From: Fu Wei <[email protected]>
This can be a example of adding SBSA Generic Watchdog device node into some dts files for the Soc which contains SBSA Generic Watchdog.
--- arch/arm64/boot/dts/amd/amd-seattle-soc.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/arm64/boot/dts/amd/amd-seattle-soc.dtsi +11 -0
@@ -84,6 +84,17 @@ clock-names = "uartclk", "apb_pclk"; }; + watchdog0: watchdog@e0bb0000 { + compatible = "arm,sbsa-gwdt"; + reg = <0x0 0xe0bb0000 0 0x1000>, + <0x0 0xe0bc0000 0 0x1000>; + reg-names = "refresh", + "control"; + interrupts = <0 337 4>; + interrupt-names = "ws0"; + timeout-sec = <10 5>; + }; + spi0: ssp@e1020000 { status = "disabled"; compatible = "arm,pl022", "arm,primecell";
Signature · 1 line
1.9.1
PATCH v6 4/8 Watchdog: introdouce "pretimeout" into framework
In reply to [email protected]From: Fu Wei <[email protected]>
Also update Documentation/watchdog/watchdog-kernel-api.txt to introduce:
(1)the new elements in the watchdog_device and watchdog_ops struct; (2)the new API "watchdog_init_timeouts"
Reasons:
(1)kernel already has two watchdog drivers are using "pretimeout":
drivers/char/ipmi/ipmi_watchdog.c drivers/watchdog/kempld_wdt.c(but the definition is different)
(2)some other drivers are going to use this: ARM SBSA Generic Watchdog
--- Documentation/watchdog/watchdog-kernel-api.txt | 47 ++++++++++-- drivers/watchdog/watchdog_core.c | 98 ++++++++++++++++++-------- drivers/watchdog/watchdog_dev.c | 53 ++++++++++++++ include/linux/watchdog.h | 39 ++++++++-- 4 files changed, 200 insertions(+), 37 deletions(-)
Documentation/watchdog/watchdog-kernel-api.txt +42 -5
@@ -49,6 +49,9 @@ struct watchdog_device { unsigned int timeout; unsigned int min_timeout; unsigned int max_timeout; + unsigned int pretimeout; + unsigned int min_pretimeout; + unsigned int max_pretimeout; void *driver_data; struct mutex lock; unsigned long status;
@@ -70,6 +73,9 @@ It contains following fields: * timeout: the watchdog timer's timeout value (in seconds). * min_timeout: the watchdog timer's minimum timeout value (in seconds). * max_timeout: the watchdog timer's maximum timeout value (in seconds). +* pretimeout: the watchdog timer's pretimeout value (in seconds). +* min_pretimeout: the watchdog timer's minimum pretimeout value (in seconds). +* max_pretimeout: the watchdog timer's maximum pretimeout value (in seconds). * bootstatus: status of the device after booting (reported with watchdog WDIOF_* status bits). * driver_data: a pointer to the drivers private data of a watchdog device.
@@ -92,6 +98,7 @@ struct watchdog_ops { int (*ping)(struct watchdog_device *); unsigned int (*status)(struct watchdog_device *); int (*set_timeout)(struct watchdog_device *, unsigned int); + int (*set_pretimeout)(struct watchdog_device *, unsigned int); unsigned int (*get_timeleft)(struct watchdog_device *); void (*ref)(struct watchdog_device *); void (*unref)(struct watchdog_device *);
@@ -153,9 +160,19 @@ they are supported. These optional routines/operations are: and -EIO for "could not write value to the watchdog". On success this routine should set the timeout value of the watchdog_device to the achieved timeout value (which may be different from the requested one - because the watchdog does not necessarily has a 1 second resolution). + because the watchdog does not necessarily has a 1 second resolution; + If the driver supports pretimeout, then the timeout value must be greater + than that). (Note: the WDIOF_SETTIMEOUT needs to be set in the options field of the watchdog's info structure). +* set_pretimeout: this routine checks and changes the pretimeout of the + watchdog timer device. It returns 0 on success, -EINVAL for "parameter out of + range" and -EIO for "could not write value to the watchdog". On success this + routine should set the pretimeout value of the watchdog_device to the + achieved pretimeout value (which may be different from the requested one + because the watchdog does not necessarily has a 1 second resolution). + (Note: the WDIOF_PRETIMEOUT needs to be set in the options field of the + watchdog's info structure). * get_timeleft: this routines returns the time that's left before a reset. * ref: the operation that calls kref_get on the kref of a dynamically allocated watchdog_device struct.
@@ -219,8 +236,28 @@ extern int watchdog_init_timeout(struct watchdog_device *wdd, unsigned int timeout_parm, struct device *dev); The watchdog_init_timeout function allows you to initialize the timeout field -using the module timeout parameter or by retrieving the timeout-sec property from -the device tree (if the module timeout parameter is invalid). Best practice is -to set the default timeout value as timeout value in the watchdog_device and -then use this function to set the user "preferred" timeout value. +using the module timeout parameter or by retrieving the first element of +the timeout-sec property from the device tree (if the module timeout parameter +is invalid). Best practice is to set the default timeout value as timeout value +in the watchdog_device and then use this function to set the user "preferred" +timeout value. +This routine returns zero on success and a negative errno code for failure. + +Some watchdog timers have two stage of timeouts (timeout and pretimeout), +to initialize the timeout and pretimeout fields at the same time, the following +function can be used: + +int watchdog_init_timeouts(struct watchdog_device *wdd, + unsigned int pretimeout_parm, + unsigned int timeout_parm, + struct device *dev); + +The watchdog_init_timeouts function allows you to initialize the pretimeout and +timeout fields using the module pretimeout and timeout parameter or by +retrieving the elements in the timeout-sec property (the first element is for +timeout, the second one is for pretimeout) from the device tree (if the module +pretimeout and timeout parameter are invalid). +Best practice is to set the default pretimeout and timeout value as pretimeout +and timeout value in the watchdog_device and then use this function to set the +user "preferred" pretimeout value. This routine returns zero on success and a negative errno code for failure.
drivers/watchdog/watchdog_core.c +70 -28
127 lines not on this page · raw message
drivers/watchdog/watchdog_dev.c +53 -0
65 lines not on this page · raw message
include/linux/watchdog.h +35 -4
@@ -25,6 +25,7 @@ struct watchdog_device;* @ping: The routine that sends a keepalive ping to the watchdog device. * @status: The routine that shows the status of the watchdog device. * @set_timeout:The routine for setting the watchdog devices timeout value. +* @set_pretimeout:The routine for setting the watchdog devices pretimeout value * @get_timeleft:The routine that get's the time that's left before a reset. * @ref: The ref operation for dyn. allocated watchdog_device structs * @unref: The unref operation for dyn. allocated watchdog_device structs
@@ -44,6 +45,7 @@ struct watchdog_ops {int (*ping)(struct watchdog_device *);unsigned int (*status)(struct watchdog_device *);int (*set_timeout)(struct watchdog_device *,unsigned int ); +int (*set_pretimeout)(struct watchdog_device *,unsigned int );unsigned int (*get_timeleft)(struct watchdog_device *);void (*ref)(struct watchdog_device *);void (*unref)(struct watchdog_device *);
@@ -62,6 +64,9 @@ struct watchdog_ops {* @timeout: The watchdog devices timeout value. * @min_timeout:The watchdog devices minimum timeout value. * @max_timeout:The watchdog devices maximum timeout value. +* @pretimeout: The watchdog devices pretimeout value. +* @min_pretimeout:The watchdog devices minimum pretimeout value. +* @max_pretimeout:The watchdog devices maximum pretimeout value. * @driver-data:Pointer to the drivers private data. * @lock: Lock for watchdog core internal use only. * @status: Field that contains the devices internal status bits.
@@ -86,6 +91,9 @@ struct watchdog_device {unsigned int timeout;unsigned int min_timeout;unsigned int max_timeout; +unsigned int pretimeout; +unsigned int min_pretimeout; +unsigned int max_pretimeout;void *driver_data;struct mutex lock;unsigned long status;
@@ -116,8 +124,22 @@ static inline void watchdog_set_nowayout(struct watchdog_device *wdd, bool noway/* 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) { -return ((wdd->max_timeout !=0 ) && - (t < wdd->min_timeout || t > wdd->max_timeout)); +return (wdd->max_timeout && + (t < wdd->min_timeout || t > wdd->max_timeout)) || + (wdd->pretimeout && t <= wdd->pretimeout); +} + +/* +* Use the following function to check if a pretimeout value is invalid. +* It can be "0", that means we don't use pretimeout. +* This function returns false, when pretimeout is 0. +*/ +static inline bool watchdog_pretimeout_invalid (struct watchdog_device *wdd, +unsigned int t) +{ +return t && ((wdd->max_pretimeout && + (t < wdd->min_pretimeout || t > wdd->max_pretimeout)) || + (wdd->timeout && t >= wdd->timeout)); }/* Use the following functions to manipulate watchdog driver specific data */
@@ -132,8 +154,17 @@ static inline void *watchdog_get_drvdata(struct watchdog_device *wdd) }/* drivers/watchdog/watchdog_core.c */ -extern int watchdog_init_timeout (struct watchdog_device *wdd, -unsigned int timeout_parm,struct device *dev); +int watchdog_init_timeouts (struct watchdog_device *wdd, +unsigned int pretimeout_parm, +unsigned int timeout_parm, +struct device *dev); +static inline int watchdog_init_timeout (struct watchdog_device *wdd, +unsigned int timeout_parm, +struct device *dev) +{ +return watchdog_init_timeouts (wdd,0 , timeout_parm, dev); +} +extern int watchdog_register_device (struct watchdog_device *);extern void watchdog_unregister_device (struct watchdog_device *);
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Guenter Roeck
maintainerRe: [non-pretimeout,4/7] Watchdog: introduce ARM SBSA watchdog driver
In reply to Fu WeiQuoted 1 line · Fu Wei
Hi Guenter,
[ ...]
Quoted 38 lines
Quoted 12 lines
Quoted 3 lines
+ * When the first timeout occurs, WS0(SPI or LPI) is triggered,
+ * the second timeout period(as long as the first timeout period) starts.no longer accurate if WOR is used for the second period.
Quoted 5 lines
+ * In WS0 interrupt routine, panic() will be called for collecting + * crashdown info. + * If system can not recover from WS0 interrupt routine, then second + * timeout occurs, WS1(reset or higher level interrupt) is triggered. + * The two timeout period can be set by WOR(32bit).Quoted 8 lines
The second timeout period is determined by ...
Quoted 3 lines
+ * WOR gives a maximum watch period of around 10s at the maximum + * system counter frequency. + * The System Counter shall run at maximum of 400MHz."... at the maximum system counter frequency of 400 MHz.", and drop the last sentence.
For the second timeout period, I have discussed with a kdump developers, (1)10s maybe not good enough for all the case of panic + kdump, so maybe we still need to use WCV in the second timeout period (2)in the second timeout period, maybe we need to programme WCV for two reason: a, trigger WS1 to reboot system ASAP; b, feed the watchdog without cleanning WS0 flag.
WHY we want to feed the watchdog (keepalive) without cleanning WS0 flag?? REASON:
(1)if the system context is large, we may need to feed the dog until we get all the things backed up.
(2)if system goes wrong, WS0 triggered, then panic--> kdump. if we feed the dog by WRR or programming WOR, WS0 flag will be cleaned. Once system goes wrong again, then panic again.....
So this system will be in a panic--kdump--panic--kdump loop, have not chance to reset.
Quoted 2 lines
So if we are in the second timeout period, we may need to always programme WCV.
The crashdump kernel is supposed to reload the watchdog driver, which will ping the watchdog. If it isn't able to do that in 10 seconds, something is wrong.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
drivers/watchdog/sbsa_gwdt.c new file +5
-0+ + status =readl_relaxed (gwdt->control_base +SBSA_GWDT_WCS ); +if (status &SBSA_GWDT_WCS_WS1 ) { +dev_warn (dev,"System reset by WDT(WCV: %llx)\n" , +sbsa_gwdt_get_wcv (wdd));
Quoted 7 lines
Quoted 3 lines
WCV here only tells us how many clock cycles were executed since the system started (or something like that). So I still don't understand why it is valuable to print that number.
this number provides the time of system reset, I thinks that may help admin to analyse the system failure.
It doesn't mean anything to anyone but you since it is not in a well defined time scale. Also, I would be somewhat surprised if WCV would retain its value on reset. Much more likely it is the time (in clock cycles) since reset.
Guenter
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v6 5/8 Watchdog: introduce ARM SBSA watchdog driver
In reply to a message not in the archiveFrom: Fu Wei <[email protected]>
This driver bases on linux kernel watchdog framework, and use "pretimeout" in the framework. It supports getting timeout and pretimeout from parameter and FDT at the driver init stage. In first timeout, the interrupt routine run panic to save system context.
--- drivers/watchdog/Kconfig | 14 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/sbsa_gwdt.c | 455 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 470 insertions(+) create mode 100644 drivers/watchdog/sbsa_gwdt.c
drivers/watchdog/Kconfig +14 -0
@@ -152,6 +152,20 @@ config ARM_SP805_WATCHDOG ARM Primecell SP805 Watchdog timer. This will reboot your system when the timeout is reached. +config ARM_SBSA_WATCHDOG + tristate "ARM SBSA Generic Watchdog" + depends on ARM64 + depends on ARM_ARCH_TIMER + select WATCHDOG_CORE + help + ARM SBSA Generic Watchdog. This watchdog has two Watchdog timeouts. + The first timeout will trigger a panic; the second timeout will + trigger a system reset. + More details: ARM DEN0029B - Server Base System Architecture (SBSA) + + To compile this driver as module, choose M here: The module + will be called sbsa_gwdt. + config AT91RM9200_WATCHDOG tristate "AT91RM9200 watchdog" depends on SOC_AT91RM9200 && MFD_SYSCON
drivers/watchdog/Makefile +1 -0
@@ -30,6 +30,7 @@ obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o # ARM Architecture obj-$(CONFIG_ARM_SP805_WATCHDOG) += sp805_wdt.o +obj-$(CONFIG_ARM_SBSA_WATCHDOG) += sbsa_gwdt.o obj-$(CONFIG_AT91RM9200_WATCHDOG) += at91rm9200_wdt.o obj-$(CONFIG_AT91SAM9X_WATCHDOG) += at91sam9_wdt.o obj-$(CONFIG_CADENCE_WATCHDOG) += cadence_wdt.o
drivers/watchdog/sbsa_gwdt.c new file +455 -0
455 lines not on this page · raw message
Signature · 1 line
1.9.1