From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E7EAC2D0EC for ; Fri, 10 Apr 2020 19:12:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DFAEB2083E for ; Fri, 10 Apr 2020 19:12:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726703AbgDJTMG (ORCPT ); Fri, 10 Apr 2020 15:12:06 -0400 Received: from mail.baikalelectronics.com ([87.245.175.226]:41564 "EHLO mail.baikalelectronics.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726142AbgDJTMF (ORCPT ); Fri, 10 Apr 2020 15:12:05 -0400 Received: from localhost (unknown [127.0.0.1]) by mail.baikalelectronics.ru (Postfix) with ESMTP id 659858030791; Fri, 10 Apr 2020 19:12:02 +0000 (UTC) X-Virus-Scanned: amavisd-new at baikalelectronics.ru Received: from mail.baikalelectronics.ru ([127.0.0.1]) by localhost (mail.baikalelectronics.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jMQJVX8R95mn; Fri, 10 Apr 2020 22:12:01 +0300 (MSK) Date: Fri, 10 Apr 2020 22:12:37 +0300 From: Sergey Semin To: Guenter Roeck CC: Wim Van Sebroeck , Alexey Malahov , Thomas Bogendoerfer , Paul Burton , Ralf Baechle , , Subject: Re: [PATCH 7/7] watchdog: dw_wdt: Add DebugFS files Message-ID: <20200410191236.ifi6kus23r5xeyb6@ubsrv2.baikal.int> References: <20200306132747.14701-1-Sergey.Semin@baikalelectronics.ru> <20200306132836.763718030786@mail.baikalelectronics.ru> <20200306151248.DE1EC80307C4@mail.baikalelectronics.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20200306151248.DE1EC80307C4@mail.baikalelectronics.ru> X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org On Fri, Mar 06, 2020 at 07:12:32AM -0800, Guenter Roeck wrote: > On 3/6/20 5:27 AM, Sergey.Semin@baikalelectronics.ru wrote: > > From: Serge Semin > > > > For the sake of the easier device-driver debug procedure, we added a > > few DebugFS files with the next content: watchdog timeout, watchdog > > pre-timeout, watchdog ping/kick operation, watchdog start/stop, device > > registers dump. They are available only if kernel is configured with > > DebugFS support. > > > > Signed-off-by: Serge Semin > > Signed-off-by: Alexey Malahov > > Cc: Thomas Bogendoerfer > > Cc: Paul Burton > > Cc: Ralf Baechle > > --- > > drivers/watchdog/dw_wdt.c | 150 ++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 150 insertions(+) > > > > diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c > > index 3000120f7e39..9353d83f3e45 100644 > > --- a/drivers/watchdog/dw_wdt.c > > +++ b/drivers/watchdog/dw_wdt.c > > @@ -27,6 +27,7 @@ > > #include > > #include > > #include > > +#include > > > > #define WDOG_CONTROL_REG_OFFSET 0x00 > > #define WDOG_CONTROL_REG_WDT_EN_MASK 0x01 > > @@ -38,8 +39,14 @@ > > #define WDOG_COUNTER_RESTART_KICK_VALUE 0x76 > > #define WDOG_INTERRUPT_STATUS_REG_OFFSET 0x10 > > #define WDOG_INTERRUPT_CLEAR_REG_OFFSET 0x14 > > +#define WDOG_COMP_PARAMS_5_REG_OFFSET 0xe4 > > +#define WDOG_COMP_PARAMS_4_REG_OFFSET 0xe8 > > +#define WDOG_COMP_PARAMS_3_REG_OFFSET 0xec > > +#define WDOG_COMP_PARAMS_2_REG_OFFSET 0xf0 > > #define WDOG_COMP_PARAMS_1_REG_OFFSET 0xf4 > > #define WDOG_COMP_PARAMS_1_USE_FIX_TOP BIT(6) > > +#define WDOG_COMP_VERSION_REG_OFFSET 0xf8 > > +#define WDOG_COMP_TYPE_REG_OFFSET 0xfc > > > > /* There are sixteen TOPs (timeout periods) that can be set in the watchdog. */ > > #define DW_WDT_NUM_TOPS 16 > > @@ -79,6 +86,10 @@ struct dw_wdt { > > /* Save/restore */ > > u32 control; > > u32 timeout; > > + > > +#ifdef CONFIG_DEBUG_FS > > + struct dentry *dbgfs_dir; > > +#endif > > }; > > > > #define to_dw_wdt(wdd) container_of(wdd, struct dw_wdt, wdd) > > @@ -430,6 +441,141 @@ static void dw_wdt_init_timeouts(struct dw_wdt *dw_wdt, struct device *dev) > > mult_frac(tops[idx], MSEC_PER_SEC, dw_wdt->rate); > > } > > > > +#ifdef CONFIG_DEBUG_FS > > + > > +static int dw_wdt_dbgfs_timeout_get(void *priv, u64 *val) > > +{ > > + struct dw_wdt *dw_wdt = priv; > > + > > + *val = dw_wdt_get_timeout(dw_wdt) / MSEC_PER_SEC; > > + > > + return 0; > > +} > > + > > +static int dw_wdt_dbgfs_timeout_set(void *priv, u64 val) > > +{ > > + struct dw_wdt *dw_wdt = priv; > > + > > + return dw_wdt_set_timeout(&dw_wdt->wdd, val); > > +} > > +DEFINE_DEBUGFS_ATTRIBUTE(dw_wdt_dbgfs_timeout_fops, > > + dw_wdt_dbgfs_timeout_get, dw_wdt_dbgfs_timeout_set, "%llu\n"); > > + > > +static int dw_wdt_dbgfs_pretimeout_get(void *priv, u64 *val) > > +{ > > + struct dw_wdt *dw_wdt = priv; > > + > > + *val = dw_wdt->wdd.pretimeout; > > + > > + return 0; > > +} > > + > > +static int dw_wdt_dbgfs_pretimeout_set(void *priv, u64 val) > > +{ > > + struct dw_wdt *dw_wdt = priv; > > + > > + return dw_wdt_set_pretimeout(&dw_wdt->wdd, val); > > +} > > +DEFINE_DEBUGFS_ATTRIBUTE(dw_wdt_dbgfs_pretimeout_fops, > > + dw_wdt_dbgfs_pretimeout_get, dw_wdt_dbgfs_pretimeout_set, "%llu\n"); > > + > > +static int dw_wdt_dbgfs_ping_set(void *priv, u64 val) > > +{ > > + struct dw_wdt *dw_wdt = priv; > > + > > + dw_wdt_ping(&dw_wdt->wdd); > > + > > + return 0; > > +} > > +DEFINE_DEBUGFS_ATTRIBUTE(dw_wdt_dbgfs_ping_fops, > > + NULL, dw_wdt_dbgfs_ping_set, "%llu\n"); > > + > > +static int dw_wdt_dbgfs_en_get(void *priv, u64 *val) > > +{ > > + struct dw_wdt *dw_wdt = priv; > > + > > + *val = !!dw_wdt_is_enabled(dw_wdt); > > + > > + return 0; > > +} > > + > > +static int dw_wdt_dbgfs_en_set(void *priv, u64 val) > > +{ > > + struct dw_wdt *dw_wdt = priv; > > + > > + if (val) > > + dw_wdt_start(&dw_wdt->wdd); > > + else > > + dw_wdt_stop(&dw_wdt->wdd); > > + > > + return 0; > > +} > > +DEFINE_DEBUGFS_ATTRIBUTE(dw_wdt_dbgfs_en_fops, > > + dw_wdt_dbgfs_en_get, dw_wdt_dbgfs_en_set, "%llu\n"); > > + > > +#define DW_WDT_DBGFS_REG(_name, _off) \ > > +{ \ > > + .name = _name, \ > > + .offset = _off \ > > +} > > + > > +static const struct debugfs_reg32 dw_wdt_dbgfs_regs[] = { > > + DW_WDT_DBGFS_REG("cr", WDOG_CONTROL_REG_OFFSET), > > + DW_WDT_DBGFS_REG("torr", WDOG_TIMEOUT_RANGE_REG_OFFSET), > > + DW_WDT_DBGFS_REG("ccvr", WDOG_CURRENT_COUNT_REG_OFFSET), > > + DW_WDT_DBGFS_REG("crr", WDOG_COUNTER_RESTART_REG_OFFSET), > > + DW_WDT_DBGFS_REG("stat", WDOG_INTERRUPT_STATUS_REG_OFFSET), > > + DW_WDT_DBGFS_REG("param5", WDOG_COMP_PARAMS_5_REG_OFFSET), > > + DW_WDT_DBGFS_REG("param4", WDOG_COMP_PARAMS_4_REG_OFFSET), > > + DW_WDT_DBGFS_REG("param3", WDOG_COMP_PARAMS_3_REG_OFFSET), > > + DW_WDT_DBGFS_REG("param2", WDOG_COMP_PARAMS_2_REG_OFFSET), > > + DW_WDT_DBGFS_REG("param1", WDOG_COMP_PARAMS_1_REG_OFFSET), > > + DW_WDT_DBGFS_REG("version", WDOG_COMP_VERSION_REG_OFFSET), > > + DW_WDT_DBGFS_REG("type", WDOG_COMP_TYPE_REG_OFFSET) > > +}; > > + > > +static void dw_wdt_dbgfs_init(struct dw_wdt *dw_wdt) > > +{ > > + struct device *dev = dw_wdt->wdd.parent; > > + struct debugfs_regset32 *regset; > > + > > + regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL); > > + if (!regset) > > + return; > > + > > + regset->regs = dw_wdt_dbgfs_regs; > > + regset->nregs = ARRAY_SIZE(dw_wdt_dbgfs_regs); > > + regset->base = dw_wdt->regs; > > + > > + dw_wdt->dbgfs_dir = debugfs_create_dir(dev_name(dev), NULL); > > + > > + debugfs_create_regset32("registers", 0444, dw_wdt->dbgfs_dir, regset); > > + > > + debugfs_create_file_unsafe("timeout", 0600, dw_wdt->dbgfs_dir, > > + dw_wdt, &dw_wdt_dbgfs_timeout_fops); > > + > > + debugfs_create_file_unsafe("pretimeout", 0600, dw_wdt->dbgfs_dir, > > + dw_wdt, &dw_wdt_dbgfs_pretimeout_fops); > > + > > + debugfs_create_file_unsafe("ping", 0200, dw_wdt->dbgfs_dir, > > + dw_wdt, &dw_wdt_dbgfs_ping_fops); > > + > > + debugfs_create_file_unsafe("enable", 0600, dw_wdt->dbgfs_dir, > > + dw_wdt, &dw_wdt_dbgfs_en_fops); > > +} > > I don't oppose debugfs support in general, but I really don't see > the point replicating watchdog core functionality for it - even more so > since this bypasses the watchdog core. This lets one, for example, > enable the watchdog and then unload the driver with the watchdog > running. This is not only unnecessary, it is way too dangerous, > debugfs or not. > > NACK for that part. I see your point. What if I keep the registers dump and read-only timeout, pretimeout, enable and timeleft nodes? This won't be harmful, but the info still can be useful to debug the driver. -Sergey > > Guenter > > > + > > +static void dw_wdt_dbgfs_clear(struct dw_wdt *dw_wdt) > > +{ > > + debugfs_remove_recursive(dw_wdt->dbgfs_dir); > > +} > > + > > +#else /* !CONFIG_DEBUG_FS */ > > + > > +static void dw_wdt_dbgfs_init(struct dw_wdt *dw_wdt) {} > > +static void dw_wdt_dbgfs_clear(struct dw_wdt *dw_wdt) {} > > + > > +#endif /* !CONFIG_DEBUG_FS */ > > + > > static int dw_wdt_drv_probe(struct platform_device *pdev) > > { > > struct device *dev = &pdev->dev; > > @@ -544,6 +690,8 @@ static int dw_wdt_drv_probe(struct platform_device *pdev) > > if (ret) > > goto out_disable_pclk; > > > > + dw_wdt_dbgfs_init(dw_wdt); > > + > > return 0; > > > > out_disable_pclk: > > @@ -558,6 +706,8 @@ static int dw_wdt_drv_remove(struct platform_device *pdev) > > { > > struct dw_wdt *dw_wdt = platform_get_drvdata(pdev); > > > > + dw_wdt_dbgfs_clear(dw_wdt); > > + > > watchdog_unregister_device(&dw_wdt->wdd); > > reset_control_assert(dw_wdt->rst); > > clk_disable_unprepare(dw_wdt->pclk); > > >