watchdog: Add window watchdog driver
Subsystems (4)
cover watchdog: Add window watchdog driver
This patch series:
- Add xilinx window watchdog binding document.
- Add versal window watchdog feature.
- Add MAINTAINERS fragment for xilinx watchdog drivers.
Srinivas Neeli (3):
watchdog: bindings: xlnx,versal-wwdt: Add binding documentation for
xilinx window watchdog device
watchdog: xilinx_wwdt: Add Versal Window watchdog mode
MAINTAINERS: Add fragment for xilinx watchdog drivers
.../bindings/watchdog/xlnx,versal-wwdt.yaml | 71 ++++ MAINTAINERS | 10 + drivers/watchdog/Kconfig | 16 + drivers/watchdog/Makefile | 1 + drivers/watchdog/xilinx_wwdt.c | 382 ++++++++++++++++++ 5 files changed, 480 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/xlnx,versal-wwdt.yaml create mode 100644 drivers/watchdog/xilinx_wwdt.c
Signature · 1 line
2.22.0
PATCH 1/3 watchdog: bindings: xlnx,versal-wwdt: Add binding documentation for xilinx window watchdog device
Add documentation for the binding of Window watchdog device.
--- .../bindings/watchdog/xlnx,versal-wwdt.yaml | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/xlnx,versal-wwdt.yaml
Documentation/devicetree/bindings/watchdog/xlnx,versal-wwdt.yaml new file +71 -0
@@ -0,0 +1,71 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/watchdog/xlnx,versal-wwdt.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Xilinx Versal Window Watchdog Timer Controller + +maintainers: + - Neeli Srinivas <[email protected]> + +description: + Versal watchdog driver uses Window watchdog mode. Window watchdog + timer(WWDT) contains closed(first) and open(second) window with + 32 bit width. WWDT will generate an interrupt after the first window + timeout and reset signal after the second window timeout. Timeout + and pretimeout configuration, Stop and Refresh trigger only in open + window. + +properties: + compatible: + enum: + - xlnx,versal-wwdt-1.0 + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + timeout-sec: true + + pretimeout-sec: true + + interrupts: + items: + - description: Watchdog interrupt + - description: Watchdog reset pending interrupt + description: + Interrupt line names "wdt" or "wwdt_reset_pending". + wdt - will assert high after first (closed) window + timer expires. wwdt_reset_pending - will assert high + after second (open) window timer expires if WRP + (Watchdog Reset pending) is configured with third + (SST) timer. + + interrupt-names: + items: + - const: wdt + - const: wwdt_reset_pending + +required: + - compatible + - reg + - clocks + - interrupts + - interrupt-names + +additionalProperties: false + +examples: + - | + watchdog@fd4d0000 { + compatible = "xlnx,versal-wwdt-1.0"; + reg = <0xfd4d0000 0x10000>; + clocks = <&clock25>; + timeout-sec = <30>; + pretimeout-sec = <25>; + interrupts = <0 0x64 1>, <0 0x6D 1>; + interrupt-names = "wdt", "wwdt_reset_pending"; + }; +...
Signature · 1 line
2.22.0
PATCH 2/3 watchdog: xilinx_wwdt: Add Versal Window watchdog mode
In reply to Srinivas NeeliVersal watchdog driver uses Window watchdog mode. Window watchdog timer(WWDT) contains closed(first) and open(second) window with 32 bit width. WWDT will generate an interrupt after the first window timeout and reset signal after the second window timeout. Timeout and Pre-timeout configuration, Stop and Refresh trigger only in open window.
--- drivers/watchdog/Kconfig | 16 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/xilinx_wwdt.c | 382 +++++++++++++++++++++++++++++++++ 3 files changed, 399 insertions(+) create mode 100644 drivers/watchdog/xilinx_wwdt.c
drivers/watchdog/Kconfig +16 -0
@@ -307,6 +307,22 @@ config XILINX_WATCHDOG To compile this driver as a module, choose M here: the module will be called of_xilinx_wdt. +config XILINX_WINDOW_WATCHDOG + tristate "Xilinx Window Watchdog timer" + depends on HAS_IOMEM + select WATCHDOG_CORE + help + Window Watchdog driver for the versal_wwdt ip core. + Window watchdog timer(WWDT) contains closed(first) and + open(second) window with 32 bit width. WWDT will generate + an interrupt after the first window timeout and reset + signal after the second window timeout. Timeout and + Pre-timeout configuration, Stop and Refresh trigger + only in open window. + + To compile this driver as a module, choose M here: the + module will be called xilinx_wwdt. + config ZIIRAVE_WATCHDOG tristate "Zodiac RAVE Watchdog Timer" depends on I2C
drivers/watchdog/Makefile +1 -0
@@ -148,6 +148,7 @@ obj-$(CONFIG_M54xx_WATCHDOG) += m54xx_wdt.o # MicroBlaze Architecture obj-$(CONFIG_XILINX_WATCHDOG) += of_xilinx_wdt.o +obj-$(CONFIG_XILINX_WINDOW_WATCHDOG) += xilinx_wwdt.o # MIPS Architecture obj-$(CONFIG_ATH79_WDT) += ath79_wdt.o
drivers/watchdog/xilinx_wwdt.c new file +382 -0
382 lines not on this page · raw message
Signature · 1 line
2.22.0
Guenter Roeck
maintainerRe: [PATCH 2/3] watchdog: xilinx_wwdt: Add Versal Window watchdog mode
The subject is confusing. This patch does not add "Versal Window watchdog mode", it adds a driver which supports the Versal Window watchdog. The subject should be something like "watchdog: Add Versal Window watchdog driver".
Quoted 6 lines · Srinivas Neeli
Versal watchdog driver uses Window watchdog mode. Window watchdog timer(WWDT) contains closed(first) and open(second) window with 32 bit width. WWDT will generate an interrupt after the first window timeout and reset signal after the second window timeout. Timeout and Pre-timeout configuration, Stop and Refresh trigger only in open window.
Does that mean that userspace can not send a keepalive before the pretimeout expires ? That is not how this is supposed to work. If that is the case, this is not a pretimeout. Pretimeout is supposed to be used for emergency handling, such as triggering a crash dump. The above description as well as the code suggests that an interrupt is all but mandatory.
Assuming that is all the case, ie that keepalive is only possible after the interrupt was received, and that timeout updates are also only possible after an interrupt was received, one possible handling would to record that a keepalive was received, and to record that a request to update the timeout was received if that happens while the window is closed. Then, when the interrupt is received, those actions can be applied. Otherwise, if there was no keepalive request prior to the interrupt, the interrupt handler would call watchdog_notify_pretimeout().
Of course, this is all just guesswork.
More comments below.
Guenter
Quoted 100 lines
Signed-off-by Srinivas Neeli <[email protected]>--- drivers/watchdog/Kconfig | 16 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/xilinx_wwdt.c | 382 +++++++++++++++++++++++++++++++++ 3 files changed, 399 insertions(+)create mode 100644
drivers/watchdog/xilinx_wwdt.cdrivers/watchdog/Kconfig +16
-0@@ -307,6 +307,22 @@ config XILINX_WATCHDOG To compile this driver as a module, choose M here: the module will be called of_xilinx_wdt. +config XILINX_WINDOW_WATCHDOG + tristate "Xilinx Window Watchdog timer" + depends on HAS_IOMEM + select WATCHDOG_CORE + help + Window Watchdog driver for the versal_wwdt ip core. + Window watchdog timer(WWDT) contains closed(first) and + open(second) window with 32 bit width. WWDT will generate + an interrupt after the first window timeout and reset + signal after the second window timeout. Timeout and + Pre-timeout configuration, Stop and Refresh trigger + only in open window. + + To compile this driver as a module, choose M here: the + module will be called xilinx_wwdt. + config ZIIRAVE_WATCHDOG tristate "Zodiac RAVE Watchdog Timer" depends on I2Cdrivers/watchdog/Makefile +1
-0@@ -148,6 +148,7 @@ obj-$(CONFIG_M54xx_WATCHDOG) += m54xx_wdt.o # MicroBlaze Architecture obj-$(CONFIG_XILINX_WATCHDOG) += of_xilinx_wdt.o +obj-$(CONFIG_XILINX_WINDOW_WATCHDOG) += xilinx_wwdt.o # MIPS Architecture obj-$(CONFIG_ATH79_WDT) += ath79_wdt.odrivers/watchdog/xilinx_wwdt.c new file +46
-0@@ -0,0 +1,382 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Window Watchdog Device Driver for Xilinx Versal WWDT +* +* (C) Copyright 2021 Xilinx, Inc. +*/ + +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/ioport.h> +#include <linux/of_device.h> +#include <linux/of_address.h> +#include <linux/module.h> +#include <linux/watchdog.h> + +#define XWWDT_DEFAULT_TIMEOUT 40 +#define XWWDT_MIN_TIMEOUT 1 +#define XWWDT_MAX_TIMEOUT 42 + +/* Register offsets for the WWdt device */ +#define XWWDT_MWR_OFFSET 0x00 +#define XWWDT_ESR_OFFSET 0x04 +#define XWWDT_FCR_OFFSET 0x08 +#define XWWDT_FWR_OFFSET 0x0c +#define XWWDT_SWR_OFFSET 0x10 + +/* Master Write Control Register Masks */ +#define XWWDT_MWR_MASK BIT(0) + +/* Enable and Status Register Masks */ +#define XWWDT_ESR_WINT_MASK BIT(16) +#define XWWDT_ESR_WSW_MASK BIT(8) +#define XWWDT_ESR_WEN_MASK BIT(0) + +/* Function control Register Masks */ +#define XWWDT_SBC_MASK 0xFF00 +#define XWWDT_SBC_SHIFT 16 +#define XWWDT_BSS_MASK 0xC0 + +static int wwdt_timeout; + +module_param (wwdt_timeout, int,0644 ); +MODULE_PARM_DESC (wwdt_timeout, + "Watchdog time in seconds. (default=" + __MODULE_STRING(XWWDT_DEFAULT_TIMEOUT) ")");
drivers/watchdog/xilinx_wwdt.c line 56
Quoted 10 lines
drivers/watchdog/xilinx_wwdt.c new file +10
-0+ +struct xwwdt_device { +void __iomem *base; +spinlock_t spinlock;/* spinlock for register handling */ +struct watchdog_device xilinx_wwdt_wdd; +struct clk *clk; +int irq; +}; + +static int is_wwdt_in_closed_window (struct watchdog_device *wdd)
should return bool
drivers/watchdog/xilinx_wwdt.c line 68
Quoted 12 lines
drivers/watchdog/xilinx_wwdt.c new file +12
-0+{ +u32 control_status_reg; +struct xwwdt_device *xdev =watchdog_get_drvdata (wdd); + +spin_lock (&xdev->spinlock); + control_status_reg =ioread32 (xdev->base +XWWDT_ESR_OFFSET ); +spin_unlock (&xdev->spinlock); +if (control_status_reg &XWWDT_ESR_WEN_MASK ) +if (!(control_status_reg &XWWDT_ESR_WSW_MASK )) +return 0 ; + +return 1 ;
Can be written as expresion without if statement
Quoted 4 lines
drivers/watchdog/xilinx_wwdt.c new file +4
-0+} + +static int xilinx_wwdt_start (struct watchdog_device *wdd) +{
drivers/watchdog/xilinx_wwdt.c line 82
Quoted 10 lines
drivers/watchdog/xilinx_wwdt.c new file +10
-0+struct xwwdt_device *xdev =watchdog_get_drvdata (wdd); +struct watchdog_device *xilinx_wwdt_wdd = &xdev->xilinx_wwdt_wdd; +u64 time_out, pre_timeout, count; +u32 control_status_reg, fcr; +int ret; + + count =clk_get_rate (xdev->clk); +if (!count) +return -EINVAL ; +
Is there a reason to believe that the clock rate can change ? If not I would suggest to read it once and store it in struct xwwdt_device.
drivers/watchdog/xilinx_wwdt.c line 87
Quoted 5 lines
drivers/watchdog/xilinx_wwdt.c new file +5
-0+/* Calculate timeout count */ + pre_timeout = count * wdd->pretimeout; + time_out = count * wdd->timeout; +if (!watchdog_active (xilinx_wwdt_wdd)) { + ret =clk_enable (xdev->clk);
This is at the very least confusing.
The last action in the probe function is to call clk_disable_unprepare(), meaning the clock should not be prepared here. How can it be enabled without being prepared ?
drivers/watchdog/xilinx_wwdt.c line 93
Quoted 6 lines
drivers/watchdog/xilinx_wwdt.c new file +6
-0+if (ret) { +dev_err (wdd->parent,"Failed to enable clock\n" ); +return ret; + } + } +
I think it would be better to separate the functions to start/stop the clock from the function to update/enable the watchdog. The use of watchdog_active() combined with clk_enable/clk_disable/clk_prepare_enable/clk_disable_unprepare is confusing and makes it all but impossible to review the driver.
Quoted 44 lines
drivers/watchdog/xilinx_wwdt.c new file +44
-0+spin_lock (&xdev->spinlock); +iowrite32 (XWWDT_MWR_MASK , xdev->base +XWWDT_MWR_OFFSET ); +iowrite32 (~(u32 )XWWDT_ESR_WEN_MASK , + xdev->base +XWWDT_ESR_OFFSET ); + +if (pre_timeout) { +iowrite32 ((u32)(time_out - pre_timeout), + xdev->base +XWWDT_FWR_OFFSET ); +iowrite32 ((u32 )pre_timeout, xdev->base +XWWDT_SWR_OFFSET ); + fcr =ioread32 (xdev->base +XWWDT_SWR_OFFSET ); + fcr = (fcr >>XWWDT_SBC_SHIFT ) &XWWDT_SBC_MASK ; + fcr = fcr |XWWDT_BSS_MASK ; +iowrite32 (fcr, xdev->base +XWWDT_FCR_OFFSET ); + }else { +iowrite32 ((u32 )pre_timeout, + xdev->base +XWWDT_FWR_OFFSET ); +iowrite32 ((u32 )time_out, xdev->base +XWWDT_SWR_OFFSET ); +iowrite32 (0x0 , xdev->base +XWWDT_FCR_OFFSET ); + } + +/* Enable the window watchdog timer */ + control_status_reg =ioread32 (xdev->base +XWWDT_ESR_OFFSET ); + control_status_reg |=XWWDT_ESR_WEN_MASK ; +iowrite32 (control_status_reg, xdev->base +XWWDT_ESR_OFFSET ); + +spin_unlock (&xdev->spinlock); + +dev_dbg (xilinx_wwdt_wdd->parent,"Watchdog Started!\n" ); + +return 0 ; +} + +static int xilinx_wwdt_stop (struct watchdog_device *wdd) +{ +struct xwwdt_device *xdev =watchdog_get_drvdata (wdd); +struct watchdog_device *xilinx_wwdt_wdd = &xdev->xilinx_wwdt_wdd; + +if (!is_wwdt_in_closed_window (wdd)) { +dev_warn (xilinx_wwdt_wdd->parent,"timer in closed window" ); +return -EINVAL ; + } + +spin_lock (&xdev->spinlock); +
drivers/watchdog/xilinx_wwdt.c line 147
Quoted 10 lines
drivers/watchdog/xilinx_wwdt.c new file +10
-0+iowrite32 (XWWDT_MWR_MASK , xdev->base +XWWDT_MWR_OFFSET ); +/* Disable the Window watchdog timer */ +iowrite32 (~(u32 )XWWDT_ESR_WEN_MASK , + xdev->base +XWWDT_ESR_OFFSET ); + +spin_unlock (&xdev->spinlock); + +if (watchdog_active (xilinx_wwdt_wdd)) +clk_disable (xdev->clk); +
The stop function won't be called if the watchdog is not running, ie if watchdog_active() returns false.
I don't undeerstand the logic of clock handling in this driver. More on that below.
Quoted 4 lines
drivers/watchdog/xilinx_wwdt.c new file +4
-0+dev_dbg (xilinx_wwdt_wdd->parent,"Watchdog Stopped!\n" ); + +return 0 ; +}
drivers/watchdog/xilinx_wwdt.c line 161
Quoted 10 lines
drivers/watchdog/xilinx_wwdt.c new file +10
-0+ +static int xilinx_wwdt_keepalive (struct watchdog_device *wdd) +{ +u32 control_status_reg; +struct xwwdt_device *xdev =watchdog_get_drvdata (wdd); + +/* Refresh in open window is ignored */ +if (!is_wwdt_in_closed_window (wdd)) +return 0 ; +
This is dangerous. There is no reason for userspace to adhere to these restrictions.
Quoted 18 lines
drivers/watchdog/xilinx_wwdt.c new file +18
-0+spin_lock (&xdev->spinlock); + +iowrite32 (XWWDT_MWR_MASK , xdev->base +XWWDT_MWR_OFFSET ); + control_status_reg =ioread32 (xdev->base +XWWDT_ESR_OFFSET ); + control_status_reg |=XWWDT_ESR_WINT_MASK ; + control_status_reg &= ~XWWDT_ESR_WSW_MASK ; +iowrite32 (control_status_reg, xdev->base +XWWDT_ESR_OFFSET ); + control_status_reg =ioread32 (xdev->base +XWWDT_ESR_OFFSET ); + control_status_reg |=XWWDT_ESR_WSW_MASK ; +iowrite32 (control_status_reg, xdev->base +XWWDT_ESR_OFFSET ); + +spin_unlock (&xdev->spinlock); + +return 0 ; +} + +static int xilinx_wwdt_set_timeout (struct watchdog_device *wdd, +unsigned int new_time)
drivers/watchdog/xilinx_wwdt.c line 189
Quoted 10 lines
drivers/watchdog/xilinx_wwdt.c new file +10
-0+{ +u32 ret =0 ; +struct xwwdt_device *xdev =watchdog_get_drvdata (wdd); +struct watchdog_device *xilinx_wwdt_wdd = &xdev->xilinx_wwdt_wdd; + +if (!is_wwdt_in_closed_window (wdd)) { +dev_warn (xilinx_wwdt_wdd->parent,"timer in closed window" ); +return -EINVAL ; + } +
So userspace can clog the log by continuously trying to set the timeout ?
Also, again, this is dangerous. Userspace does not know the window size.
drivers/watchdog/xilinx_wwdt.c line 197
Quoted 8 lines
drivers/watchdog/xilinx_wwdt.c new file +8
-0+if (new_time <XWWDT_MIN_TIMEOUT || + new_time >XWWDT_MAX_TIMEOUT ) { +dev_warn (xilinx_wwdt_wdd->parent, +"timeout value must be %d<=x<=%d, using %d\n" , +XWWDT_MIN_TIMEOUT , +XWWDT_MAX_TIMEOUT , new_time); +return -EINVAL ; + }
This is handled by the watchdog core.
Quoted 14 lines
drivers/watchdog/xilinx_wwdt.c new file +14
-0+ + wdd->timeout = new_time; + wdd->pretimeout =0 ; + +if (watchdog_active (xilinx_wwdt_wdd)) { + ret =xilinx_wwdt_start (wdd); +if (ret) +dev_dbg (xilinx_wwdt_wdd->parent,"timer start failed" ); + } + +return ret; +} + +static int xilinx_wwdt_set_pretimeout(struct watchdog_device *wdd,
drivers/watchdog/xilinx_wwdt.c line 221
Quoted 10 lines
drivers/watchdog/xilinx_wwdt.c new file +10
-0+ u32 new_pretimeout) +{ +u32 ret =0 ; +struct xwwdt_device *xdev =watchdog_get_drvdata (wdd); +struct watchdog_device *xilinx_wwdt_wdd = &xdev->xilinx_wwdt_wdd; + +if (!is_wwdt_in_closed_window (wdd)) { +dev_warn (xilinx_wwdt_wdd->parent,"timer in closed window" ); +return -EINVAL ; + }
This restriction is not only dangerous but confusing, and simply unacceptable. Userspace will get -EINVAL with no idea what is wrong. A watchdog daemon will bail out for no good reason.
drivers/watchdog/xilinx_wwdt.c line 226
Quoted 5 lines
drivers/watchdog/xilinx_wwdt.c new file +5
-0+ +if (new_pretimeout < wdd->min_timeout || + new_pretimeout >= wdd->timeout) +return -EINVAL ; +
This is handled by the watchdog core.
Quoted 86 lines
drivers/watchdog/xilinx_wwdt.c new file +86
-0+ wdd->pretimeout = new_pretimeout; + +if (watchdog_active (xilinx_wwdt_wdd)) { + ret =xilinx_wwdt_start (wdd); +if (ret) +dev_dbg (xilinx_wwdt_wdd->parent,"timer start failed" ); + } + +return ret; +} + +static void xwwdt_clk_disable_unprepare (void *data) +{ +clk_disable_unprepare (data); +} + +static irqreturn_t xilinx_wwdt_isr (int irq,void *wdog_arg) +{ +struct xwwdt_device *xdev = wdog_arg; + +watchdog_notify_pretimeout (&xdev->xilinx_wwdt_wdd); + +return IRQ_HANDLED ; +} + +static const struct watchdog_info xilinx_wwdt_ident = { + .options =WDIOF_MAGICCLOSE | +WDIOF_KEEPALIVEPING | +WDIOF_SETTIMEOUT , + .firmware_version =1 , + .identity ="xlnx_window watchdog" , +}; + +static const struct watchdog_info xilinx_wwdt_pretimeout_ident = { + .options =WDIOF_MAGICCLOSE | +WDIOF_KEEPALIVEPING | +WDIOF_PRETIMEOUT | +WDIOF_SETTIMEOUT , + .firmware_version =1 , + .identity ="xlnx_window watchdog" , +}; + +static const struct watchdog_ops xilinx_wwdt_ops = { + .owner =THIS_MODULE , + .start = xilinx_wwdt_start, + .stop = xilinx_wwdt_stop, + .ping = xilinx_wwdt_keepalive, + .set_timeout = xilinx_wwdt_set_timeout, + .set_pretimeout = xilinx_wwdt_set_pretimeout, +}; + +static int xwwdt_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct watchdog_device *xilinx_wwdt_wdd; +struct xwwdt_device *xdev; +u32 pre_timeout =0 ; +int ret; + + xdev =devm_kzalloc (dev,sizeof (*xdev),GFP_KERNEL ); +if (!xdev) +return -ENOMEM ; + + xilinx_wwdt_wdd = &xdev->xilinx_wwdt_wdd; + xilinx_wwdt_wdd->info = &xilinx_wwdt_ident; + xilinx_wwdt_wdd->ops = &xilinx_wwdt_ops; + xilinx_wwdt_wdd->parent = dev; + + xdev->base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (xdev->base)) +return PTR_ERR (xdev->base); + + ret =of_property_read_u32 (dev->of_node,"pretimeout-sec" , + &pre_timeout); +if (ret) +dev_dbg (dev, +"Parameter \"pretimeout-sec\" not found\n" ); + + xdev->clk =devm_clk_get (dev,NULL ); +if (IS_ERR (xdev->clk)) +return PTR_ERR (xdev->clk); + + ret =clk_get_rate (xdev->clk); +if (!ret) +return -EINVAL ; +
drivers/watchdog/xilinx_wwdt.c line 322
Quoted 10 lines
drivers/watchdog/xilinx_wwdt.c new file +10
-0+ ret =clk_prepare_enable (xdev->clk); +if (ret) { +dev_err (dev,"unable to enable clock\n" ); +return ret; + } + ret =devm_add_action_or_reset (dev, xwwdt_clk_disable_unprepare, + xdev->clk); +if (ret) + goto err_clk_disable; +
Seems pointless. What happens when you unload the driver ?
Quoted 18 lines
drivers/watchdog/xilinx_wwdt.c new file +18
-0+ xilinx_wwdt_wdd->pretimeout = pre_timeout; + xilinx_wwdt_wdd->timeout =XWWDT_DEFAULT_TIMEOUT ; + xilinx_wwdt_wdd->min_timeout =XWWDT_MIN_TIMEOUT ; + xilinx_wwdt_wdd->max_timeout =XWWDT_MAX_TIMEOUT ; + + xdev->irq =platform_get_irq_byname (pdev,"wdt" ); +if (xdev->irq <0 ) { + ret = xdev->irq; + goto err_clk_disable; + } + +if (!devm_request_irq (dev, xdev->irq, xilinx_wwdt_isr, +0 ,dev_name (dev), xdev)) { + xilinx_wwdt_wdd->info = &xilinx_wwdt_pretimeout_ident; + } + + ret =watchdog_init_timeout (xilinx_wwdt_wdd, + wwdt_timeout, &pdev->dev);
drivers/watchdog/xilinx_wwdt.c line 350
Quoted 10 lines
drivers/watchdog/xilinx_wwdt.c new file +10
-0+if (ret) +dev_info (&pdev->dev,"Configured default timeout value\n" ); + +spin_lock_init (&xdev->spinlock); +watchdog_set_drvdata (xilinx_wwdt_wdd, xdev); + + ret =devm_watchdog_register_device (dev, xilinx_wwdt_wdd); +if (ret) + goto err_clk_disable; +
At this point the watchdog is fully instantiated, and userspace may have enabled it.
drivers/watchdog/xilinx_wwdt.c line 352
Quoted 2 lines
drivers/watchdog/xilinx_wwdt.c new file +2
-0+clk_disable_unprepare (xdev->clk); +
And now its clock is getting stopped. Actually, it is getting unprepared. Does this even work ?
drivers/watchdog/xilinx_wwdt.c line 359
Quoted 7 lines
drivers/watchdog/xilinx_wwdt.c new file +7
-0+dev_info (dev,"Xilinx Window Watchdog Timer with timeout %ds\n" , + xilinx_wwdt_wdd->timeout); + +return 0 ; + +err_clk_disable: +clk_disable_unprepare (xdev->clk);
devm_add_action_or_reset() already handles this.
Quoted 24 lines
drivers/watchdog/xilinx_wwdt.c new file +23
-0+return ret; +} + +/* Mat for of_platform binding */ +static const struct of_device_id xwwdt_of_match[] = { + { .compatible ="xlnx,versal-wwdt-1.0" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, xwwdt_of_match); + +static struct platform_driver xwwdt_driver = { + .probe = xwwdt_probe, + .driver = { + .name ="Xilinx Window Watchdog" , + .of_match_table = xwwdt_of_match, + }, +}; + +module_platform_driver (xwwdt_driver); + +MODULE_AUTHOR ("Neeli Srinivas <[email protected]>" ); +MODULE_DESCRIPTION ("Xilinx Window Watchdog driver" ); +MODULE_LICENSE ("GPL" );
A message that is not in the archive (sent off-list or not yet received): DM6PR02MB538635505ABE30C42100E059AF369@DM6PR02MB5386.namprd02.prod.outlook.com
A message that is not in the archive (sent off-list or not yet received): DM6PR02MB5386C805459902F9C28391AAAF139@DM6PR02MB5386.namprd02.prod.outlook.com
Guenter Roeck
maintainerRe: [PATCH 2/3] watchdog: xilinx_wwdt: Add Versal Window watchdog mode
Quoted 4 lines · Srinivas Neeli
Hi Guenter,
If you are fine with my justification, I will send v2 with update code.
We have at least one more watchdog driver with open/closed window concepts. This is not a "pretimeout". Please see drivers/watchdog/rti_wdt.c for an example on how to handle this; essentially you have to set min_hw_heartbeat_ms to the value of the closed window timeout. The watchdog core then handles the mechanics.
You can not use "pretimeout" to set the "closed" window size; this is an ABI abuse. There is no standard ABI for this, so if you want to have it configurable it would have to be a module parameter.
Guenter
Quoted 1,209 lines
Thanks
Srinivas Neeli.*From:* Srinivas Neeli <[email protected]>
*Sent:* Wednesday, June 9, 2021 12:57 PM
*To:* Guenter Roeck <[email protected]>; Shubhrajyoti Datta <[email protected]>; Srinivas Goud <[email protected]>; Michal Simek <[email protected]> *Cc:* [email protected]; [email protected]; [email protected]; git <[email protected]>
*Subject:* RE: [PATCH 2/3] watchdog:xilinx_wwdt: Add Versal Window watchdog modeHi Guenter Roeck,
Thanks for review.
Versal platform contain System watchdog Timer. It supports two functions, Those are
1) Generic watchdog mode
2) Window watchdog mode
Right now we are implementing window watchdog timer functionality in driver.
Features of Window watchdog mode:
- The timer contains two configurable windows( closed and open).
- The timer has to restart only in open window.
- If software tries to restart out side of open window it will generate a reset.
We have a requirement for window watchdog driver, So I implemented window watchdog in two scenarios.
1) With Pre-timeout
2) With without Pre-timeout
*Scenario 1:*
With pre-timeout:
Here we will get two window concept.
1) closed window
2) Open window
start to pre-timeout, we are calling "*closed*" window.
From pre-timeout to timeout we are calling “*Open*” window.
*Operations:*
start
keep
alive(only in open window, closed window we are ignoring)stop
we don't have permission to refresh/restart our timer in closed window, So ignoring the keepalive.
Adjusted code to generate interrupt after completion of closed window. once we cross the closed window we can restart our time anytime.
Once we reaches to timeout , will get reset signal.
*Advantage:*
After getting pre-timeout notification we can reset our timer or can collect our log.
once we get interrupt we can conclude our task is not working as expected.
So we can takecare of our tasks.
*Scenario 2:*
with out pre-timeout:
It will work like general watchdog timer.
we can run keepalive
anytime(as there is no closed window, only open window present).Once we reaches to time out, will get reset.
*Operations:*
start
keep alive
stop
For more details:
https://www.xilinx.com/support/documentation/architecture-manuals/am011-versal-acap-trm.pdf <https://www.xilinx.com/support/documentation/architecture-manuals/am011-versal-acap-trm.pdf>
major comments will update in V2.
Quoted 308 lines
-----Original Message-----
From: Guenter Roeck <[email protected] <mailto:[email protected]>> On Behalf Of Guenter Roeck
Sent: Thursday, May 27, 2021 8:09 PM
To: Srinivas Neeli <[email protected] <mailto:[email protected]>>; Shubhrajyoti Datta
<[email protected] <mailto:[email protected]>>; Srinivas Goud <[email protected] <mailto:[email protected]>>; Michal Simek
<[email protected] <mailto:[email protected]>>
Cc [email protected] <mailto:[email protected]>; [email protected] <mailto:[email protected]>; linux-[email protected] <mailto:[email protected]>; git <[email protected] <mailto:[email protected]>>
Subject: Re: [PATCH 2/3] watchdog:
xilinx_wwdt: Add Versal Windowwatchdog mode
The subject is confusing. This patch does not add "Versal Window watchdog
mode", it adds a driver which supports the Versal Window watchdog. The
subject should be something like "watchdog: Add Versal Window watchdog
driver".
Quoted 11 lines · Srinivas Neeli
Versal watchdog driver uses Window watchdog mode. Window watchdog
timer(WWDT) contains closed(first) and open(second) window with
32 bit width. WWDT will generate an interrupt after the first window
timeout and reset signal after the second window timeout. Timeout and
Pre-timeout configuration, Stop and Refresh trigger only in open
window.
Does that mean that userspace can not send a keepalive before the
pretimeout expires ? That is not how this is supposed to work. If that is the
case, this is not a pretimeout. Pretimeout is supposed to be used for
emergency handling, such as triggering a crash dump. The above description
as well as the code suggests that an interrupt is all but mandatory.
Assuming that is all the case, ie that keepalive is only possible after the
interrupt was received, and that timeout updates are also only possible after
an interrupt was received, one possible handling would to record that a
keepalive was received, and to record that a request to update the timeout
was received if that happens while the window is closed. Then, when the
interrupt is received, those actions can be applied. Otherwise, if there was
no keepalive request prior to the interrupt, the interrupt handler would call
watchdog_notify_pretimeout().Of course, this is all just guesswork.
More comments below.
Guenter
Quoted 11 lines
Signed-off-by Srinivas Neeli <[email protected] <mailto:[email protected]>>---
drivers/watchdog/Kconfig | 16 ++
drivers/watchdog/Makefile | 1 +
drivers/watchdog/xilinx_wwdt.c| 382+++++++++++++++++++++++++++++++++
drivers/watchdog/Makefile obj-$(CONFIG_M54xx_WATCHDOG) +=
Quoted 69 lines
3 files changed, 399 insertions(+)create mode 100644
drivers/watchdog/xilinx_wwdt.cdrivers/watchdog/Kconfig index renamed from drivers/watchdog/Kconfig +0
-0
355100dad60a..2ed17f278783100644--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
drivers/watchdog/Kconfig index renamed from drivers/watchdog/Kconfig +0
-0@@ -307,6 +307,22 @@ config XILINX_WATCHDOGTo compile this driver as a module, choose M here: the
module will be called
of_xilinx_wdt.drivers/watchdog/Kconfig index renamed from drivers/watchdog/Kconfig +16
-0+config XILINX_WINDOW_WATCHDOG + tristate "Xilinx Window Watchdog timer" + depends on HAS_IOMEM + select WATCHDOG_CORE + help + Window Watchdog driver for the versal_wwdt ip core. + Window watchdog timer(WWDT) contains closed(first) and + open(second) window with 32 bit width. WWDT will generate + an interrupt after the first window timeout and reset + signal after the second window timeout. Timeout and + Pre-timeout configuration, Stop and Refresh trigger + only in open window. + + To compile this driver as a module, choose M here: the + module will be called xilinx_wwdt. +config
ZIIRAVE_WATCHDOGtristate "Zodiac RAVE Watchdog Timer"
depends on I2C
drivers/watchdog/Makefile +0
-0index
a7eade8b4d45..97d10c3d39c7100644--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
drivers/watchdog/Makefile +0
-0@@ -148,6 +148,7 @@ obj-$(CONFIG_M54xx_WATCHDOG) +=m54xx_wdt.o
Quoted 99 lines
drivers/watchdog/Makefile +0
-0# MicroBlaze Architectureobj-$(CONFIG_XILINX_WATCHDOG) += of_xilinx_wdt.o
+obj-$(CONFIG_XILINX_WINDOW_WATCHDOG) += xilinx_wwdt.o
# MIPS Architecture
obj-$(CONFIG_ATH79_WDT) += ath79_wdt.o diff --git
a/drivers/watchdog/xilinx_wwdt.cb/drivers/watchdog/xilinx_wwdt.cnewfile mode 100644 index 000000000000..8fa2cb2225e8
---
/dev/null+++
b/drivers/watchdog/xilinx_wwdt.cdrivers/watchdog/Makefile +38
-0@@ -0,0 +1,382 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Window Watchdog Device Driver for Xilinx Versal WWDT + * + * (C) Copyright 2021 Xilinx, Inc. + */ + +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/ioport.h> +#include <linux/of_device.h> +#include <linux/of_address.h> +#include <linux/module.h> +#include <linux/watchdog.h> + +#define XWWDT_DEFAULT_TIMEOUT 40 +#define XWWDT_MIN_TIMEOUT 1 +#define XWWDT_MAX_TIMEOUT 42 + +/* Register offsets for the WWdt device */ +#define XWWDT_MWR_OFFSET 0x00 +#define XWWDT_ESR_OFFSET 0x04 +#define XWWDT_FCR_OFFSET 0x08 +#define XWWDT_FWR_OFFSET 0x0c +#define XWWDT_SWR_OFFSET 0x10 + +/* Master Write Control Register Masks */ +#define XWWDT_MWR_MASK BIT(0) + +/* Enable and Status Register Masks */ +#define XWWDT_ESR_WINT_MASK BIT(16) +#define XWWDT_ESR_WSW_MASK BIT(8) +#define XWWDT_ESR_WEN_MASK BIT(0) + +/* Function control Register Masks */ +#define XWWDT_SBC_MASK 0xFF00 +#define XWWDT_SBC_SHIFT 16drivers/watchdog/Makefile
Quoted 10 lines
drivers/watchdog/Makefile +5
-0+#define XWWDT_BSS_MASK 0xC0 + +static int wwdt_timeout; + +module_param(wwdt_timeout, int, 0644);MODULE_PARM_DESC(wwdt_timeout,
Quoted 19 lines
+ "Watchdog time in seconds. (default="
+
__MODULE_STRING(XWWDT_DEFAULT_TIMEOUT)")");drivers/watchdog/Makefile +8
-0+ +struct xwwdt_device { + void __iomem *base; + spinlock_t spinlock; /* spinlock for register handling */ + struct watchdog_device xilinx_wwdt_wdd; + struct clk *clk; + int irq; +};Quoted 7 lines
drivers/watchdog/Makefile
Quoted 3 lines
drivers/watchdog/Makefile +2
-0+ +static int is_wwdt_in_closed_window(struct watchdog_device *wdd)should return bool
Will update in V2.
Quoted 22 lines
Quoted 21 lines
drivers/watchdog/Makefile +10
-0+{ + u32 control_status_reg; + struct xwwdt_device *xdev = watchdog_get_drvdata(wdd); + + spin_lock(&xdev->spinlock); + control_status_reg = ioread32(xdev->base + XWWDT_ESR_OFFSET); + spin_unlock(&xdev->spinlock); + if (control_status_reg & XWWDT_ESR_WEN_MASK) + if (!(control_status_reg & XWWDT_ESR_WSW_MASK)) + return 0;Quoted 7 lines
Quoted 3 lines
+
+ return 1;
Can be written as expresion without if statement
Will update in V2
Quoted 26 lines
Quoted 25 lines
drivers/watchdog/Makefile +5
-0+} + +static int xilinx_wwdt_start(struct watchdog_device *wdd) { + struct xwwdt_device *xdev = watchdog_get_drvdata(wdd); + struct watchdog_device *xilinx_wwdt_wdd = &xdev-
xilinx_wwdt_wdd;+ u64
time_out,pre_timeout, count;+ u32
control_status_reg, fcr;+ int ret;
+
+ count =
clk_get_rate(xdev->clk);+ if (!count)
Quoted 7 lines
Quoted 3 lines
+ return
-EINVAL;+
Is there a reason to believe that the clock rate can change ?
If not I would suggest to read it once and store it in struct
xwwdt_device.Will update in V2.
Quoted 14 lines
Quoted 11 lines
+ /* Calculate timeout count */
+
pre_timeout= count *wdd->pretimeout;+
time_out= count *wdd->timeout;+ if (!watchdog_active(xilinx_wwdt_wdd)) {
+ ret =
clk_enable(xdev->clk);Quoted 7 lines
This is at the very least confusing.
The last action in the probe function is to call
clk_disable_unprepare(),meaning the clock should not be prepared here. How can it be enabled
without being prepared ?
Will update in V2
Quoted 252 lines
Quoted 6 lines
+ if (ret) {
+
dev_err(wdd->parent, "Failed to enable clock\n");Quoted 7 lines
+ return ret;
+ }
+ }
+
I think it would be better to separate the functions to start/stop the clock
from the function to update/enable the watchdog. The use of
watchdog_active()combined withclk_enable/clk_disable/clk_prepare_enable/clk_disable_unprepare
is confusing and makes it all but impossible to review the driver.
Quoted 3 lines
+
spin_lock(&xdev->spinlock);+ iowrite32(XWWDT_MWR_MASK,
xdev->base+
XWWDT_MWR_OFFSET);Quoted 6 lines
+ iowrite32(~(u32)XWWDT_ESR_WEN_MASK,
+
xdev->base+XWWDT_ESR_OFFSET);+
Quoted 7 lines
+ if (
pre_timeout) {+ iowrite32((u32)(time_out -
pre_timeout),+
xdev->base+XWWDT_FWR_OFFSET);+ iowrite32((u32)pre_timeout,
xdev->base+
XWWDT_SWR_OFFSET);Quoted 8 lines
+ fcr =
ioread32(xdev->base + XWWDT_SWR_OFFSET);+ fcr = (fcr >>
XWWDT_SBC_SHIFT) &XWWDT_SBC_MASK;+ fcr = fcr |
XWWDT_BSS_MASK;+
iowrite32(fcr, xdev->base + XWWDT_FCR_OFFSET);Quoted 7 lines
+ } else {
+ iowrite32((u32)pre_timeout,
+
xdev->base+XWWDT_FWR_OFFSET);+ iowrite32((u32)time_out,
xdev->base+
XWWDT_SWR_OFFSET);Quoted 36 lines
+
iowrite32(0x0, xdev->base + XWWDT_FCR_OFFSET);+ }
drivers/watchdog/Makefile +16
-0+ + /* Enable the window watchdog timer */ + control_status_reg = ioread32(xdev->base + XWWDT_ESR_OFFSET); + control_status_reg |= XWWDT_ESR_WEN_MASK; + iowrite32(control_status_reg, xdev->base + XWWDT_ESR_OFFSET); + + spin_unlock(&xdev->spinlock); + + dev_dbg(xilinx_wwdt_wdd->parent, "Watchdog Started!\n"); + + return 0; +} + +static int xilinx_wwdt_stop(struct watchdog_device *wdd) { + struct xwwdt_device *xdev = watchdog_get_drvdata(wdd); + struct watchdog_device *xilinx_wwdt_wdd = &xdev-Quoted 7 lines
xilinx_wwdt_wdd;+
+ if (!is_wwdt_in_closed_window(wdd)) {
+ dev_warn(xilinx_wwdt_wdd->parent, "timer in closed
window");
drivers/watchdog/Makefile
Quoted 11 lines
+ return
-EINVAL;+ }
drivers/watchdog/Makefile +4
-0+ + spin_lock(&xdev->spinlock); + + iowrite32(XWWDT_MWR_MASK, xdev->base +
XWWDT_MWR_OFFSET);Quoted 7 lines
+ /* Disable the Window watchdog timer */
+ iowrite32(~(u32)XWWDT_ESR_WEN_MASK,
+
xdev->base+XWWDT_ESR_OFFSET);drivers/watchdog/Makefile +1
-0+drivers/watchdog/Makefile
Quoted 10 lines
drivers/watchdog/Makefile +5
-0+ spin_unlock(&xdev->spinlock); + + if (watchdog_active(xilinx_wwdt_wdd)) + clk_disable(xdev->clk); +The stop function won't be called if the watchdog is not running, ie if
watchdog_active()returns false.I don't undeerstand the logic of clock handling in this driver.
More on that below.
Quoted 15 lines
+
dev_dbg(xilinx_wwdt_wdd->parent, "Watchdog Stopped!\n");drivers/watchdog/Makefile +7
-0+ + return 0; +} + +static int xilinx_wwdt_keepalive(struct watchdog_device *wdd) { + u32 control_status_reg; + struct xwwdt_device *xdev = watchdog_get_drvdata(wdd);drivers/watchdog/Makefile
Quoted 10 lines
drivers/watchdog/Makefile +5
-0+ + /* Refresh in open window is ignored */ + if (!is_wwdt_in_closed_window(wdd)) + return 0; +This is dangerous. There is no reason for userspace to adhere to these
restrictions.
Quoted 5 lines
+
spin_lock(&xdev->spinlock);+
+ iowrite32(XWWDT_MWR_MASK,
xdev->base+
XWWDT_MWR_OFFSET);Quoted 38 lines
+
control_status_reg=ioread32(xdev->base + XWWDT_ESR_OFFSET);+
control_status_reg|=XWWDT_ESR_WINT_MASK;+
control_status_reg&= ~XWWDT_ESR_WSW_MASK;+
iowrite32(control_status_reg, xdev->base + XWWDT_ESR_OFFSET);+
control_status_reg=ioread32(xdev->base + XWWDT_ESR_OFFSET);+
control_status_reg|=XWWDT_ESR_WSW_MASK;+
iowrite32(control_status_reg, xdev->base + XWWDT_ESR_OFFSET);drivers/watchdog/Makefile +12
-0+ + spin_unlock(&xdev->spinlock); + + return 0; +} + +static int xilinx_wwdt_set_timeout(struct watchdog_device *wdd, + unsigned int new_time) +{ + u32 ret = 0; + struct xwwdt_device *xdev = watchdog_get_drvdata(wdd); + struct watchdog_device *xilinx_wwdt_wdd = &xdev-Quoted 7 lines
xilinx_wwdt_wdd;+
+ if (!is_wwdt_in_closed_window(wdd)) {
+ dev_warn(xilinx_wwdt_wdd->parent, "timer in closed
window");
Quoted 5 lines
+ return
-EINVAL;+ }
+
Quoted 5 lines
So userspace can clog the log by continuously trying to set the timeout ?
Also, again, this is dangerous. Userspace does not know the window size.
user can configure window size.
Quoted 382 lines
Quoted 12 lines
+ if (
new_time<XWWDT_MIN_TIMEOUT||+
new_time>XWWDT_MAX_TIMEOUT) {+ dev_warn(xilinx_wwdt_wdd->parent,
+ "timeout value must be %d<=x<=%d, using %d\n",
Quoted 7 lines
+
XWWDT_MIN_TIMEOUT,+
XWWDT_MAX_TIMEOUT,new_time);+ return
-EINVAL;+ }
This is handled by the watchdog core.
Quoted 5 lines
drivers/watchdog/Makefile +3
-0+ + wdd->timeout = new_time; + wdd->pretimeout = 0;drivers/watchdog/Makefile
Quoted 10 lines
drivers/watchdog/Makefile +5
-0+ + if (watchdog_active(xilinx_wwdt_wdd)) { + ret = xilinx_wwdt_start(wdd); + if (ret) + dev_dbg(xilinx_wwdt_wdd->parent, "timer startfailed");
Quoted 22 lines
+ }
drivers/watchdog/Makefile +10
-0+ + return ret; +} + +static int xilinx_wwdt_set_pretimeout(struct watchdog_device *wdd, + u32 new_pretimeout) +{ + u32 ret = 0; + struct xwwdt_device *xdev = watchdog_get_drvdata(wdd); + struct watchdog_device *xilinx_wwdt_wdd = &xdev-Quoted 7 lines
xilinx_wwdt_wdd;+
+ if (!is_wwdt_in_closed_window(wdd)) {
+ dev_warn(xilinx_wwdt_wdd->parent, "timer in closed
window");
Quoted 3 lines
+ return
-EINVAL;+ }
This restriction is not only dangerous but confusing, and simply unacceptable.
Userspace will get
-EINVALwith no idea what is wrong.A watchdog daemon will bail out for no good reason.
drivers/watchdog/Makefile
Quoted 9 lines
drivers/watchdog/Makefile +5
-0+ + if (new_pretimeout < wdd->min_timeout || + new_pretimeout >= wdd->timeout) + return -EINVAL; +This is handled by the watchdog core.
Quoted 11 lines
+
wdd->pretimeout=new_pretimeout;+
+ if (
watchdog_active(xilinx_wwdt_wdd)) {+ ret =
xilinx_wwdt_start(wdd);+ if (ret)
+ dev_dbg(xilinx_wwdt_wdd->parent, "timer start
failed");
Quoted 153 lines
+ }
drivers/watchdog/Makefile +76
-0+ + return ret; +} + +static void xwwdt_clk_disable_unprepare(void *data) { + clk_disable_unprepare(data); +} + +static irqreturn_t xilinx_wwdt_isr(int irq, void *wdog_arg) { + struct xwwdt_device *xdev = wdog_arg; + + watchdog_notify_pretimeout(&xdev->xilinx_wwdt_wdd); + + return IRQ_HANDLED; +} + +static const struct watchdog_info xilinx_wwdt_ident = { + .options = WDIOF_MAGICCLOSE | + WDIOF_KEEPALIVEPING | + WDIOF_SETTIMEOUT, + .firmware_version = 1, + .identity = "xlnx_window watchdog", +}; + +static const struct watchdog_info xilinx_wwdt_pretimeout_ident = { + .options = WDIOF_MAGICCLOSE | + WDIOF_KEEPALIVEPING | + WDIOF_PRETIMEOUT | + WDIOF_SETTIMEOUT, + .firmware_version = 1, + .identity = "xlnx_window watchdog", +}; + +static const struct watchdog_ops xilinx_wwdt_ops = { + .owner = THIS_MODULE, + .start = xilinx_wwdt_start, + .stop = xilinx_wwdt_stop, + .ping = xilinx_wwdt_keepalive, + .set_timeout = xilinx_wwdt_set_timeout, + .set_pretimeout = xilinx_wwdt_set_pretimeout, }; + +static int xwwdt_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; + struct watchdog_device *xilinx_wwdt_wdd; + struct xwwdt_device *xdev; + u32 pre_timeout = 0; + int ret; + + xdev = devm_kzalloc(dev, sizeof(*xdev), GFP_KERNEL); + if (!xdev) + return -ENOMEM; + + xilinx_wwdt_wdd = &xdev->xilinx_wwdt_wdd; + xilinx_wwdt_wdd->info = &xilinx_wwdt_ident; + xilinx_wwdt_wdd->ops = &xilinx_wwdt_ops; + xilinx_wwdt_wdd->parent = dev; + + xdev->base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(xdev->base)) + return PTR_ERR(xdev->base); + + ret = of_property_read_u32(dev->of_node, "pretimeout-sec", + &pre_timeout); + if (ret) + dev_dbg(dev, + "Parameter \"pretimeout-sec\" not found\n"); + + xdev->clk = devm_clk_get(dev, NULL); + if (IS_ERR(xdev->clk)) + return PTR_ERR(xdev->clk); + + ret = clk_get_rate(xdev->clk); + if (!ret) + return -EINVAL; + + ret = clk_prepare_enable(xdev->clk);drivers/watchdog/Makefile
Quoted 10 lines
drivers/watchdog/Makefile +5
-0+ if (ret) { + dev_err(dev, "unable to enable clock\n"); + return ret; + } + ret = devm_add_action_or_reset(dev,
xwwdt_clk_disable_unprepare,Quoted 7 lines
+
xdev->clk);+ if (ret)
+ goto
err_clk_disable;+
Seems pointless. What happens when you unload the driver ?
Quoted 29 lines
+
xilinx_wwdt_wdd->pretimeout=pre_timeout;+
xilinx_wwdt_wdd->timeout=XWWDT_DEFAULT_TIMEOUT;+
xilinx_wwdt_wdd->min_timeout=XWWDT_MIN_TIMEOUT;+
xilinx_wwdt_wdd->max_timeout=XWWDT_MAX_TIMEOUT;drivers/watchdog/Makefile +11
-0+ + xdev->irq = platform_get_irq_byname(pdev, "wdt"); + if (xdev->irq < 0) { + ret = xdev->irq; + goto err_clk_disable; + } + + if (!devm_request_irq(dev, xdev->irq, xilinx_wwdt_isr, + 0, dev_name(dev), xdev)) { + xilinx_wwdt_wdd->info = &xilinx_wwdt_pretimeout_ident; + }drivers/watchdog/Makefile
Quoted 10 lines
drivers/watchdog/Makefile +5
-0+ + ret = watchdog_init_timeout(xilinx_wwdt_wdd, + wwdt_timeout, &pdev->dev); + if (ret) + dev_info(&pdev->dev, "Configured default timeoutvalue\n");
Quoted 5 lines
drivers/watchdog/Makefile +3
-0+ + spin_lock_init(&xdev->spinlock); + watchdog_set_drvdata(xilinx_wwdt_wdd, xdev);drivers/watchdog/Makefile
Quoted 10 lines
drivers/watchdog/Makefile +5
-0+ + ret = devm_watchdog_register_device(dev, xilinx_wwdt_wdd); + if (ret) + goto err_clk_disable; +At this point the watchdog is fully instantiated, and userspace may have
enabled it.
Quoted 3 lines
+
clk_disable_unprepare(xdev->clk);+
And now its clock is getting stopped. Actually, it is getting unprepared.
Does this even work ?
Quoted 9 lines
+ dev_info(dev, "Xilinx Window Watchdog Timer with timeout %ds\n",
+
xilinx_wwdt_wdd->timeout);drivers/watchdog/Makefile +3
-0+ + return 0; +Quoted 57 lines
Quoted 3 lines
+err_clk_disable:
+
clk_disable_unprepare(xdev->clk);
devm_add_action_or_reset()already handles this.Quoted 47 lines
+ return ret;
drivers/watchdog/Makefile +22
-0+} + +/* Mat for of_platform binding */ +static const struct of_device_id xwwdt_of_match[] = { + { .compatible = "xlnx,versal-wwdt-1.0", }, + {}, +}; +MODULE_DEVICE_TABLE(of, xwwdt_of_match); + +static struct platform_driver xwwdt_driver = { + .probe = xwwdt_probe, + .driver = { + .name = "Xilinx Window Watchdog", + .of_match_table = xwwdt_of_match, + }, +}; + +module_platform_driver(xwwdt_driver); + +MODULE_AUTHOR("Neeli Srinivas <[email protected] <mailto:[email protected]>>"); +MODULE_DESCRIPTION("Xilinx Window Watchdog driver"); +MODULE_LICENSE("GPL");Thanks
Srinivas Neeli.
RE: [PATCH 2/3] watchdog: xilinx_wwdt: Add Versal Window watchdog mode
Hi Guenter,
I went through reference "rti_wdt.c" driver. It implemented Window watchdog with few limitations. Limitations:
---------------
1) Not able to configure Closed window and Open window separately.
Because of xilinx window watchdog supports separate configurable closed and open windows.
2) In case of rti driver, if any bad event(error event) occur due to any user space event like ping then the watchdog core bypassing the ping call.
But in case of xilinx watchdog there are separate register bits for counting error events.
So if I implement driver in similar to rti-wdt.c driver, then we can not be able read the error events from the registers.
So is this ok because we are not notifying the errors to user.
Thanks
Srinivas Neeli
Quoted 1,327 lines
-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Wednesday, July 14, 2021 5:01 PM
To: Srinivas Neeli <[email protected]>; Shubhrajyoti Datta <[email protected]>; Srinivas Goud <[email protected]>; Michal Simek <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; git <[email protected]>
Subject: Re: [PATCH 2/3] watchdog:xilinx_wwdt: Add Versal Window watchdog modeQuoted 4 lines · Srinivas Neeli
Hi Guenter,
If you are fine with my justification, I will send v2 with update code.
We have at least one more watchdog driver with open/closed window concepts.
This is not a "pretimeout". Please seedrivers/watchdog/rti_wdt.cfor an example on how to handle this; essentially you have to setmin_hw_heartbeat_msto the value of the closed window timeout. The watchdog core then handles the mechanics.You can not use "pretimeout" to set the "closed" window size; this is an ABI abuse. There is no standard ABI for this, so if you want to have it configurable it would have to be a module parameter.
Guenter
Quoted 17 lines
Thanks
Srinivas Neeli.*From:* Srinivas Neeli <[email protected]>
*Sent:* Wednesday, June 9, 2021 12:57 PM
*To:* Guenter Roeck <[email protected]>; Shubhrajyoti Datta <[email protected]>; Srinivas Goud <[email protected]>; Michal Simek <[email protected]>
*Cc:* [email protected]; [email protected]; [email protected]; git <[email protected]> *Subject:* RE: [PATCH 2/3] watchdog:xilinx_wwdt: Add Versal Window watchdog modeHi Guenter Roeck,
Thanks for review.
Quoted 8 lines
Versal platform contain System watchdog Timer. It supports two functions, Those are
1) Generic watchdog mode
2) Window watchdog mode
Right now we are implementing window watchdog timer functionality in
driver.
Quoted 8 lines
Features of Window watchdog mode:
- The timer contains two configurable windows( closed and open).
- The timer has to restart only in open window.
- If software tries to restart out side of open window it will generate a
reset.
Quoted 2 lines
We have a requirement for window watchdog driver, So I implemented
window watchdog in two scenarios.
Quoted 21 lines
1) With Pre-timeout
2) With without Pre-timeout
*Scenario 1:*
With pre-timeout:
Here we will get two window concept.
1) closed window
2) Open window
start to pre-timeout, we are calling "*closed*" window.
From pre-timeout to timeout we are calling “*Open*” window.
*Operations:*
Quoted 7 lines
start
keep
alive(only in open window, closed window we are ignoring)stop
we don't have permission to refresh/restart our timer in closed window, So
ignoring the keepalive.
Quoted 2 lines
Adjusted code to generate interrupt after completion of closed window.
once we cross the closed window we can restart our time anytime.
Quoted 6 lines
Once we reaches to timeout , will get reset signal.
*Advantage:*
After getting pre-timeout notification we can reset our timer or can collect
our log.
Quoted 5 lines
once we get interrupt we can conclude our task is not working as expected.
So we can takecare of our tasks.
Quoted 7 lines
*Scenario 2:*
with out pre-timeout:
It will work like general watchdog timer.
we can run keepalive anytime(as there is no closed window, only open
window present).
Quoted 7 lines
Once we reaches to time out, will get reset.
*Operations:*
start
Quoted 7 lines
keep alive
stop
For more details:
manuals/am01
Quoted 2 lines
1-versal-acap-trm.pdf
<https://www.xilinx.com/support/documentation/architecture-manuals/am0
Quoted 7 lines
11-versal-acap-trm.pdf>
major comments will update in V2.
Quoted 3 lines
-----Original Message-----
From: Guenter Roeck <[email protected]
<mailto:[email protected]>>
Quoted 25 lines
On Behalf Of Guenter Roeck
Quoted 3 lines
Sent: Thursday, May 27, 2021 8:09 PM
To: Srinivas Neeli <[email protected] <mailto:[email protected]>>;
Shubhrajyoti Datta
Quoted 1 line
<[email protected] <mailto:[email protected]>>; Srinivas Goud
<[email protected] <mailto:[email protected]>>; Michal Simek
Quoted 3 lines
<[email protected] <mailto:[email protected]>>
Cc [email protected] <mailto:[email protected]>;[email protected]
<mailto:[email protected]>; linux-Quoted 1 line
[email protected] <mailto:[email protected]>; git
<[email protected] <mailto:[email protected]>>
Quoted 5 lines
Subject: Re: [PATCH 2/3] watchdog:
xilinx_wwdt: Add Versal Windowwatchdog mode
Quoted 16 lines
Quoted 1 line
The subject is confusing. This patch does not add "Versal Window
watchdog
Quoted 1 line
mode", it adds a driver which supports the Versal Window watchdog.
The
Quoted 1 line
subject should be something like "watchdog: Add Versal Window
watchdog
Quoted 7 lines
driver".
Quoted 1 line · Srinivas Neeli
Versal watchdog driver uses Window watchdog mode. Window
watchdog
Quoted 747 lines
Quoted 4 lines
Quoted 4 lines
timer(WWDT) contains closed(first) and open(second) window with
32 bit width. WWDT will generate an interrupt after the first
window
Quoted 1 line
Quoted 1 line
timeout and reset signal after the second window timeout. Timeout
and
Quoted 9 lines
Quoted 3 lines
Pre-timeout configuration, Stop and Refresh trigger only in open
window.
Does that mean that userspace can not send a keepalive before the
pretimeout expires ? That is not how this is supposed to work. If
that is the
Quoted 1 line
case, this is not a pretimeout. Pretimeout is supposed to be used
for
Quoted 1 line
emergency handling, such as triggering a crash dump. The above
description
Quoted 5 lines
as well as the code suggests that an interrupt is all but mandatory.
Assuming that is all the case, ie that keepalive is only possible
after the
Quoted 1 line
interrupt was received, and that timeout updates are also only
possible after
Quoted 1 line
an interrupt was received, one possible handling would to record
that a
Quoted 1 line
keepalive was received, and to record that a request to update the
timeout
Quoted 1 line
was received if that happens while the window is closed. Then, when
the
Quoted 1 line
interrupt is received, those actions can be applied. Otherwise, if
there was
Quoted 1 line
no keepalive request prior to the interrupt, the interrupt handler
would call
Quoted 8 lines
watchdog_notify_pretimeout().Of course, this is all just guesswork.
Quoted 11 lines
More comments below.
Guenter
Quoted 3 lines
Signed-off-by Srinivas Neeli <[email protected]<mailto:[email protected]>>
Quoted 10 lines
Quoted 7 lines
---
drivers/watchdog/Kconfig | 16 ++
drivers/watchdog/Makefile | 1 +
drivers/watchdog/xilinx_wwdt.c| 382+++++++++++++++++++++++++++++++++
Quoted 7 lines
drivers/watchdog/Kconfig
Quoted 7 lines
3 files changed, 399 insertions(+)create mode 100644
drivers/watchdog/xilinx_wwdt.cdrivers/watchdog/Kconfig +0
-0index
Quoted 22 lines
Quoted 21 lines
355100dad60a..2ed17f278783100644--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
drivers/watchdog/Kconfig +0
-0@@ -307,6 +307,22 @@ config XILINX_WATCHDOGTo compile this driver as a module, choose M here: the
module will be called
of_xilinx_wdt.+config
XILINX_WINDOW_WATCHDOG+ tristate "Xilinx Window Watchdog timer"
+ depends on
HAS_IOMEM+ select
WATCHDOG_COREQuoted 7 lines
Quoted 7 lines
+ help
+ Window Watchdog driver for the
versal_wwdtip core.+ Window watchdog timer(WWDT) contains closed(first) and
+ open(second) window with 32 bit width. WWDT will
generate
Quoted 16 lines
Quoted 15 lines
+ an interrupt after the first window timeout and reset
+ signal after the second window timeout. Timeout and
+ Pre-timeout configuration, Stop and Refresh trigger
+ only in open window.
drivers/watchdog/Kconfig +4
-0+ + To compile this driver as a module, choose M here: the + module will be called xilinx_wwdt. +Quoted 7 lines
Review
Quoted 7 lines
config
ZIIRAVE_WATCHDOGtristate "Zodiac RAVE Watchdog Timer"
depends on I2C
(quoted diff) +0
-0b/drivers/watchdog/Makefile
Quoted 25 lines
drivers/watchdog/Kconfig obj-$(CONFIG_M54xx_WATCHDOG) +=
Quoted 7 lines
index
a7eade8b4d45..97d10c3d39c7100644--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
drivers/watchdog/Kconfig +0
-0@@ -148,6 +148,7 @@ obj-$(CONFIG_M54xx_WATCHDOG) +=m54xx_wdt.o
Quoted 15 lines
drivers/watchdog/Kconfig +0
-0# MicroBlaze Architectureobj-$(CONFIG_XILINX_WATCHDOG) += of_xilinx_wdt.o
+obj-$(CONFIG_XILINX_WINDOW_WATCHDOG) += xilinx_wwdt.o
# MIPS Architecture
obj-$(CONFIG_ATH79_WDT) += ath79_wdt.o diff --git
a/drivers/watchdog/xilinx_wwdt.cb/drivers/watchdog/xilinx_wwdt.cnew
Quoted 88 lines
Quoted 87 lines
file mode 100644 index 000000000000..8fa2cb2225e8
---
/dev/null+++
b/drivers/watchdog/xilinx_wwdt.cdrivers/watchdog/Kconfig +40
-0@@ -0,0 +1,382 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Window Watchdog Device Driver for Xilinx Versal WWDT + * + * (C) Copyright 2021 Xilinx, Inc. + */ + +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/ioport.h> +#include <linux/of_device.h> +#include <linux/of_address.h> +#include <linux/module.h> +#include <linux/watchdog.h> + +#define XWWDT_DEFAULT_TIMEOUT 40 +#define XWWDT_MIN_TIMEOUT 1 +#define XWWDT_MAX_TIMEOUT 42 + +/* Register offsets for the WWdt device */ +#define XWWDT_MWR_OFFSET 0x00 +#define XWWDT_ESR_OFFSET 0x04 +#define XWWDT_FCR_OFFSET 0x08 +#define XWWDT_FWR_OFFSET 0x0c +#define XWWDT_SWR_OFFSET 0x10 + +/* Master Write Control Register Masks */ +#define XWWDT_MWR_MASK BIT(0) + +/* Enable and Status Register Masks */ +#define XWWDT_ESR_WINT_MASK BIT(16) +#define XWWDT_ESR_WSW_MASK BIT(8) +#define XWWDT_ESR_WEN_MASK BIT(0) + +/* Function control Register Masks */ +#define XWWDT_SBC_MASK 0xFF00 +#define XWWDT_SBC_SHIFT 16 +#define XWWDT_BSS_MASK 0xC0 +Quoted 11 lines
drivers/watchdog/Kconfig
Quoted 5 lines
drivers/watchdog/Kconfig +3
-0+static int wwdt_timeout; + +module_param(wwdt_timeout, int, 0644);MODULE_PARM_DESC(wwdt_timeout,
Quoted 3 lines
+ "Watchdog time in seconds. (default="
+
__MODULE_STRING(XWWDT_DEFAULT_TIMEOUT)")");
Quoted 16 lines
Quoted 15 lines
drivers/watchdog/Kconfig +8
-0+ +struct xwwdt_device { + void __iomem *base; + spinlock_t spinlock; /* spinlock for register handling */ + struct watchdog_device xilinx_wwdt_wdd; + struct clk *clk; + int irq; +};Quoted 7 lines
drivers/watchdog/Kconfig
Quoted 3 lines
drivers/watchdog/Kconfig +2
-0+ +static int is_wwdt_in_closed_window(struct watchdog_device *wdd)should return bool
Will update in V2.
Quoted 6 lines
Quoted 5 lines
+{
+ u32
control_status_reg;Quoted 7 lines
Quoted 7 lines
+ struct
xwwdt_device*xdev =watchdog_get_drvdata(wdd);+
+
spin_lock(&xdev->spinlock);+
control_status_reg= ioread32(xdev->base +
XWWDT_ESR_OFFSET);Quoted 5 lines
Quoted 5 lines
+
spin_unlock(&xdev->spinlock);+ if (
control_status_reg&XWWDT_ESR_WEN_MASK)+ if (!(control_status_reg &
XWWDT_ESR_WSW_MASK))Quoted 9 lines
Quoted 5 lines
+ return 0;
+
+ return 1;
Can be written as expresion without if statement
Will update in V2
Quoted 26 lines
Quoted 25 lines
drivers/watchdog/Kconfig +5
-0+} + +static int xilinx_wwdt_start(struct watchdog_device *wdd) { + struct xwwdt_device *xdev = watchdog_get_drvdata(wdd); + struct watchdog_device *xilinx_wwdt_wdd = &xdev-
xilinx_wwdt_wdd;+ u64
time_out,pre_timeout, count;+ u32
control_status_reg, fcr;+ int ret;
+
+ count =
clk_get_rate(xdev->clk);+ if (!count)
Quoted 7 lines
Quoted 3 lines
+ return
-EINVAL;+
Is there a reason to believe that the clock rate can change ?
If not I would suggest to read it once and store it in struct
xwwdt_device.Will update in V2.
Quoted 10 lines
Quoted 9 lines
+ /* Calculate timeout count */
+
pre_timeout= count *wdd->pretimeout;+
time_out= count *wdd->timeout;+ if (!watchdog_active(xilinx_wwdt_wdd)) {
Quoted 7 lines
Quoted 1 line
+ ret =
clk_enable(xdev->clk);This is at the very least confusing.
The last action in the probe function is to call
clk_disable_unprepare(),Quoted 1 line
meaning the clock should not be prepared here. How can it be
enabled
Quoted 1 line
without being prepared ?
Will update in V2
Quoted 5 lines
Quoted 5 lines
+ if (ret) {
+ dev_err(wdd->parent,
"Failed to enable clock\n");
Quoted 9 lines
Quoted 7 lines
+ return ret;
+ }
+ }
+
I think it would be better to separate the functions to start/stop
the clock
Quoted 10 lines
from the function to update/enable the watchdog. The use of
watchdog_active()combined withclk_enable/clk_disable/clk_prepare_enable/clk_disable_unprepare
is confusing and makes it all but impossible to review the driver.
Quoted 17 lines
Quoted 3 lines
+
spin_lock(&xdev->spinlock);+ iowrite32(XWWDT_MWR_MASK,
xdev->base+
XWWDT_MWR_OFFSET);Quoted 11 lines
+ iowrite32(~(u32)XWWDT_ESR_WEN_MASK,
+
xdev->base+XWWDT_ESR_OFFSET);+
+ if (
pre_timeout) {+ iowrite32((u32)(time_out -
pre_timeout),+
xdev->base+
XWWDT_FWR_OFFSET);Quoted 5 lines
Quoted 1 line
+ iowrite32((u32)pre_timeout,
xdev->base+
XWWDT_SWR_OFFSET);Quoted 1 line
+ fcr = ioread32(xdev->base +
XWWDT_SWR_OFFSET);Quoted 1 line
Quoted 1 line
+ fcr = (fcr >>
XWWDT_SBC_SHIFT) &
XWWDT_SBC_MASK;Quoted 3 lines
Quoted 3 lines
+ fcr = fcr |
XWWDT_BSS_MASK;+ iowrite32(fcr,
xdev->base+
XWWDT_FCR_OFFSET);Quoted 5 lines
Quoted 5 lines
+ } else {
+ iowrite32((u32)pre_timeout,
+
xdev->base+
XWWDT_FWR_OFFSET);Quoted 5 lines
Quoted 1 line
+ iowrite32((u32)time_out,
xdev->base+
XWWDT_SWR_OFFSET);Quoted 1 line
+ iowrite32(0x0,
xdev->base+
XWWDT_FCR_OFFSET);Quoted 7 lines
Quoted 7 lines
+ }
+
+ /* Enable the window watchdog timer */
+
control_status_reg= ioread32(xdev->base +
XWWDT_ESR_OFFSET);Quoted 3 lines
Quoted 3 lines
+
control_status_reg|=XWWDT_ESR_WEN_MASK;+ iowrite32(control_status_reg,
xdev->base+
XWWDT_ESR_OFFSET);Quoted 22 lines
Quoted 21 lines
drivers/watchdog/Kconfig +11
-0+ + spin_unlock(&xdev->spinlock); + + dev_dbg(xilinx_wwdt_wdd->parent, "Watchdog Started!\n"); + + return 0; +} + +static int xilinx_wwdt_stop(struct watchdog_device *wdd) { + struct xwwdt_device *xdev = watchdog_get_drvdata(wdd); + struct watchdog_device *xilinx_wwdt_wdd = &xdev-Quoted 7 lines
Quoted 7 lines
xilinx_wwdt_wdd;+
+ if (!is_wwdt_in_closed_window(wdd)) {
+ dev_warn(xilinx_wwdt_wdd->parent, "timer
in closed
Quoted 30 lines
window");
drivers/watchdog/Kconfig
Quoted 11 lines
+ return
-EINVAL;+ }
drivers/watchdog/Kconfig +4
-0+ + spin_lock(&xdev->spinlock); + + iowrite32(XWWDT_MWR_MASK, xdev->base +
XWWDT_MWR_OFFSET);Quoted 13 lines
+ /* Disable the Window watchdog timer */
+ iowrite32(~(u32)XWWDT_ESR_WEN_MASK,
+
xdev->base+XWWDT_ESR_OFFSET);drivers/watchdog/Kconfig +4
-0+ + spin_unlock(&xdev->spinlock); + + if (watchdog_active(xilinx_wwdt_wdd))Quoted 7 lines
Quoted 3 lines
+
clk_disable(xdev->clk);+
The stop function won't be called if the watchdog is not running,
ie if
Quoted 28 lines
watchdog_active()returns false.I don't undeerstand the logic of clock handling in this driver.
More on that below.
Quoted 19 lines
+
dev_dbg(xilinx_wwdt_wdd->parent, "Watchdog Stopped!\n");drivers/watchdog/Kconfig +9
-0+ + return 0; +} + +static int xilinx_wwdt_keepalive(struct watchdog_device *wdd) { + u32 control_status_reg; + struct xwwdt_device *xdev = watchdog_get_drvdata(wdd); + + /* Refresh in open window is ignored */Quoted 7 lines
Quoted 5 lines
+ if (!is_wwdt_in_closed_window(wdd))
+ return 0;
+
This is dangerous. There is no reason for userspace to adhere to
these
Quoted 4 lines
restrictions.
Quoted 9 lines
Quoted 5 lines
+
spin_lock(&xdev->spinlock);+
+ iowrite32(XWWDT_MWR_MASK,
xdev->base+
XWWDT_MWR_OFFSET);Quoted 1 line
+
control_status_reg= ioread32(xdev->base +
XWWDT_ESR_OFFSET);Quoted 5 lines
Quoted 5 lines
+
control_status_reg|=XWWDT_ESR_WINT_MASK;+
control_status_reg&= ~XWWDT_ESR_WSW_MASK;+ iowrite32(control_status_reg,
xdev->base+
XWWDT_ESR_OFFSET);Quoted 1 line
Quoted 1 line
+
control_status_reg= ioread32(xdev->base +
XWWDT_ESR_OFFSET);Quoted 3 lines
Quoted 3 lines
+
control_status_reg|=XWWDT_ESR_WSW_MASK;+ iowrite32(control_status_reg,
xdev->base+
XWWDT_ESR_OFFSET);Quoted 8 lines
Quoted 7 lines
drivers/watchdog/Kconfig +4
-0+ + spin_unlock(&xdev->spinlock); + + return 0;Quoted 7 lines
drivers/watchdog/Kconfig
Quoted 7 lines
drivers/watchdog/Kconfig +4
-0+} + +static int xilinx_wwdt_set_timeout(struct watchdog_device *wdd, +unsigned int
new_time)Quoted 8 lines
Quoted 7 lines
+{
+ u32 ret = 0;
+ struct
xwwdt_device*xdev =watchdog_get_drvdata(wdd);+ struct
watchdog_device*xilinx_wwdt_wdd= &xdev-Quoted 7 lines
Quoted 7 lines
xilinx_wwdt_wdd;+
+ if (!is_wwdt_in_closed_window(wdd)) {
+ dev_warn(xilinx_wwdt_wdd->parent, "timer
in closed
Quoted 10 lines
window");
Quoted 5 lines
+ return
-EINVAL;+ }
+
Quoted 5 lines
So userspace can clog the log by continuously trying to set the timeout ?
Also, again, this is dangerous. Userspace does not know the window size.
user can configure window size.
Quoted 11 lines
Quoted 11 lines
+ if (
new_time<XWWDT_MIN_TIMEOUT||+
new_time>XWWDT_MAX_TIMEOUT) {+ dev_warn(xilinx_wwdt_wdd->parent,
+ "timeout value must be
%d<=x<=%d, using %d\n",
Quoted 3 lines
Quoted 3 lines
+
XWWDT_MIN_TIMEOUT,+
XWWDT_MAX_TIMEOUT,
new_time);Quoted 25 lines
Quoted 3 lines
+ return
-EINVAL;+ }
This is handled by the watchdog core.
Quoted 15 lines
drivers/watchdog/Kconfig +8
-0+ + wdd->timeout = new_time; + wdd->pretimeout = 0; + + if (watchdog_active(xilinx_wwdt_wdd)) { + ret = xilinx_wwdt_start(wdd); + if (ret) +dev_dbg(xilinx_wwdt_wdd->parent, "timer start
Quoted 13 lines
failed");
Quoted 11 lines
+ }
drivers/watchdog/Kconfig +5
-0+ + return ret; +} + +static int xilinx_wwdt_set_pretimeout(struct watchdog_device*wdd,
Quoted 1 line
Quoted 1 line
+ u32
new_pretimeout)Quoted 7 lines
Quoted 7 lines
+{
+ u32 ret = 0;
+ struct
xwwdt_device*xdev =watchdog_get_drvdata(wdd);+ struct
watchdog_device*xilinx_wwdt_wdd= &xdev-Quoted 18 lines
Quoted 7 lines
Quoted 7 lines
xilinx_wwdt_wdd;+
+ if (!is_wwdt_in_closed_window(wdd)) {
+ dev_warn(xilinx_wwdt_wdd->parent, "timer
in closed
Quoted 9 lines
window");
Quoted 3 lines
+ return
-EINVAL;+ }
This restriction is not only dangerous but confusing, and simply
unacceptable.
Quoted 373 lines
Quoted 11 lines
Userspace will get
-EINVALwith no idea what is wrong.A watchdog daemon will bail out for no good reason.
Quoted 3 lines
+
+ if (
new_pretimeout<wdd->min_timeout||Quoted 21 lines
Quoted 5 lines
+
new_pretimeout>=wdd->timeout)+ return
-EINVAL;+
This is handled by the watchdog core.
Quoted 11 lines
+
wdd->pretimeout=new_pretimeout;drivers/watchdog/Kconfig +5
-0+ + if (watchdog_active(xilinx_wwdt_wdd)) { + ret = xilinx_wwdt_start(wdd); + if (ret) +dev_dbg(xilinx_wwdt_wdd->parent, "timer start
Quoted 53 lines
failed");
Quoted 51 lines
+ }
drivers/watchdog/Kconfig +25
-0+ + return ret; +} + +static void xwwdt_clk_disable_unprepare(void *data) { + clk_disable_unprepare(data); +} + +static irqreturn_t xilinx_wwdt_isr(int irq, void *wdog_arg) { + struct xwwdt_device *xdev = wdog_arg; + + watchdog_notify_pretimeout(&xdev->xilinx_wwdt_wdd); + + return IRQ_HANDLED; +} + +static const struct watchdog_info xilinx_wwdt_ident = { + .options = WDIOF_MAGICCLOSE | + WDIOF_KEEPALIVEPING | + WDIOF_SETTIMEOUT, + .firmware_version = 1, + .identity = "xlnx_window watchdog", +}; + +static const struct watchdog_info xilinx_wwdt_pretimeout_ident ={
Quoted 68 lines
Quoted 67 lines
+ .options =
WDIOF_MAGICCLOSE|+
WDIOF_KEEPALIVEPING|+
WDIOF_PRETIMEOUT|+
WDIOF_SETTIMEOUT,+ .firmware_version = 1,
+ .identity = "
xlnx_windowwatchdog",drivers/watchdog/Kconfig +28
-0+}; + +static const struct watchdog_ops xilinx_wwdt_ops = { + .owner = THIS_MODULE, + .start = xilinx_wwdt_start, + .stop = xilinx_wwdt_stop, + .ping = xilinx_wwdt_keepalive, + .set_timeout = xilinx_wwdt_set_timeout, + .set_pretimeout = xilinx_wwdt_set_pretimeout, }; + +static int xwwdt_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; + struct watchdog_device *xilinx_wwdt_wdd; + struct xwwdt_device *xdev; + u32 pre_timeout = 0; + int ret; + + xdev = devm_kzalloc(dev, sizeof(*xdev), GFP_KERNEL); + if (!xdev) + return -ENOMEM; + + xilinx_wwdt_wdd = &xdev->xilinx_wwdt_wdd; + xilinx_wwdt_wdd->info = &xilinx_wwdt_ident; + xilinx_wwdt_wdd->ops = &xilinx_wwdt_ops; + xilinx_wwdt_wdd->parent = dev; + + xdev->base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(xdev->base))Quoted 7 lines
drivers/watchdog/Kconfig
Quoted 7 lines
+ return
PTR_ERR(xdev->base);drivers/watchdog/Kconfig +3
-0+ + ret = of_property_read_u32(dev->of_node, "pretimeout-sec", +
&pre_timeout);Quoted 5 lines
Quoted 5 lines
+ if (ret)
+ dev_dbg(dev,
+ "Parameter
\"pretimeout-sec\" not found\n");
Quoted 24 lines
Quoted 23 lines
drivers/watchdog/Kconfig +12
-0+ + xdev->clk = devm_clk_get(dev, NULL); + if (IS_ERR(xdev->clk)) + return PTR_ERR(xdev->clk); + + ret = clk_get_rate(xdev->clk); + if (!ret) + return -EINVAL; + + ret = clk_prepare_enable(xdev->clk); + if (ret) { + dev_err(dev, "unable to enable clock\n");Quoted 9 lines
Quoted 5 lines
+ return ret;
+ }
+ ret = devm_add_action_or_reset(dev,
xwwdt_clk_disable_unprepare,Quoted 1 line
+
xdev->clk);Quoted 37 lines
Quoted 5 lines
+ if (ret)
+ goto
err_clk_disable;+
Seems pointless. What happens when you unload the driver ?
Quoted 25 lines
+
xilinx_wwdt_wdd->pretimeout=pre_timeout;+
xilinx_wwdt_wdd->timeout=XWWDT_DEFAULT_TIMEOUT;+
xilinx_wwdt_wdd->min_timeout=XWWDT_MIN_TIMEOUT;+
xilinx_wwdt_wdd->max_timeout=XWWDT_MAX_TIMEOUT;drivers/watchdog/Kconfig +9
-0+ + xdev->irq = platform_get_irq_byname(pdev, "wdt"); + if (xdev->irq < 0) { + ret = xdev->irq; + goto err_clk_disable; + } + + if (!devm_request_irq(dev, xdev->irq, xilinx_wwdt_isr, + 0, dev_name(dev),xdev)) {
Quoted 1 line
Quoted 1 line
+
xilinx_wwdt_wdd->info=
&xilinx_wwdt_pretimeout_ident;Quoted 7 lines
drivers/watchdog/Kconfig
Quoted 7 lines
+ }
drivers/watchdog/Kconfig +3
-0+ + ret = watchdog_init_timeout(xilinx_wwdt_wdd, +
wwdt_timeout,&pdev->dev);Quoted 3 lines
Quoted 3 lines
+ if (ret)
+ dev_info(&pdev->dev, "Configured default
timeout
Quoted 12 lines
value\n");
Quoted 9 lines
drivers/watchdog/Kconfig +5
-0+ + spin_lock_init(&xdev->spinlock); + watchdog_set_drvdata(xilinx_wwdt_wdd, xdev); + + ret = devm_watchdog_register_device(dev, xilinx_wwdt_wdd);Quoted 7 lines
Quoted 5 lines
+ if (ret)
+ goto
err_clk_disable;+
At this point the watchdog is fully instantiated, and userspace may
have
Quoted 4 lines
enabled it.
Quoted 11 lines
Quoted 3 lines
+
clk_disable_unprepare(xdev->clk);+
And now its clock is getting stopped. Actually, it is getting unprepared.
Does this even work ?
Quoted 1 line
+ dev_info(dev, "Xilinx Window Watchdog Timer with timeout
%ds\n",
Quoted 8 lines
Quoted 7 lines
+
xilinx_wwdt_wdd->timeout);drivers/watchdog/Kconfig +3
-0+ + return 0; +Quoted 51 lines
Quoted 3 lines
+err_clk_disable:
+
clk_disable_unprepare(xdev->clk);
devm_add_action_or_reset()already handles this.Quoted 41 lines
+ return ret;
drivers/watchdog/Kconfig +20
-0+} + +/* Mat for of_platform binding */ +static const struct of_device_id xwwdt_of_match[] = { + { .compatible = "xlnx,versal-wwdt-1.0", }, + {}, +}; +MODULE_DEVICE_TABLE(of, xwwdt_of_match); + +static struct platform_driver xwwdt_driver = { + .probe = xwwdt_probe, + .driver = { + .name = "Xilinx Window Watchdog", + .of_match_table = xwwdt_of_match, + }, +}; + +module_platform_driver(xwwdt_driver); + +MODULE_AUTHOR("Neeli Srinivas <[email protected]<mailto:[email protected]>>");
Quoted 5 lines
drivers/watchdog/Kconfig
Quoted 5 lines
drivers/watchdog/Kconfig +2
-0+MODULE_DESCRIPTION("Xilinx Window Watchdog driver"); +MODULE_LICENSE("GPL");Thanks
Srinivas Neeli.
RE: [PATCH 2/3] watchdog: xilinx_wwdt: Add Versal Window watchdog mode
Hi Guenter,
Could you please share your comments on below limitations.
Thanks
Srinivas Neeli
Quoted 1,377 lines
-----Original Message-----
From: Srinivas Neeli <[email protected]>
Sent: Wednesday, September 29, 2021 12:32 PM
To: Guenter Roeck <[email protected]>; Shubhrajyoti Datta <[email protected]>; Srinivas Goud <[email protected]>; Michal Simek <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; git <[email protected]>
Subject: RE: [PATCH 2/3] watchdog:xilinx_wwdt: Add Versal Window watchdog modeHi Guenter,
I went through reference "
rti_wdt.c" driver. It implemented Window watchdog with few limitations.
Limitations:
---------------
1) Not able to configure Closed window and Open window separately. Because of xilinx window watchdog supports separate configurable
closed and open windows.
2) In case of rti driver, if any bad event(error event) occur due to any user space event like ping then
the watchdog core bypassing the ping call.
But in case of xilinx watchdog there are separate register bits for counting
error events.
So if I implement driver in similar torti-wdt.cdriver, then we can not
be able read the error events from
the registers.
So is this ok because we are not notifying the errors to user.Thanks
Srinivas NeeliQuoted 103 lines
-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Wednesday, July 14, 2021 5:01 PM
To: Srinivas Neeli <[email protected]>; Shubhrajyoti Datta <[email protected]>; Srinivas Goud <[email protected]>; Michal Simek <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; git <[email protected]>
Subject: Re: [PATCH 2/3] watchdog:xilinx_wwdt: Add Versal Window watchdog modeQuoted 4 lines · Srinivas Neeli
Hi Guenter,
If you are fine with my justification, I will send v2 with update code.
We have at least one more watchdog driver with open/closed window concepts.
This is not a "pretimeout". Please seedrivers/watchdog/rti_wdt.cfor an example on how to handle this; essentially you have to setmin_hw_heartbeat_msto the value of the closed window timeout. The watchdog core then handles the mechanics.You can not use "pretimeout" to set the "closed" window size; this is an ABI abuse. There is no standard ABI for this, so if you want to have it configurable it would have to be a module parameter.
Guenter
Quoted 17 lines
Thanks
Srinivas Neeli.*From:* Srinivas Neeli <[email protected]>
*Sent:* Wednesday, June 9, 2021 12:57 PM
*To:* Guenter Roeck <[email protected]>; Shubhrajyoti Datta <[email protected]>; Srinivas Goud <[email protected]>; Michal Simek <[email protected]>
*Cc:* [email protected]; [email protected]; [email protected]; git <[email protected]> *Subject:* RE: [PATCH 2/3] watchdog:xilinx_wwdt: Add Versal Window watchdog modeHi Guenter Roeck,
Thanks for review.
Quoted 8 lines
Versal platform contain System watchdog Timer. It supports two functions, Those are
1) Generic watchdog mode
2) Window watchdog mode
Right now we are implementing window watchdog timer functionality in
driver.
Quoted 9 lines
Features of Window watchdog mode:
- The timer contains two configurable windows( closed and open).
- The timer has to restart only in open window.
- If software tries to restart out side of open window it will generate a
reset.
Quoted 2 lines
We have a requirement for window watchdog driver, So I implemented
window watchdog in two scenarios.
Quoted 21 lines
1) With Pre-timeout
2) With without Pre-timeout
*Scenario 1:*
With pre-timeout:
Here we will get two window concept.
1) closed window
2) Open window
start to pre-timeout, we are calling "*closed*" window.
From pre-timeout to timeout we are calling “*Open*” window.
*Operations:*
Quoted 8 lines
start
keep
alive(only in open window, closed window we are ignoring)stop
we don't have permission to refresh/restart our timer in closed window, So
ignoring the keepalive.
Quoted 2 lines
Adjusted code to generate interrupt after completion of closed window.
once we cross the closed window we can restart our time anytime.
Quoted 1 line
Quoted 9 lines
Quoted 6 lines
Once we reaches to timeout , will get reset signal.
*Advantage:*
After getting pre-timeout notification we can reset our timer or can collect
our log.
Quoted 2 lines
once we get interrupt we can conclude our task is not working as
expected.
Quoted 71 lines
Quoted 10 lines
So we can takecare of our tasks.
*Scenario 2:*
with out pre-timeout:
It will work like general watchdog timer.
we can run keepalive anytime(as there is no closed window, only open
window present).
Quoted 7 lines
Once we reaches to time out, will get reset.
*Operations:*
start
Quoted 7 lines
keep alive
stop
For more details:
manuals/am01
Quoted 2 lines
1-versal-acap-trm.pdf
<https://www.xilinx.com/support/documentation/architecture-manuals/am0
Quoted 7 lines
11-versal-acap-trm.pdf>
major comments will update in V2.
Quoted 3 lines
-----Original Message-----
From: Guenter Roeck <[email protected]
<mailto:[email protected]>>
Quoted 34 lines
On Behalf Of Guenter Roeck
Quoted 3 lines
Sent: Thursday, May 27, 2021 8:09 PM
To: Srinivas Neeli <[email protected]
<mailto:[email protected]>>; Shubhrajyoti Datta
Quoted 1 line
<[email protected] <mailto:[email protected]>>; Srinivas Goud
<[email protected] <mailto:[email protected]>>; Michal Simek
Quoted 3 lines
<[email protected] <mailto:[email protected]>>
Cc [email protected] <mailto:[email protected]>;[email protected]
<mailto:[email protected]>; linux-Quoted 1 line
[email protected] <mailto:[email protected]>; git
<[email protected] <mailto:[email protected]>>
Quoted 7 lines
Subject: Re: [PATCH 2/3] watchdog:
xilinx_wwdt: Add Versal Windowwatchdog mode
The subject is confusing. This patch does not add "Versal Window
watchdog
Quoted 1 line
mode", it adds a driver which supports the Versal Window watchdog.
The
Quoted 1 line
subject should be something like "watchdog: Add Versal Window
watchdog
Quoted 380 lines
Quoted 7 lines
Quoted 7 lines
driver".
Quoted 1 line · Srinivas Neeli
Versal watchdog driver uses Window watchdog mode. Window
watchdog
Quoted 372 lines
Quoted 4 lines
Quoted 4 lines
timer(WWDT) contains closed(first) and open(second) window with
32 bit width. WWDT will generate an interrupt after the first
window
Quoted 1 line
Quoted 1 line
timeout and reset signal after the second window timeout.
Timeout and
Quoted 1 line
Quoted 1 line
Pre-timeout configuration, Stop and Refresh trigger only in
open
Quoted 7 lines
Quoted 1 line
window.
Does that mean that userspace can not send a keepalive before the
pretimeout expires ? That is not how this is supposed to work. If
that is the
Quoted 1 line
case, this is not a pretimeout. Pretimeout is supposed to be used
for
Quoted 1 line
emergency handling, such as triggering a crash dump. The above
description
Quoted 5 lines
as well as the code suggests that an interrupt is all but mandatory.
Assuming that is all the case, ie that keepalive is only possible
after the
Quoted 1 line
interrupt was received, and that timeout updates are also only
possible after
Quoted 1 line
an interrupt was received, one possible handling would to record
that a
Quoted 1 line
keepalive was received, and to record that a request to update
the timeout
Quoted 1 line
was received if that happens while the window is closed. Then,
when the
Quoted 1 line
interrupt is received, those actions can be applied. Otherwise,
if there was
Quoted 1 line
no keepalive request prior to the interrupt, the interrupt
handler would call
Quoted 8 lines
watchdog_notify_pretimeout().Of course, this is all just guesswork.
Quoted 11 lines
More comments below.
Guenter
Quoted 3 lines
Signed-off-by Srinivas Neeli <[email protected]<mailto:[email protected]>>
Quoted 10 lines
Quoted 7 lines
---
drivers/watchdog/Kconfig | 16 ++
drivers/watchdog/Makefile | 1 +
drivers/watchdog/xilinx_wwdt.c| 382+++++++++++++++++++++++++++++++++
Quoted 7 lines
Review
Quoted 7 lines
3 files changed, 399 insertions(+)create mode 100644
drivers/watchdog/xilinx_wwdt.c(quoted diff) +0
-0b/drivers/watchdog/Kconfig index
Quoted 9 lines
Quoted 9 lines
355100dad60a..2ed17f278783100644--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
(quoted diff) +0
-0@@ -307,6 +307,22 @@ config XILINX_WATCHDOGTo compile this driver as a module, choose M here:
the
Quoted 12 lines
Quoted 11 lines
module will be called
of_xilinx_wdt.+config
XILINX_WINDOW_WATCHDOG+ tristate "Xilinx Window Watchdog timer"
+ depends on
HAS_IOMEM+ select
WATCHDOG_COREQuoted 7 lines
Quoted 7 lines
+ help
+ Window Watchdog driver for the
versal_wwdtip core.+ Window watchdog timer(WWDT) contains closed(first) and
+ open(second) window with 32 bit width. WWDT will
generate
Quoted 16 lines
Quoted 15 lines
+ an interrupt after the first window timeout and reset
+ signal after the second window timeout. Timeout and
+ Pre-timeout configuration, Stop and Refresh trigger
+ only in open window.
drivers/watchdog/Kconfig +4
-0+ + To compile this driver as a module, choose M here: the + module will be called xilinx_wwdt. +Quoted 7 lines
Review
Quoted 7 lines
config
ZIIRAVE_WATCHDOGtristate "Zodiac RAVE Watchdog Timer"
depends on I2C
(quoted diff) +0
-0b/drivers/watchdog/Makefile
Quoted 25 lines
Review obj-$(CONFIG_M54xx_WATCHDOG) +=
Quoted 7 lines
index
a7eade8b4d45..97d10c3d39c7100644--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
(quoted diff) +0
-0@@ -148,6 +148,7 @@ obj-$(CONFIG_M54xx_WATCHDOG) +=m54xx_wdt.o
Quoted 15 lines
drivers/watchdog/Makefile +0
-0# MicroBlaze Architectureobj-$(CONFIG_XILINX_WATCHDOG) += of_xilinx_wdt.o
+obj-$(CONFIG_XILINX_WINDOW_WATCHDOG) += xilinx_wwdt.o
# MIPS Architecture
obj-$(CONFIG_ATH79_WDT) += ath79_wdt.o diff --git
a/drivers/watchdog/xilinx_wwdt.c
b/drivers/watchdog/xilinx_wwdt.cnewQuoted 88 lines
Quoted 87 lines
file mode 100644 index 000000000000..8fa2cb2225e8
---
/dev/null+++
b/drivers/watchdog/xilinx_wwdt.cdrivers/watchdog/xilinx_wwdt.c new file +40
-0@@ -0,0 +1,382 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Window Watchdog Device Driver for Xilinx Versal WWDT +* +* (C) Copyright 2021 Xilinx, Inc. +*/ + +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/ioport.h> +#include <linux/of_device.h> +#include <linux/of_address.h> +#include <linux/module.h> +#include <linux/watchdog.h> + +#define XWWDT_DEFAULT_TIMEOUT 40 +#define XWWDT_MIN_TIMEOUT 1 +#define XWWDT_MAX_TIMEOUT 42 + +/* Register offsets for the WWdt device */ +#define XWWDT_MWR_OFFSET 0x00 +#define XWWDT_ESR_OFFSET 0x04 +#define XWWDT_FCR_OFFSET 0x08 +#define XWWDT_FWR_OFFSET 0x0c +#define XWWDT_SWR_OFFSET 0x10 + +/* Master Write Control Register Masks */ +#define XWWDT_MWR_MASK BIT(0) + +/* Enable and Status Register Masks */ +#define XWWDT_ESR_WINT_MASK BIT(16) +#define XWWDT_ESR_WSW_MASK BIT(8) +#define XWWDT_ESR_WEN_MASK BIT(0) + +/* Function control Register Masks */ +#define XWWDT_SBC_MASK 0xFF00 +#define XWWDT_SBC_SHIFT 16 +#define XWWDT_BSS_MASK 0xC0 +Quoted 11 lines
drivers/watchdog/xilinx_wwdt.c line 43
Quoted 5 lines
drivers/watchdog/xilinx_wwdt.c new file +3
-0+static int wwdt_timeout; + +module_param (wwdt_timeout, int,0644 );MODULE_PARM_DESC(wwdt_timeout,
Quoted 3 lines
+ "Watchdog time in seconds. (default="
+
__MODULE_STRING(XWWDT_DEFAULT_TIMEOUT)")");
Quoted 7 lines
Review
Quoted 7 lines
(quoted diff) +4
-0+ +struct xwwdt_device { + void __iomem *base; + spinlock_t spinlock; /* spinlock for register handling*/
Quoted 11 lines
Review
Quoted 11 lines
+ struct
watchdog_devicexilinx_wwdt_wdd;+ struct clk *clk;
+ int irq;
(quoted diff) +3
-0+}; + +static int is_wwdt_in_closed_window(struct watchdog_device*wdd)
Quoted 3 lines
should return bool
Will update in V2.
Quoted 6 lines
Quoted 5 lines
+{
+ u32
control_status_reg;Quoted 7 lines
Quoted 7 lines
+ struct
xwwdt_device*xdev =watchdog_get_drvdata(wdd);+
+
spin_lock(&xdev->spinlock);+
control_status_reg= ioread32(xdev->base +
XWWDT_ESR_OFFSET);Quoted 5 lines
Quoted 5 lines
+
spin_unlock(&xdev->spinlock);+ if (
control_status_reg&XWWDT_ESR_WEN_MASK)+ if (!(control_status_reg &
XWWDT_ESR_WSW_MASK))Quoted 9 lines
Quoted 5 lines
+ return 0;
+
+ return 1;
Can be written as expresion without if statement
Will update in V2
Quoted 33 lines
Quoted 20 lines
(quoted diff) +5
-0+} + +static int xilinx_wwdt_start(struct watchdog_device *wdd) { + struct xwwdt_device *xdev = watchdog_get_drvdata(wdd); + struct watchdog_device *xilinx_wwdt_wdd = &xdev-
xilinx_wwdt_wdd;+ u64
time_out,pre_timeout, count;+ u32
control_status_reg, fcr;+ int ret;
drivers/watchdog/xilinx_wwdt.c line 82
Quoted 9 lines
drivers/watchdog/xilinx_wwdt.c new file +5
-0+ + count = clk_get_rate(xdev->clk); + if (!count) + return -EINVAL; +Is there a reason to believe that the clock rate can change ?
If not I would suggest to read it once and store it in struct
xwwdt_device.Quoted 296 lines
Quoted 296 lines
Will update in V2.
Quoted 10 lines
Quoted 9 lines
+ /* Calculate timeout count */
+
pre_timeout= count *wdd->pretimeout;+
time_out= count *wdd->timeout;+ if (!watchdog_active(xilinx_wwdt_wdd)) {
Quoted 7 lines
Quoted 1 line
+ ret =
clk_enable(xdev->clk);This is at the very least confusing.
The last action in the probe function is to call
clk_disable_unprepare(),Quoted 1 line
meaning the clock should not be prepared here. How can it be
enabled
Quoted 1 line
without being prepared ?
Will update in V2
Quoted 5 lines
Quoted 5 lines
+ if (ret) {
+ dev_err(wdd->parent,
"Failed to enable clock\n");
Quoted 9 lines
Quoted 7 lines
+ return ret;
+ }
+ }
+
I think it would be better to separate the functions to
start/stop the clock
Quoted 10 lines
from the function to update/enable the watchdog. The use of
watchdog_active()combined withclk_enable/clk_disable/clk_prepare_enable/clk_disable_unprepare
is confusing and makes it all but impossible to review the driver.
Quoted 17 lines
Quoted 3 lines
+
spin_lock(&xdev->spinlock);+ iowrite32(XWWDT_MWR_MASK,
xdev->base+
XWWDT_MWR_OFFSET);Quoted 11 lines
+ iowrite32(~(u32)XWWDT_ESR_WEN_MASK,
+
xdev->base+XWWDT_ESR_OFFSET);+
+ if (
pre_timeout) {+ iowrite32((u32)(time_out -
pre_timeout),+
xdev->base+
XWWDT_FWR_OFFSET);Quoted 5 lines
Quoted 1 line
+ iowrite32((u32)pre_timeout,
xdev->base+
XWWDT_SWR_OFFSET);Quoted 1 line
+ fcr = ioread32(xdev->base +
XWWDT_SWR_OFFSET);Quoted 1 line
Quoted 1 line
+ fcr = (fcr >>
XWWDT_SBC_SHIFT) &
XWWDT_SBC_MASK;Quoted 3 lines
Quoted 3 lines
+ fcr = fcr |
XWWDT_BSS_MASK;+ iowrite32(fcr,
xdev->base+
XWWDT_FCR_OFFSET);Quoted 5 lines
Quoted 5 lines
+ } else {
+ iowrite32((u32)pre_timeout,
+
xdev->base+
XWWDT_FWR_OFFSET);Quoted 5 lines
Quoted 1 line
+ iowrite32((u32)time_out,
xdev->base+
XWWDT_SWR_OFFSET);Quoted 1 line
+ iowrite32(0x0,
xdev->base+
XWWDT_FCR_OFFSET);Quoted 7 lines
Quoted 7 lines
+ }
+
+ /* Enable the window watchdog timer */
+
control_status_reg= ioread32(xdev->base +
XWWDT_ESR_OFFSET);Quoted 3 lines
Quoted 3 lines
+
control_status_reg|=XWWDT_ESR_WEN_MASK;+ iowrite32(control_status_reg,
xdev->base+
XWWDT_ESR_OFFSET);Quoted 22 lines
Quoted 21 lines
(quoted diff) +11
-0+ + spin_unlock(&xdev->spinlock); + + dev_dbg(xilinx_wwdt_wdd->parent, "Watchdog Started!\n"); + + return 0; +} + +static int xilinx_wwdt_stop(struct watchdog_device *wdd) { + struct xwwdt_device *xdev = watchdog_get_drvdata(wdd); + struct watchdog_device *xilinx_wwdt_wdd = &xdev-Quoted 7 lines
Quoted 7 lines
xilinx_wwdt_wdd;+
+ if (!is_wwdt_in_closed_window(wdd)) {
+ dev_warn(xilinx_wwdt_wdd->parent, "timer
in closed
Quoted 30 lines
window");
Review
Quoted 11 lines
+ return
-EINVAL;+ }
(quoted diff) +4
-0+ + spin_lock(&xdev->spinlock); + + iowrite32(XWWDT_MWR_MASK, xdev->base +
XWWDT_MWR_OFFSET);Quoted 13 lines
+ /* Disable the Window watchdog timer */
+ iowrite32(~(u32)XWWDT_ESR_WEN_MASK,
+
xdev->base+XWWDT_ESR_OFFSET);drivers/watchdog/xilinx_wwdt.c new file +4
-0+ + spin_unlock(&xdev->spinlock); + + if (watchdog_active(xilinx_wwdt_wdd))Quoted 7 lines
Quoted 3 lines
+
clk_disable(xdev->clk);+
The stop function won't be called if the watchdog is not running,
ie if
Quoted 19 lines
watchdog_active()returns false.I don't undeerstand the logic of clock handling in this driver.
More on that below.
Quoted 11 lines
+
dev_dbg(xilinx_wwdt_wdd->parent, "Watchdog Stopped!\n");drivers/watchdog/xilinx_wwdt.c new file +5
-0+ + return 0; +} + +static int xilinx_wwdt_keepalive (struct watchdog_device *wdd){
Quoted 8 lines
Quoted 7 lines
+ u32
control_status_reg;+ struct
xwwdt_device*xdev =watchdog_get_drvdata(wdd);+
+ /* Refresh in open window is ignored */
Quoted 7 lines
Quoted 5 lines
+ if (!is_wwdt_in_closed_window(wdd))
+ return 0;
+
This is dangerous. There is no reason for userspace to adhere to
these
Quoted 4 lines
restrictions.
Quoted 9 lines
Quoted 5 lines
+
spin_lock(&xdev->spinlock);+
+ iowrite32(XWWDT_MWR_MASK,
xdev->base+
XWWDT_MWR_OFFSET);Quoted 1 line
+
control_status_reg= ioread32(xdev->base +
XWWDT_ESR_OFFSET);Quoted 5 lines
Quoted 5 lines
+
control_status_reg|=XWWDT_ESR_WINT_MASK;+
control_status_reg&= ~XWWDT_ESR_WSW_MASK;+ iowrite32(control_status_reg,
xdev->base+
XWWDT_ESR_OFFSET);Quoted 1 line
Quoted 1 line
+
control_status_reg= ioread32(xdev->base +
XWWDT_ESR_OFFSET);Quoted 3 lines
Quoted 3 lines
+
control_status_reg|=XWWDT_ESR_WSW_MASK;+ iowrite32(control_status_reg,
xdev->base+
XWWDT_ESR_OFFSET);Quoted 6 lines
Quoted 5 lines
drivers/watchdog/xilinx_wwdt.c new file +3
-0+ + spin_unlock(&xdev->spinlock); +Quoted 7 lines
Review
Quoted 7 lines
+ return 0;
(quoted diff) +3
-0+} + +static int xilinx_wwdt_set_timeout(struct watchdog_device*wdd,
Quoted 1 line
Quoted 1 line
+
unsigned int
new_time)Quoted 8 lines
Quoted 7 lines
+{
+ u32 ret = 0;
+ struct
xwwdt_device*xdev =watchdog_get_drvdata(wdd);+ struct
watchdog_device*xilinx_wwdt_wdd= &xdev-Quoted 7 lines
Quoted 7 lines
xilinx_wwdt_wdd;+
+ if (!is_wwdt_in_closed_window(wdd)) {
+ dev_warn(xilinx_wwdt_wdd->parent, "timer
in closed
Quoted 3 lines
window");
Quoted 1 line
+ return
-EINVAL;Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
+ }
+
So userspace can clog the log by continuously trying to set the timeout
?
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Also, again, this is dangerous. Userspace does not know the window
size.
Quoted 470 lines
Quoted 75 lines
user can configure window size.
Quoted 11 lines
Quoted 11 lines
+ if (
new_time<XWWDT_MIN_TIMEOUT||+
new_time>XWWDT_MAX_TIMEOUT) {+ dev_warn(xilinx_wwdt_wdd->parent,
+ "timeout value must be
%d<=x<=%d, using %d\n",
Quoted 3 lines
Quoted 3 lines
+
XWWDT_MIN_TIMEOUT,+
XWWDT_MAX_TIMEOUT,
new_time);Quoted 25 lines
Quoted 3 lines
+ return
-EINVAL;+ }
This is handled by the watchdog core.
Quoted 15 lines
drivers/watchdog/xilinx_wwdt.c new file +8
-0+ + wdd->timeout = new_time; + wdd->pretimeout = 0; + + if (watchdog_active(xilinx_wwdt_wdd)) { + ret = xilinx_wwdt_start(wdd); + if (ret) +dev_dbg(xilinx_wwdt_wdd->parent, "timer start
Quoted 13 lines
failed");
Quoted 11 lines
+ }
(quoted diff) +5
-0+ + return ret; +} + +static int xilinx_wwdt_set_pretimeout(struct watchdog_device*wdd,
Quoted 1 line
Quoted 1 line
+
u32
new_pretimeout)Quoted 7 lines
Quoted 7 lines
+{
+ u32 ret = 0;
+ struct
xwwdt_device*xdev =watchdog_get_drvdata(wdd);+ struct
watchdog_device*xilinx_wwdt_wdd= &xdev-Quoted 18 lines
Quoted 7 lines
Quoted 7 lines
xilinx_wwdt_wdd;+
+ if (!is_wwdt_in_closed_window(wdd)) {
+ dev_warn(xilinx_wwdt_wdd->parent, "timer
in closed
Quoted 9 lines
window");
Quoted 3 lines
+ return
-EINVAL;+ }
This restriction is not only dangerous but confusing, and simply
unacceptable.
Quoted 376 lines
Quoted 11 lines
Userspace will get
-EINVALwith no idea what is wrong.A watchdog daemon will bail out for no good reason.
Quoted 3 lines
+
+ if (
new_pretimeout<wdd->min_timeout||Quoted 21 lines
Quoted 5 lines
+
new_pretimeout>=wdd->timeout)+ return
-EINVAL;+
This is handled by the watchdog core.
Quoted 11 lines
+
wdd->pretimeout=new_pretimeout;drivers/watchdog/xilinx_wwdt.c new file +5
-0+ + if (watchdog_active(xilinx_wwdt_wdd)) { + ret = xilinx_wwdt_start(wdd); + if (ret) +dev_dbg(xilinx_wwdt_wdd->parent, "timer start
Quoted 53 lines
failed");
Quoted 51 lines
+ }
(quoted diff) +25
-0+ + return ret; +} + +static void xwwdt_clk_disable_unprepare(void *data) { + clk_disable_unprepare(data); +} + +static irqreturn_t xilinx_wwdt_isr(int irq, void *wdog_arg) { + struct xwwdt_device *xdev = wdog_arg; + + watchdog_notify_pretimeout(&xdev->xilinx_wwdt_wdd); + + return IRQ_HANDLED; +} + +static const struct watchdog_info xilinx_wwdt_ident = { + .options = WDIOF_MAGICCLOSE | + WDIOF_KEEPALIVEPING | + WDIOF_SETTIMEOUT, + .firmware_version = 1, + .identity = "xlnx_window watchdog", +}; + +static const struct watchdog_info xilinx_wwdt_pretimeout_ident= {
Quoted 66 lines
Quoted 65 lines
+ .options =
WDIOF_MAGICCLOSE|+
WDIOF_KEEPALIVEPING|+
WDIOF_PRETIMEOUT|+
WDIOF_SETTIMEOUT,+ .firmware_version = 1,
+ .identity = "
xlnx_windowwatchdog",(quoted diff) +27
-0+}; + +static const struct watchdog_ops xilinx_wwdt_ops = { + .owner = THIS_MODULE, + .start = xilinx_wwdt_start, + .stop = xilinx_wwdt_stop, + .ping = xilinx_wwdt_keepalive, + .set_timeout = xilinx_wwdt_set_timeout, + .set_pretimeout = xilinx_wwdt_set_pretimeout, }; + +static int xwwdt_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; + struct watchdog_device *xilinx_wwdt_wdd; + struct xwwdt_device *xdev; + u32 pre_timeout = 0; + int ret; + + xdev = devm_kzalloc(dev, sizeof(*xdev), GFP_KERNEL); + if (!xdev) + return -ENOMEM; + + xilinx_wwdt_wdd = &xdev->xilinx_wwdt_wdd; + xilinx_wwdt_wdd->info = &xilinx_wwdt_ident; + xilinx_wwdt_wdd->ops = &xilinx_wwdt_ops; + xilinx_wwdt_wdd->parent = dev; + + xdev->base = devm_platform_ioremap_resource(pdev, 0);Quoted 7 lines
Quoted 7 lines
+ if (
IS_ERR(xdev->base))+ return
PTR_ERR(xdev->base);+
+ ret = of_property_read_u32(dev->of_node,
"pretimeout-sec",
Quoted 1 line
Quoted 1 line
+
&pre_timeout);Quoted 5 lines
Quoted 5 lines
+ if (ret)
+ dev_dbg(dev,
+ "Parameter
\"pretimeout-sec\" not found\n");
Quoted 16 lines
Quoted 15 lines
drivers/watchdog/xilinx_wwdt.c new file +8
-0+ + xdev->clk = devm_clk_get(dev, NULL); + if (IS_ERR(xdev->clk)) + return PTR_ERR(xdev->clk); + + ret = clk_get_rate(xdev->clk); + if (!ret) + return -EINVAL;Quoted 7 lines
Quoted 7 lines
+
+ ret =
clk_prepare_enable(xdev->clk);+ if (ret) {
+ dev_err(dev, "unable to enable
clock\n");
Quoted 9 lines
Quoted 5 lines
+ return ret;
+ }
+ ret = devm_add_action_or_reset(dev,
xwwdt_clk_disable_unprepare,Quoted 1 line
+
xdev->clk);Quoted 37 lines
Quoted 5 lines
+ if (ret)
+ goto
err_clk_disable;+
Seems pointless. What happens when you unload the driver ?
Quoted 25 lines
+
xilinx_wwdt_wdd->pretimeout=pre_timeout;+
xilinx_wwdt_wdd->timeout=XWWDT_DEFAULT_TIMEOUT;+
xilinx_wwdt_wdd->min_timeout=XWWDT_MIN_TIMEOUT;+
xilinx_wwdt_wdd->max_timeout=XWWDT_MAX_TIMEOUT;(quoted diff) +9
-0+ + xdev->irq = platform_get_irq_byname(pdev, "wdt"); + if (xdev->irq < 0) { + ret = xdev->irq; + goto err_clk_disable; + } + + if (!devm_request_irq(dev, xdev->irq, xilinx_wwdt_isr, + 0, dev_name(dev),xdev)) {
Quoted 1 line
Quoted 1 line
+
xilinx_wwdt_wdd->info=
&xilinx_wwdt_pretimeout_ident;Quoted 7 lines
drivers/watchdog/xilinx_wwdt.c line 343
Quoted 7 lines
+ }
drivers/watchdog/xilinx_wwdt.c new file +3
-0+ + ret = watchdog_init_timeout(xilinx_wwdt_wdd, +
wwdt_timeout,&pdev->dev);Quoted 3 lines
Quoted 3 lines
+ if (ret)
+ dev_info(&pdev->dev, "Configured default
timeout
Quoted 11 lines
value\n");
Quoted 9 lines
(quoted diff) +5
-0+ + spin_lock_init(&xdev->spinlock); + watchdog_set_drvdata(xilinx_wwdt_wdd, xdev); + + ret = devm_watchdog_register_device(dev,
xilinx_wwdt_wdd);Quoted 7 lines
Quoted 5 lines
+ if (ret)
+ goto
err_clk_disable;+
At this point the watchdog is fully instantiated, and userspace
may have
Quoted 4 lines
enabled it.
Quoted 11 lines
Quoted 3 lines
+
clk_disable_unprepare(xdev->clk);+
And now its clock is getting stopped. Actually, it is getting unprepared.
Does this even work ?
Quoted 1 line
+ dev_info(dev, "Xilinx Window Watchdog Timer with timeout
%ds\n",
Quoted 8 lines
Quoted 7 lines
+
xilinx_wwdt_wdd->timeout);drivers/watchdog/xilinx_wwdt.c new file +3
-0+ + return 0; +Quoted 51 lines
Quoted 3 lines
+err_clk_disable:
+
clk_disable_unprepare(xdev->clk);
devm_add_action_or_reset()already handles this.Quoted 41 lines
+ return ret;
(quoted diff) +20
-0+} + +/* Mat for of_platform binding */ +static const struct of_device_id xwwdt_of_match[] = { + { .compatible = "xlnx,versal-wwdt-1.0", }, + {}, +}; +MODULE_DEVICE_TABLE(of, xwwdt_of_match); + +static struct platform_driver xwwdt_driver = { + .probe = xwwdt_probe, + .driver = { + .name = "Xilinx Window Watchdog", + .of_match_table = xwwdt_of_match, + }, +}; + +module_platform_driver(xwwdt_driver); + +MODULE_AUTHOR("Neeli Srinivas <[email protected]<mailto:[email protected]>>");
Quoted 5 lines
drivers/watchdog/xilinx_wwdt.c line 382
Quoted 5 lines
drivers/watchdog/xilinx_wwdt.c new file +2
-0+MODULE_DESCRIPTION ("Xilinx Window Watchdog driver" ); +MODULE_LICENSE ("GPL" );Thanks
Srinivas Neeli.
Guenter Roeck
maintainerRe: [PATCH 2/3] watchdog: xilinx_wwdt: Add Versal Window watchdog mode
Quoted 38 lines · Srinivas Neeli
Hi Guenter,
Could you please share your comments on below limitations.
Thanks
Srinivas NeeliQuoted 30 lines
-----Original Message-----
From: Srinivas Neeli <[email protected]>
Sent: Wednesday, September 29, 2021 12:32 PM
To: Guenter Roeck <[email protected]>; Shubhrajyoti Datta <[email protected]>; Srinivas Goud <[email protected]>; Michal Simek <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; git <[email protected]>
Subject: RE: [PATCH 2/3] watchdog:xilinx_wwdt: Add Versal Window watchdog modeHi Guenter,
I went through reference "
rti_wdt.c" driver. It implemented Window watchdog with few limitations.
Limitations:
---------------
1) Not able to configure Closed window and Open window separately. Because of xilinx window watchdog supports separate configurable
closed and open windows.
2) In case of rti driver, if any bad event(error event) occur due to any user space event like ping then
the watchdog core bypassing the ping call.
But in case of xilinx watchdog there are separate register bits for counting
error events.
So if I implement driver in similar torti-wdt.cdriver, then we can not
be able read the error events from
the registers.
So is this ok because we are not notifying the errors to user.
I can only repeat: You can not misuse pretimeout to configure the minimum window size. If you want that configurable, maybe you can use a module parameter. Not sure I understand the comment about error events. If an error event is userspace pinging the watchdog within the closed window, sure, then you can not use min_hw_heartbeat_ms to indicate the minimum window size. I don't really understand the point of this (or why anyone would want such a "window" watchdog in the first place), but then I don't have to understand it. Just remember to explain to your customers and document in the driver what happens if userspace pings the watchdog too early (eg that the ping will be ignored and that the watchdog will reboot the system unless another ping happens within the configured window). Either case, again, you can not (mis-)use pretimeout for anything but for configuring a pretimeout.
Guenter
Quoted 1,348 lines
Quoted 1,347 lines
Thanks
Srinivas NeeliQuoted 103 lines
-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Wednesday, July 14, 2021 5:01 PM
To: Srinivas Neeli <[email protected]>; Shubhrajyoti Datta <[email protected]>; Srinivas Goud <[email protected]>; Michal Simek <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; git <[email protected]>
Subject: Re: [PATCH 2/3] watchdog:xilinx_wwdt: Add Versal Window watchdog modeQuoted 4 lines · Srinivas Neeli
Hi Guenter,
If you are fine with my justification, I will send v2 with update code.
We have at least one more watchdog driver with open/closed window concepts.
This is not a "pretimeout". Please seedrivers/watchdog/rti_wdt.cfor an example on how to handle this; essentially you have to setmin_hw_heartbeat_msto the value of the closed window timeout. The watchdog core then handles the mechanics.You can not use "pretimeout" to set the "closed" window size; this is an ABI abuse. There is no standard ABI for this, so if you want to have it configurable it would have to be a module parameter.
Guenter
Quoted 17 lines
Thanks
Srinivas Neeli.*From:* Srinivas Neeli <[email protected]>
*Sent:* Wednesday, June 9, 2021 12:57 PM
*To:* Guenter Roeck <[email protected]>; Shubhrajyoti Datta <[email protected]>; Srinivas Goud <[email protected]>; Michal Simek <[email protected]>
*Cc:* [email protected]; [email protected]; [email protected]; git <[email protected]> *Subject:* RE: [PATCH 2/3] watchdog:xilinx_wwdt: Add Versal Window watchdog modeHi Guenter Roeck,
Thanks for review.
Quoted 8 lines
Versal platform contain System watchdog Timer. It supports two functions, Those are
1) Generic watchdog mode
2) Window watchdog mode
Right now we are implementing window watchdog timer functionality in
driver.
Quoted 9 lines
Features of Window watchdog mode:
- The timer contains two configurable windows( closed and open).
- The timer has to restart only in open window.
- If software tries to restart out side of open window it will generate a
reset.
Quoted 2 lines
We have a requirement for window watchdog driver, So I implemented
window watchdog in two scenarios.
Quoted 21 lines
1) With Pre-timeout
2) With without Pre-timeout
*Scenario 1:*
With pre-timeout:
Here we will get two window concept.
1) closed window
2) Open window
start to pre-timeout, we are calling "*closed*" window.
From pre-timeout to timeout we are calling “*Open*” window.
*Operations:*
Quoted 8 lines
start
keep
alive(only in open window, closed window we are ignoring)stop
we don't have permission to refresh/restart our timer in closed window, So
ignoring the keepalive.
Quoted 2 lines
Adjusted code to generate interrupt after completion of closed window.
once we cross the closed window we can restart our time anytime.
Quoted 1 line
Quoted 9 lines
Quoted 6 lines
Once we reaches to timeout , will get reset signal.
*Advantage:*
After getting pre-timeout notification we can reset our timer or can collect
our log.
Quoted 2 lines
once we get interrupt we can conclude our task is not working as
expected.
Quoted 71 lines
Quoted 10 lines
So we can takecare of our tasks.
*Scenario 2:*
with out pre-timeout:
It will work like general watchdog timer.
we can run keepalive anytime(as there is no closed window, only open
window present).
Quoted 7 lines
Once we reaches to time out, will get reset.
*Operations:*
start
Quoted 7 lines
keep alive
stop
For more details:
manuals/am01
Quoted 2 lines
1-versal-acap-trm.pdf
<https://www.xilinx.com/support/documentation/architecture-manuals/am0
Quoted 7 lines
11-versal-acap-trm.pdf>
major comments will update in V2.
Quoted 3 lines
-----Original Message-----
From: Guenter Roeck <[email protected]
<mailto:[email protected]>>
Quoted 34 lines
On Behalf Of Guenter Roeck
Quoted 3 lines
Sent: Thursday, May 27, 2021 8:09 PM
To: Srinivas Neeli <[email protected]
<mailto:[email protected]>>; Shubhrajyoti Datta
Quoted 1 line
<[email protected] <mailto:[email protected]>>; Srinivas Goud
<[email protected] <mailto:[email protected]>>; Michal Simek
Quoted 3 lines
<[email protected] <mailto:[email protected]>>
Cc [email protected] <mailto:[email protected]>;[email protected]
<mailto:[email protected]>; linux-Quoted 1 line
[email protected] <mailto:[email protected]>; git
<[email protected] <mailto:[email protected]>>
Quoted 7 lines
Subject: Re: [PATCH 2/3] watchdog:
xilinx_wwdt: Add Versal Windowwatchdog mode
The subject is confusing. This patch does not add "Versal Window
watchdog
Quoted 1 line
mode", it adds a driver which supports the Versal Window watchdog.
The
Quoted 1 line
subject should be something like "watchdog: Add Versal Window
watchdog
Quoted 380 lines
Quoted 7 lines
Quoted 7 lines
driver".
Quoted 1 line · Srinivas Neeli
Versal watchdog driver uses Window watchdog mode. Window
watchdog
Quoted 372 lines
Quoted 4 lines
Quoted 4 lines
timer(WWDT) contains closed(first) and open(second) window with
32 bit width. WWDT will generate an interrupt after the first
window
Quoted 1 line
Quoted 1 line
timeout and reset signal after the second window timeout.
Timeout and
Quoted 1 line
Quoted 1 line
Pre-timeout configuration, Stop and Refresh trigger only in
open
Quoted 7 lines
Quoted 1 line
window.
Does that mean that userspace can not send a keepalive before the
pretimeout expires ? That is not how this is supposed to work. If
that is the
Quoted 1 line
case, this is not a pretimeout. Pretimeout is supposed to be used
for
Quoted 1 line
emergency handling, such as triggering a crash dump. The above
description
Quoted 5 lines
as well as the code suggests that an interrupt is all but mandatory.
Assuming that is all the case, ie that keepalive is only possible
after the
Quoted 1 line
interrupt was received, and that timeout updates are also only
possible after
Quoted 1 line
an interrupt was received, one possible handling would to record
that a
Quoted 1 line
keepalive was received, and to record that a request to update
the timeout
Quoted 1 line
was received if that happens while the window is closed. Then,
when the
Quoted 1 line
interrupt is received, those actions can be applied. Otherwise,
if there was
Quoted 1 line
no keepalive request prior to the interrupt, the interrupt
handler would call
Quoted 8 lines
watchdog_notify_pretimeout().Of course, this is all just guesswork.
Quoted 11 lines
More comments below.
Guenter
Quoted 3 lines
Signed-off-by Srinivas Neeli <[email protected]<mailto:[email protected]>>
Quoted 10 lines
Quoted 7 lines
---
drivers/watchdog/Kconfig | 16 ++
drivers/watchdog/Makefile | 1 +
drivers/watchdog/xilinx_wwdt.c| 382+++++++++++++++++++++++++++++++++
Quoted 7 lines
Review
Quoted 7 lines
3 files changed, 399 insertions(+)create mode 100644
drivers/watchdog/xilinx_wwdt.c(quoted diff) +0
-0b/drivers/watchdog/Kconfig index
Quoted 9 lines
Quoted 9 lines
355100dad60a..2ed17f278783100644--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
(quoted diff) +0
-0@@ -307,6 +307,22 @@ config XILINX_WATCHDOGTo compile this driver as a module, choose M here:
the
Quoted 12 lines
Quoted 11 lines
module will be called
of_xilinx_wdt.+config
XILINX_WINDOW_WATCHDOG+ tristate "Xilinx Window Watchdog timer"
+ depends on
HAS_IOMEM+ select
WATCHDOG_COREQuoted 7 lines
Quoted 7 lines
+ help
+ Window Watchdog driver for the
versal_wwdtip core.+ Window watchdog timer(WWDT) contains closed(first) and
+ open(second) window with 32 bit width. WWDT will
generate
Quoted 16 lines
Quoted 15 lines
+ an interrupt after the first window timeout and reset
+ signal after the second window timeout. Timeout and
+ Pre-timeout configuration, Stop and Refresh trigger
+ only in open window.
(quoted diff) +4
-0+ + To compile this driver as a module, choose M here: the + module will be called xilinx_wwdt. +Quoted 7 lines
Review
Quoted 7 lines
config
ZIIRAVE_WATCHDOGtristate "Zodiac RAVE Watchdog Timer"
depends on I2C
(quoted diff) +0
-0b/drivers/watchdog/Makefile
Quoted 25 lines
Review obj-$(CONFIG_M54xx_WATCHDOG) +=
Quoted 7 lines
index
a7eade8b4d45..97d10c3d39c7100644--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
(quoted diff) +0
-0@@ -148,6 +148,7 @@ obj-$(CONFIG_M54xx_WATCHDOG) +=m54xx_wdt.o
Quoted 15 lines
(quoted diff) +0
-0# MicroBlaze Architectureobj-$(CONFIG_XILINX_WATCHDOG) += of_xilinx_wdt.o
+obj-$(CONFIG_XILINX_WINDOW_WATCHDOG) += xilinx_wwdt.o
# MIPS Architecture
obj-$(CONFIG_ATH79_WDT) += ath79_wdt.o diff --git
a/drivers/watchdog/xilinx_wwdt.c
b/drivers/watchdog/xilinx_wwdt.cnewQuoted 88 lines
Quoted 87 lines
file mode 100644 index 000000000000..8fa2cb2225e8
---
/dev/null+++
b/drivers/watchdog/xilinx_wwdt.c(quoted diff) +40
-0@@ -0,0 +1,382 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Window Watchdog Device Driver for Xilinx Versal WWDT + * + * (C) Copyright 2021 Xilinx, Inc. + */ + +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/ioport.h> +#include <linux/of_device.h> +#include <linux/of_address.h> +#include <linux/module.h> +#include <linux/watchdog.h> + +#define XWWDT_DEFAULT_TIMEOUT 40 +#define XWWDT_MIN_TIMEOUT 1 +#define XWWDT_MAX_TIMEOUT 42 + +/* Register offsets for the WWdt device */ +#define XWWDT_MWR_OFFSET 0x00 +#define XWWDT_ESR_OFFSET 0x04 +#define XWWDT_FCR_OFFSET 0x08 +#define XWWDT_FWR_OFFSET 0x0c +#define XWWDT_SWR_OFFSET 0x10 + +/* Master Write Control Register Masks */ +#define XWWDT_MWR_MASK BIT(0) + +/* Enable and Status Register Masks */ +#define XWWDT_ESR_WINT_MASK BIT(16) +#define XWWDT_ESR_WSW_MASK BIT(8) +#define XWWDT_ESR_WEN_MASK BIT(0) + +/* Function control Register Masks */ +#define XWWDT_SBC_MASK 0xFF00 +#define XWWDT_SBC_SHIFT 16 +#define XWWDT_BSS_MASK 0xC0 +Quoted 11 lines
Review
Quoted 5 lines
(quoted diff) +3
-0+static int wwdt_timeout; + +module_param(wwdt_timeout, int, 0644);MODULE_PARM_DESC(wwdt_timeout,
Quoted 3 lines
+ "Watchdog time in seconds. (default="
+
__MODULE_STRING(XWWDT_DEFAULT_TIMEOUT)")");
Quoted 7 lines
Review
Quoted 7 lines
(quoted diff) +4
-0+ +struct xwwdt_device { + void __iomem *base; + spinlock_t spinlock; /* spinlock for register handling*/
Quoted 11 lines
Review
Quoted 11 lines
+ struct
watchdog_devicexilinx_wwdt_wdd;+ struct clk *clk;
+ int irq;
(quoted diff) +3
-0+}; + +static int is_wwdt_in_closed_window(struct watchdog_device*wdd)
Quoted 3 lines
should return bool
Will update in V2.
Quoted 6 lines
Quoted 5 lines
+{
+ u32
control_status_reg;Quoted 7 lines
Quoted 7 lines
+ struct
xwwdt_device*xdev =watchdog_get_drvdata(wdd);+
+
spin_lock(&xdev->spinlock);+
control_status_reg= ioread32(xdev->base +
XWWDT_ESR_OFFSET);Quoted 5 lines
Quoted 5 lines
+
spin_unlock(&xdev->spinlock);+ if (
control_status_reg&XWWDT_ESR_WEN_MASK)+ if (!(control_status_reg &
XWWDT_ESR_WSW_MASK))Quoted 9 lines
Quoted 5 lines
+ return 0;
+
+ return 1;
Can be written as expresion without if statement
Will update in V2
Quoted 33 lines
Quoted 20 lines
(quoted diff) +5
-0+} + +static int xilinx_wwdt_start(struct watchdog_device *wdd) { + struct xwwdt_device *xdev = watchdog_get_drvdata(wdd); + struct watchdog_device *xilinx_wwdt_wdd = &xdev-
xilinx_wwdt_wdd;+ u64
time_out,pre_timeout, count;+ u32
control_status_reg, fcr;+ int ret;
Review
Quoted 9 lines
(quoted diff) +5
-0+ + count = clk_get_rate(xdev->clk); + if (!count) + return -EINVAL; +Is there a reason to believe that the clock rate can change ?
If not I would suggest to read it once and store it in struct
xwwdt_device.Quoted 296 lines
Quoted 296 lines
Will update in V2.
Quoted 10 lines
Quoted 9 lines
+ /* Calculate timeout count */
+
pre_timeout= count *wdd->pretimeout;+
time_out= count *wdd->timeout;+ if (!watchdog_active(xilinx_wwdt_wdd)) {
Quoted 7 lines
Quoted 1 line
+ ret =
clk_enable(xdev->clk);This is at the very least confusing.
The last action in the probe function is to call
clk_disable_unprepare(),Quoted 1 line
meaning the clock should not be prepared here. How can it be
enabled
Quoted 1 line
without being prepared ?
Will update in V2
Quoted 5 lines
Quoted 5 lines
+ if (ret) {
+ dev_err(wdd->parent,
"Failed to enable clock\n");
Quoted 9 lines
Quoted 7 lines
+ return ret;
+ }
+ }
+
I think it would be better to separate the functions to
start/stop the clock
Quoted 10 lines
from the function to update/enable the watchdog. The use of
watchdog_active()combined withclk_enable/clk_disable/clk_prepare_enable/clk_disable_unprepare
is confusing and makes it all but impossible to review the driver.
Quoted 17 lines
Quoted 3 lines
+
spin_lock(&xdev->spinlock);+ iowrite32(XWWDT_MWR_MASK,
xdev->base+
XWWDT_MWR_OFFSET);Quoted 11 lines
+ iowrite32(~(u32)XWWDT_ESR_WEN_MASK,
+
xdev->base+XWWDT_ESR_OFFSET);+
+ if (
pre_timeout) {+ iowrite32((u32)(time_out -
pre_timeout),+
xdev->base+
XWWDT_FWR_OFFSET);Quoted 5 lines
Quoted 1 line
+ iowrite32((u32)pre_timeout,
xdev->base+
XWWDT_SWR_OFFSET);Quoted 1 line
+ fcr = ioread32(xdev->base +
XWWDT_SWR_OFFSET);Quoted 1 line
Quoted 1 line
+ fcr = (fcr >>
XWWDT_SBC_SHIFT) &
XWWDT_SBC_MASK;Quoted 3 lines
Quoted 3 lines
+ fcr = fcr |
XWWDT_BSS_MASK;+ iowrite32(fcr,
xdev->base+
XWWDT_FCR_OFFSET);Quoted 5 lines
Quoted 5 lines
+ } else {
+ iowrite32((u32)pre_timeout,
+
xdev->base+
XWWDT_FWR_OFFSET);Quoted 5 lines
Quoted 1 line
+ iowrite32((u32)time_out,
xdev->base+
XWWDT_SWR_OFFSET);Quoted 1 line
+ iowrite32(0x0,
xdev->base+
XWWDT_FCR_OFFSET);Quoted 7 lines
Quoted 7 lines
+ }
+
+ /* Enable the window watchdog timer */
+
control_status_reg= ioread32(xdev->base +
XWWDT_ESR_OFFSET);Quoted 3 lines
Quoted 3 lines
+
control_status_reg|=XWWDT_ESR_WEN_MASK;+ iowrite32(control_status_reg,
xdev->base+
XWWDT_ESR_OFFSET);Quoted 22 lines
Quoted 21 lines
(quoted diff) +11
-0+ + spin_unlock(&xdev->spinlock); + + dev_dbg(xilinx_wwdt_wdd->parent, "Watchdog Started!\n"); + + return 0; +} + +static int xilinx_wwdt_stop(struct watchdog_device *wdd) { + struct xwwdt_device *xdev = watchdog_get_drvdata(wdd); + struct watchdog_device *xilinx_wwdt_wdd = &xdev-Quoted 7 lines
Quoted 7 lines
xilinx_wwdt_wdd;+
+ if (!is_wwdt_in_closed_window(wdd)) {
+ dev_warn(xilinx_wwdt_wdd->parent, "timer
in closed
Quoted 30 lines
window");
Review
Quoted 11 lines
+ return
-EINVAL;+ }
(quoted diff) +4
-0+ + spin_lock(&xdev->spinlock); + + iowrite32(XWWDT_MWR_MASK, xdev->base +
XWWDT_MWR_OFFSET);Quoted 13 lines
+ /* Disable the Window watchdog timer */
+ iowrite32(~(u32)XWWDT_ESR_WEN_MASK,
+
xdev->base+XWWDT_ESR_OFFSET);(quoted diff) +4
-0+ + spin_unlock(&xdev->spinlock); + + if (watchdog_active(xilinx_wwdt_wdd))Quoted 7 lines
Quoted 3 lines
+
clk_disable(xdev->clk);+
The stop function won't be called if the watchdog is not running,
ie if
Quoted 19 lines
watchdog_active()returns false.I don't undeerstand the logic of clock handling in this driver.
More on that below.
Quoted 11 lines
+
dev_dbg(xilinx_wwdt_wdd->parent, "Watchdog Stopped!\n");(quoted diff) +5
-0+ + return 0; +} + +static int xilinx_wwdt_keepalive(struct watchdog_device *wdd){
Quoted 8 lines
Quoted 7 lines
+ u32
control_status_reg;+ struct
xwwdt_device*xdev =watchdog_get_drvdata(wdd);+
+ /* Refresh in open window is ignored */
Quoted 7 lines
Quoted 5 lines
+ if (!is_wwdt_in_closed_window(wdd))
+ return 0;
+
This is dangerous. There is no reason for userspace to adhere to
these
Quoted 4 lines
restrictions.
Quoted 9 lines
Quoted 5 lines
+
spin_lock(&xdev->spinlock);+
+ iowrite32(XWWDT_MWR_MASK,
xdev->base+
XWWDT_MWR_OFFSET);Quoted 1 line
+
control_status_reg= ioread32(xdev->base +
XWWDT_ESR_OFFSET);Quoted 5 lines
Quoted 5 lines
+
control_status_reg|=XWWDT_ESR_WINT_MASK;+
control_status_reg&= ~XWWDT_ESR_WSW_MASK;+ iowrite32(control_status_reg,
xdev->base+
XWWDT_ESR_OFFSET);Quoted 1 line
Quoted 1 line
+
control_status_reg= ioread32(xdev->base +
XWWDT_ESR_OFFSET);Quoted 3 lines
Quoted 3 lines
+
control_status_reg|=XWWDT_ESR_WSW_MASK;+ iowrite32(control_status_reg,
xdev->base+
XWWDT_ESR_OFFSET);Quoted 6 lines
Quoted 5 lines
(quoted diff) +3
-0+ + spin_unlock(&xdev->spinlock); +Quoted 7 lines
Review
Quoted 7 lines
+ return 0;
(quoted diff) +3
-0+} + +static int xilinx_wwdt_set_timeout(struct watchdog_device*wdd,
Quoted 1 line
Quoted 1 line
+
unsigned int
new_time)Quoted 8 lines
Quoted 7 lines
+{
+ u32 ret = 0;
+ struct
xwwdt_device*xdev =watchdog_get_drvdata(wdd);+ struct
watchdog_device*xilinx_wwdt_wdd= &xdev-Quoted 7 lines
Quoted 7 lines
xilinx_wwdt_wdd;+
+ if (!is_wwdt_in_closed_window(wdd)) {
+ dev_warn(xilinx_wwdt_wdd->parent, "timer
in closed
Quoted 3 lines
window");
Quoted 1 line
+ return
-EINVAL;Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
+ }
+
So userspace can clog the log by continuously trying to set the timeout
?
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Also, again, this is dangerous. Userspace does not know the window
size.
Quoted 470 lines
Quoted 75 lines
user can configure window size.
Quoted 11 lines
Quoted 11 lines
+ if (
new_time<XWWDT_MIN_TIMEOUT||+
new_time>XWWDT_MAX_TIMEOUT) {+ dev_warn(xilinx_wwdt_wdd->parent,
+ "timeout value must be
%d<=x<=%d, using %d\n",
Quoted 3 lines
Quoted 3 lines
+
XWWDT_MIN_TIMEOUT,+
XWWDT_MAX_TIMEOUT,
new_time);Quoted 25 lines
Quoted 3 lines
+ return
-EINVAL;+ }
This is handled by the watchdog core.
Quoted 15 lines
(quoted diff) +8
-0+ + wdd->timeout = new_time; + wdd->pretimeout = 0; + + if (watchdog_active(xilinx_wwdt_wdd)) { + ret = xilinx_wwdt_start(wdd); + if (ret) +dev_dbg(xilinx_wwdt_wdd->parent, "timer start
Quoted 13 lines
failed");
Quoted 11 lines
+ }
(quoted diff) +5
-0+ + return ret; +} + +static int xilinx_wwdt_set_pretimeout(struct watchdog_device*wdd,
Quoted 1 line
Quoted 1 line
+
u32
new_pretimeout)Quoted 7 lines
Quoted 7 lines
+{
+ u32 ret = 0;
+ struct
xwwdt_device*xdev =watchdog_get_drvdata(wdd);+ struct
watchdog_device*xilinx_wwdt_wdd= &xdev-Quoted 18 lines
Quoted 7 lines
Quoted 7 lines
xilinx_wwdt_wdd;+
+ if (!is_wwdt_in_closed_window(wdd)) {
+ dev_warn(xilinx_wwdt_wdd->parent, "timer
in closed
Quoted 9 lines
window");
Quoted 3 lines
+ return
-EINVAL;+ }
This restriction is not only dangerous but confusing, and simply
unacceptable.
Quoted 376 lines
Quoted 11 lines
Userspace will get
-EINVALwith no idea what is wrong.A watchdog daemon will bail out for no good reason.
Quoted 3 lines
+
+ if (
new_pretimeout<wdd->min_timeout||Quoted 21 lines
Quoted 5 lines
+
new_pretimeout>=wdd->timeout)+ return
-EINVAL;+
This is handled by the watchdog core.
Quoted 11 lines
+
wdd->pretimeout=new_pretimeout;(quoted diff) +5
-0+ + if (watchdog_active(xilinx_wwdt_wdd)) { + ret = xilinx_wwdt_start(wdd); + if (ret) +dev_dbg(xilinx_wwdt_wdd->parent, "timer start
Quoted 53 lines
failed");
Quoted 51 lines
+ }
(quoted diff) +25
-0+ + return ret; +} + +static void xwwdt_clk_disable_unprepare(void *data) { + clk_disable_unprepare(data); +} + +static irqreturn_t xilinx_wwdt_isr(int irq, void *wdog_arg) { + struct xwwdt_device *xdev = wdog_arg; + + watchdog_notify_pretimeout(&xdev->xilinx_wwdt_wdd); + + return IRQ_HANDLED; +} + +static const struct watchdog_info xilinx_wwdt_ident = { + .options = WDIOF_MAGICCLOSE | + WDIOF_KEEPALIVEPING | + WDIOF_SETTIMEOUT, + .firmware_version = 1, + .identity = "xlnx_window watchdog", +}; + +static const struct watchdog_info xilinx_wwdt_pretimeout_ident= {
Quoted 66 lines
Quoted 65 lines
+ .options =
WDIOF_MAGICCLOSE|+
WDIOF_KEEPALIVEPING|+
WDIOF_PRETIMEOUT|+
WDIOF_SETTIMEOUT,+ .firmware_version = 1,
+ .identity = "
xlnx_windowwatchdog",(quoted diff) +27
-0+}; + +static const struct watchdog_ops xilinx_wwdt_ops = { + .owner = THIS_MODULE, + .start = xilinx_wwdt_start, + .stop = xilinx_wwdt_stop, + .ping = xilinx_wwdt_keepalive, + .set_timeout = xilinx_wwdt_set_timeout, + .set_pretimeout = xilinx_wwdt_set_pretimeout, }; + +static int xwwdt_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; + struct watchdog_device *xilinx_wwdt_wdd; + struct xwwdt_device *xdev; + u32 pre_timeout = 0; + int ret; + + xdev = devm_kzalloc(dev, sizeof(*xdev), GFP_KERNEL); + if (!xdev) + return -ENOMEM; + + xilinx_wwdt_wdd = &xdev->xilinx_wwdt_wdd; + xilinx_wwdt_wdd->info = &xilinx_wwdt_ident; + xilinx_wwdt_wdd->ops = &xilinx_wwdt_ops; + xilinx_wwdt_wdd->parent = dev; + + xdev->base = devm_platform_ioremap_resource(pdev, 0);Quoted 7 lines
Quoted 7 lines
+ if (
IS_ERR(xdev->base))+ return
PTR_ERR(xdev->base);+
+ ret = of_property_read_u32(dev->of_node,
"pretimeout-sec",
Quoted 1 line
Quoted 1 line
+
&pre_timeout);Quoted 5 lines
Quoted 5 lines
+ if (ret)
+ dev_dbg(dev,
+ "Parameter
\"pretimeout-sec\" not found\n");
Quoted 16 lines
Quoted 15 lines
(quoted diff) +8
-0+ + xdev->clk = devm_clk_get(dev, NULL); + if (IS_ERR(xdev->clk)) + return PTR_ERR(xdev->clk); + + ret = clk_get_rate(xdev->clk); + if (!ret) + return -EINVAL;Quoted 7 lines
Quoted 7 lines
+
+ ret =
clk_prepare_enable(xdev->clk);+ if (ret) {
+ dev_err(dev, "unable to enable
clock\n");
Quoted 9 lines
Quoted 5 lines
+ return ret;
+ }
+ ret = devm_add_action_or_reset(dev,
xwwdt_clk_disable_unprepare,Quoted 1 line
+
xdev->clk);Quoted 37 lines
Quoted 5 lines
+ if (ret)
+ goto
err_clk_disable;+
Seems pointless. What happens when you unload the driver ?
Quoted 25 lines
+
xilinx_wwdt_wdd->pretimeout=pre_timeout;+
xilinx_wwdt_wdd->timeout=XWWDT_DEFAULT_TIMEOUT;+
xilinx_wwdt_wdd->min_timeout=XWWDT_MIN_TIMEOUT;+
xilinx_wwdt_wdd->max_timeout=XWWDT_MAX_TIMEOUT;(quoted diff) +9
-0+ + xdev->irq = platform_get_irq_byname(pdev, "wdt"); + if (xdev->irq < 0) { + ret = xdev->irq; + goto err_clk_disable; + } + + if (!devm_request_irq(dev, xdev->irq, xilinx_wwdt_isr, + 0, dev_name(dev),xdev)) {
Quoted 1 line
Quoted 1 line
+
xilinx_wwdt_wdd->info=
&xilinx_wwdt_pretimeout_ident;Quoted 7 lines
Review
Quoted 7 lines
+ }
(quoted diff) +3
-0+ + ret = watchdog_init_timeout(xilinx_wwdt_wdd, +
wwdt_timeout,&pdev->dev);Quoted 3 lines
Quoted 3 lines
+ if (ret)
+ dev_info(&pdev->dev, "Configured default
timeout
Quoted 11 lines
value\n");
Quoted 9 lines
(quoted diff) +5
-0+ + spin_lock_init(&xdev->spinlock); + watchdog_set_drvdata(xilinx_wwdt_wdd, xdev); + + ret = devm_watchdog_register_device(dev,
xilinx_wwdt_wdd);Quoted 7 lines
Quoted 5 lines
+ if (ret)
+ goto
err_clk_disable;+
At this point the watchdog is fully instantiated, and userspace
may have
Quoted 4 lines
enabled it.
Quoted 11 lines
Quoted 3 lines
+
clk_disable_unprepare(xdev->clk);+
And now its clock is getting stopped. Actually, it is getting unprepared.
Does this even work ?
Quoted 1 line
+ dev_info(dev, "Xilinx Window Watchdog Timer with timeout
%ds\n",
Quoted 8 lines
Quoted 7 lines
+
xilinx_wwdt_wdd->timeout);(quoted diff) +3
-0+ + return 0; +Quoted 51 lines
Quoted 3 lines
+err_clk_disable:
+
clk_disable_unprepare(xdev->clk);
devm_add_action_or_reset()already handles this.Quoted 41 lines
+ return ret;
(quoted diff) +20
-0+} + +/* Mat for of_platform binding */ +static const struct of_device_id xwwdt_of_match[] = { + { .compatible = "xlnx,versal-wwdt-1.0", }, + {}, +}; +MODULE_DEVICE_TABLE(of, xwwdt_of_match); + +static struct platform_driver xwwdt_driver = { + .probe = xwwdt_probe, + .driver = { + .name = "Xilinx Window Watchdog", + .of_match_table = xwwdt_of_match, + }, +}; + +module_platform_driver(xwwdt_driver); + +MODULE_AUTHOR("Neeli Srinivas <[email protected]<mailto:[email protected]>>");
Quoted 5 lines
Review
Quoted 5 lines
(quoted diff) +2
-0+MODULE_DESCRIPTION("Xilinx Window Watchdog driver"); +MODULE_LICENSE("GPL");Thanks
Srinivas Neeli.
PATCH 3/3 MAINTAINERS: Add fragment for xilinx watchdog drivers
In reply to Srinivas NeeliAdded entry for xilinx WATCHDOG drivers.
--- MAINTAINERS | 10 ++++++++++ 1 file changed, 10 insertions(+)
MAINTAINERS +10 -0
@@ -20081,6 +20081,16 @@ F: Documentation/devicetree/bindings/media/xilinx/ F: drivers/media/platform/xilinx/ F: include/uapi/linux/xilinx-v4l2-controls.h +XILINX WATCHDOG DRIVER +M: Srinivas Neeli <[email protected]> +R: Shubhrajyoti Datta <[email protected]> +R: Michal Simek <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/watchdog/of-xilinx-wdt.txt +F: Documentation/devicetree/bindings/watchdog/xlnx,versal-wwdt.yaml +F: drivers/watchdog/of_xilinx_wdt.c +F: drivers/watchdog/xilinx_wwdt.c + XILINX ZYNQMP DPDMA DRIVER M: Hyun Kwon <[email protected]> M: Laurent Pinchart <[email protected]>
Signature · 1 line
2.22.0