Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752669AbdFLUaa (ORCPT ); Mon, 12 Jun 2017 16:30:30 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:54182 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752086AbdFLUa3 (ORCPT ); Mon, 12 Jun 2017 16:30:29 -0400 Subject: Re: [PATCH] drivers/watchdog: Add sys files to modify watchdog behavior To: Guenter Roeck References: <20170601213521.58141-1-cbostic@linux.vnet.ibm.com> <20170601220358.GC8803@roeck-us.net> Cc: wim@iguana.be, joel@jms.id.au, linux-kernel@vger.kernel.org, linux-watchdog@vger.kernel.org, andrew@aj.id.au From: Christopher Bostic Date: Mon, 12 Jun 2017 15:30:19 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: <20170601220358.GC8803@roeck-us.net> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 17061220-0020-0000-0000-00000C2534D8 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007220; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000212; SDB=6.00873848; UDB=6.00434915; IPR=6.00653935; BA=6.00005414; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015795; XFM=3.00000015; UTC=2017-06-12 20:30:27 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17061220-0021-0000-0000-00005CC2060C Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-06-12_12:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706120359 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6592 Lines: 186 On 6/1/17 5:03 PM, Guenter Roeck wrote: > On Thu, Jun 01, 2017 at 04:35:21PM -0500, Christopher Bostic wrote: >> Add files to enable/disable Aspeed watchdog: >> * External signal after timeout >> * Reset system after timeout >> > The subject line is heavily misleading. > >> Signed-off-by: Christopher Bostic >> --- >> .../ABI/testing/sysfs-platform-aspeed-wdt | 40 +++++++++++ >> drivers/watchdog/aspeed_wdt.c | 79 +++++++++++++++++++++- >> 2 files changed, 118 insertions(+), 1 deletion(-) >> create mode 100644 Documentation/ABI/testing/sysfs-platform-aspeed-wdt >> >> diff --git a/Documentation/ABI/testing/sysfs-platform-aspeed-wdt b/Documentation/ABI/testing/sysfs-platform-aspeed-wdt >> new file mode 100644 >> index 0000000..a582176 >> --- /dev/null >> +++ b/Documentation/ABI/testing/sysfs-platform-aspeed-wdt >> @@ -0,0 +1,40 @@ >> +What: /sys/bus/platform/devices/1e785000.wdt/watchdog/watchdog0/ >> + reset_system >> +Date: May 2017 >> +KernelVersion: 4.12 >> +Contact: Christopher Bostic >> +Description: >> + Value indicates if a watchdog time out results in a reset of >> + system. 'off': no system reset on timeout. 'on' there will >> + be a system reset on timeout. >> + >> + Default: off >> + >> + - Enable 'reset system' on watchdog timeout: >> + echo on > /sys/bus/platform/devices/1e785000.wdt/watchdog/ >> + watchdog0/reset_system; >> + >> + - Disable 'reset system' on watchdog timeout: >> + echo off > /sys/bus/platform/devices/1e785000.wdt/watchdog/ >> + watchdog0/reset_system; >> + >> +What: /sys/bus/platform/devices/1e785000.wdt/watchdog/watchdog0/ >> + ext_signal >> +Date: May 2017 >> +KernelVersion: 4.12 >> +Contact: Christopher Bostic >> +Description: >> + Value indicates if a watchdog time out results in an active >> + high pulse sent out an output pin. 'off': No output pulse >> + generated on watchdog time out. 'on': output pulse >> + generated on watchdog time out. >> + >> + Default: off >> + >> + - Enable 'external signal' on watchdog timeout: >> + echo on > /sys/bus/platform/devices/1e785000.wdt/watchdog/ >> + watchdog0/ext_signal; >> + >> + - Disable 'external signal' on watchdog timeout: >> + echo off > /sys/bus/platform/devices/1e785000.wdt/watchdog/ >> + watchdog0/ext_signal; > I'll want to see some discussion on those, both for the values written (on/off > vs. 0/1) and the action to be taken. Both seem to be system parameters rather > than something to set from user space. Also, there is no explanation what else > the watchdog should do on timeout if not to reset the system. If it doesn't do > anything, why run it in the first place ? Hi Guenter, I'll be resubmitting with a change to remove the sysfs files and instead add a device tree attribute that will be specific to the system affected. Thanks Chris > Also, specifying absolute path names seems wrong. There is no real guarantee > that the device is always watchdog0, that the path always includes > "1e785000.wdt", or that the path name will always start with > /sys/bus/platform/devices. > > Thanks, > Guenter > >> diff --git a/drivers/watchdog/aspeed_wdt.c b/drivers/watchdog/aspeed_wdt.c >> index 1c65258..66b27e8 100644 >> --- a/drivers/watchdog/aspeed_wdt.c >> +++ b/drivers/watchdog/aspeed_wdt.c >> @@ -136,6 +136,83 @@ static int aspeed_wdt_restart(struct watchdog_device *wdd, >> .identity = KBUILD_MODNAME, >> }; >> >> +static ssize_t aspeed_wdt_cntl_get_state(struct device *dev, char *buf, >> + uint32_t mask) >> +{ >> + struct platform_device *pdev = to_platform_device(dev); >> + struct aspeed_wdt *wdt = platform_get_drvdata(pdev); >> + int ret; >> + >> + if (readl(wdt->base + WDT_CTRL) & mask) >> + ret = sprintf(buf, "on\n"); >> + else >> + ret = sprintf(buf, "off\n"); >> + >> + return ret; >> +} >> + >> +static ssize_t aspeed_wdt_cntl_set_state(struct device *dev, const char *buf, >> + size_t count, uint32_t mask) >> +{ >> + struct platform_device *pdev = to_platform_device(dev); >> + struct aspeed_wdt *wdt = platform_get_drvdata(pdev); >> + >> + if (!strncmp(buf, "on", strlen("on"))) { >> + wdt->ctrl |= mask; >> + writel(wdt->ctrl, wdt->base + WDT_CTRL); >> + } else if (!strncmp(buf, "off", strlen("off"))) { >> + wdt->ctrl &= ~mask; >> + writel(wdt->ctrl, wdt->base + WDT_CTRL); >> + } else { >> + dev_warn(dev, "Unknown reset system mode command: [%s]\n", buf); >> + return -EINVAL; >> + } >> + >> + return count; >> +} >> + >> +static ssize_t aspeed_wdt_reset_system_store(struct device *dev, >> + struct device_attribute *attr, >> + const char *buf, size_t count) >> +{ >> + return aspeed_wdt_cntl_set_state(dev, buf, count, >> + WDT_CTRL_RESET_SYSTEM); >> +} >> + >> +static ssize_t aspeed_wdt_reset_system_show(struct device *dev, >> + struct device_attribute *attr, >> + char *buf) >> +{ >> + return aspeed_wdt_cntl_get_state(dev, buf, WDT_CTRL_RESET_SYSTEM); >> +} >> + >> +static DEVICE_ATTR(reset_system, 0644, >> + aspeed_wdt_reset_system_show, aspeed_wdt_reset_system_store); >> + >> +static ssize_t aspeed_wdt_ext_signal_store(struct device *dev, >> + struct device_attribute *attr, >> + const char *buf, size_t count) >> +{ >> + return aspeed_wdt_cntl_set_state(dev, buf, count, WDT_CTRL_WDT_EXT); >> +} >> + >> +static ssize_t aspeed_wdt_ext_signal_show(struct device *dev, >> + struct device_attribute *attr, >> + char *buf) >> +{ >> + return aspeed_wdt_cntl_get_state(dev, buf, WDT_CTRL_WDT_EXT); >> +} >> + >> +static DEVICE_ATTR(ext_signal, 0644, >> + aspeed_wdt_ext_signal_show, aspeed_wdt_ext_signal_store); >> + >> +static struct attribute *aspeed_wdt_attrs[] = { >> + &dev_attr_reset_system.attr, >> + &dev_attr_ext_signal.attr, >> + NULL >> +}; >> +ATTRIBUTE_GROUPS(aspeed_wdt); >> + >> static int aspeed_wdt_probe(struct platform_device *pdev) >> { >> struct aspeed_wdt *wdt; >> @@ -160,7 +237,7 @@ static int aspeed_wdt_probe(struct platform_device *pdev) >> wdt->wdd.ops = &aspeed_wdt_ops; >> wdt->wdd.max_hw_heartbeat_ms = WDT_MAX_TIMEOUT_MS; >> wdt->wdd.parent = &pdev->dev; >> - >> + wdt->wdd.groups = aspeed_wdt_groups; >> wdt->wdd.timeout = WDT_DEFAULT_TIMEOUT; >> watchdog_init_timeout(&wdt->wdd, 0, &pdev->dev); >> >> -- >> 1.8.2.2 >>