From patchwork Mon Jul 13 13:18:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 235393 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp2834076ilg; Mon, 13 Jul 2020 06:19:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBTglPsuh4EgDLGg76Qv+a2zyqQU6lFnNjh0HKOKqx3O32c2klWA2Mh7rwdkw2Axzdcrm4 X-Received: by 2002:a05:6402:2cb:: with SMTP id b11mr87322894edx.66.1594646398974; Mon, 13 Jul 2020 06:19:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594646398; cv=none; d=google.com; s=arc-20160816; b=zqnVD7lng2NqtfpN653fZrPP+vH+vpC3P/yXkpYODro3ZykaPgNPsCwjWCtaZc3Iua 2f1I14TFD6pR3FvpMBhHLG5V4ZNbiz816YgSgk8sQa+gtaMssWjlNYTV+qKSYzpydNO+ 64wn4xWzuApg7gCqoITZVgNUX80dQxcbKCXTUDWFS3JepQFHu0ViJVHoByo4ycphb6Jw A8TyCcjZzramzR+Q8O4QvAfv1yUWyPyhJq7LWw9neoe98EdtwhnjDX+fKldiiI0sp1CP X0OdqO6BgN3mynTYSxMTi+Y1N9w9EJob8reaEgyh9kUsVoNqzQGetmkkL4tw8n+aDNiO OL9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=G4wnnj72ALl51c7aAtn+twNQ2gnUnkuWdD4xZPMkDIs=; b=GxQCKyTrRnAyUmFLJNy59W7MeJxew6+M2ZMQUU81SxNgiFbEKP53IjCO1v10EsHgve EgM7udJTqv1Yq/UHuxPhAM2vEmFeKQjjgY92XYhH7BNB3bX0vmbIxOregMp1aSlS6UJx Jv3ax0IXCBn308ura6JUdxooEMWA0ZDTLJJljv3DxImI+v2ES4jPpUVeDvGDqHW5CTBI r6T2Iiil41So8KfBajfTt1De+Gdq2ht7V7lGLPk9yLHuuugaxFHFbYYr9YK50eiyaOrZ 2Fh4aOEQ2co1yyAaan660IPWFZSH5eJZjPXjpYqgr5JNBGmLX0gxS23UTpLeBWapFZLe sUCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="B6pBYT/+"; spf=pass (google.com: domain of linux-watchdog-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-watchdog-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g26si9777634edv.376.2020.07.13.06.19.58 for ; Mon, 13 Jul 2020 06:19:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-watchdog-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="B6pBYT/+"; spf=pass (google.com: domain of linux-watchdog-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-watchdog-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729815AbgGMNT6 (ORCPT ); Mon, 13 Jul 2020 09:19:58 -0400 Received: from lelv0142.ext.ti.com ([198.47.23.249]:35906 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729523AbgGMNTz (ORCPT ); Mon, 13 Jul 2020 09:19:55 -0400 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 06DDISB4107917; Mon, 13 Jul 2020 08:18:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1594646308; bh=G4wnnj72ALl51c7aAtn+twNQ2gnUnkuWdD4xZPMkDIs=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=B6pBYT/+x3oRTzUwM4Zu3SVwBvMX9OOtqRh6s7Tixw0mGlGmmiR0ViBxKBAiVteGA BKeoQh+bRpd8Rz1D5dtWMhTkzws9cWyz+szOFAmbWFuUkNibmp0fNclej32iOK4Pg/ togcAQh+cdiwwyOuZeE8YiGzPOf7xhyu4HK95tZM= Received: from DLEE115.ent.ti.com (dlee115.ent.ti.com [157.170.170.26]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id 06DDIS0R063774; Mon, 13 Jul 2020 08:18:28 -0500 Received: from DLEE104.ent.ti.com (157.170.170.34) by DLEE115.ent.ti.com (157.170.170.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Mon, 13 Jul 2020 08:18:28 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DLEE104.ent.ti.com (157.170.170.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Mon, 13 Jul 2020 08:18:28 -0500 Received: from sokoban.bb.dnainternet.fi (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 06DDIOXp015417; Mon, 13 Jul 2020 08:18:27 -0500 From: Tero Kristo To: , , CC: , Subject: [PATCHv3 1/4] watchdog: use __watchdog_ping in startup Date: Mon, 13 Jul 2020 16:18:15 +0300 Message-ID: <20200713131818.825-2-t-kristo@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200713131818.825-1-t-kristo@ti.com> References: <20200713131818.825-1-t-kristo@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org Current watchdog startup functionality does not respect the minimum hw heartbeat setup and the last watchdog ping timeframe when watchdog is already running and userspace process attaches to it. Fix this by using the __watchdog_ping from the startup also. For this code path, we can also let the __watchdog_ping handle the bookkeeping for the worker and last keepalive times. Signed-off-by: Tero Kristo Reviewed-by: Guenter Roeck --- drivers/watchdog/watchdog_dev.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) -- 2.17.1 -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c index 7e4cd34a8c20..bc1cfa288553 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchdog_dev.c @@ -275,15 +275,18 @@ static int watchdog_start(struct watchdog_device *wdd) set_bit(_WDOG_KEEPALIVE, &wd_data->status); started_at = ktime_get(); - if (watchdog_hw_running(wdd) && wdd->ops->ping) - err = wdd->ops->ping(wdd); - else + if (watchdog_hw_running(wdd) && wdd->ops->ping) { + err = __watchdog_ping(wdd); + if (err == 0) + set_bit(WDOG_ACTIVE, &wdd->status); + } else { err = wdd->ops->start(wdd); - if (err == 0) { - set_bit(WDOG_ACTIVE, &wdd->status); - wd_data->last_keepalive = started_at; - wd_data->last_hw_keepalive = started_at; - watchdog_update_worker(wdd); + if (err == 0) { + set_bit(WDOG_ACTIVE, &wdd->status); + wd_data->last_keepalive = started_at; + wd_data->last_hw_keepalive = started_at; + watchdog_update_worker(wdd); + } } return err; From patchwork Mon Jul 13 13:18:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 235397 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp2845998ilg; Mon, 13 Jul 2020 06:34:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUtT0pyFxBwfYoljif2dCbkNqPHB7vngdWzPOz4kjtVQCv20UDYEbc7YSMPaZqxWIWp0mh X-Received: by 2002:a17:906:c40d:: with SMTP id u13mr71281177ejz.519.1594647287246; Mon, 13 Jul 2020 06:34:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594647287; cv=none; d=google.com; s=arc-20160816; b=Owuyyj9sdfR0M6esEeNpbxDULyMX/aN3qBM+6Z62+050uSvOidHa2VtC/xaP3t1raA +gcHfFtu24Ajy9TMNUEYKjIMFMCeUZQVUI+ej1b4KcbGOAgFW3+yx50DTRDoZI3GCN+Z McqOJnKWXcX/2Wjg2EEEu4/vFhq0vxF2oOCPyagZCD5H3/gg/5fSi1TAq98LZiaoqcM2 Pgez7sgIoIwRU2rYyBqOXRpq0QQNgPJzabpjc1lwJV2gULxtm+9zar9mLfubKfZ229CF 68BTN8bw8qC1bLMxMBH/mVIBzXe+GCwyl/g+T5Uc1HuQlhoOj4egLiwvg09T51KxWJRn eVFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=1f8QGphM1gDJrV+uk7tlCewgRrYPd1fn7gpp9JJzAS0=; b=x62VtXeJwfKL6OeV/ikM54PHAxIJ/1g5un/dhYq7wwaFhunIo8NAF4avwvHihO4NcQ bF/+jVmwysTR0iypxNvEnEqO3H/XyIR2CjL/yJoa5dVCVB0nxhjAq8tGPseEq9NKwK1q Fa4PeOlxVAgePuW3rREHBp5y4fyTkeh0ackxL5UrC6lYz2XeoR7u653lh9q6k464z4J2 K2LNjBAWzyX5PUsegv/4NN9XG0my7VybAkBg3/T/FJ9vxDH7JQHv/HwmKHt7L5YWdzYo J+zEIgk5wYkoLgA0YaP7TQs6mgYJkSWyOhIgZ05qRaIhvykr5AbKKAgit9DV26lrqm5Q wXEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=KIkhB1X7; spf=pass (google.com: domain of linux-watchdog-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-watchdog-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp9si11380785ejc.698.2020.07.13.06.34.47 for ; Mon, 13 Jul 2020 06:34:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-watchdog-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=KIkhB1X7; spf=pass (google.com: domain of linux-watchdog-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-watchdog-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729839AbgGMNeq (ORCPT ); Mon, 13 Jul 2020 09:34:46 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:47312 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729805AbgGMNeq (ORCPT ); Mon, 13 Jul 2020 09:34:46 -0400 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 06DDIU8K004504; Mon, 13 Jul 2020 08:18:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1594646310; bh=1f8QGphM1gDJrV+uk7tlCewgRrYPd1fn7gpp9JJzAS0=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=KIkhB1X7dcl7x9LcoRqn8toc2ycDYj5+Kbfg7XSFguYO72MNSNFsOTt0DESx50jzK IZ+bPWfgNb/w7+2nLFei4sw2DquMXM07mHRTyvvozMUmiDkPnXYe5fNZ+e46JhvQbA e94pp2YCJD0t3jsipuh06z1KIqkgH0p/MdzV4jb0= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 06DDIUdO042001 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 13 Jul 2020 08:18:30 -0500 Received: from DLEE115.ent.ti.com (157.170.170.26) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Mon, 13 Jul 2020 08:18:29 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DLEE115.ent.ti.com (157.170.170.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Mon, 13 Jul 2020 08:18:29 -0500 Received: from sokoban.bb.dnainternet.fi (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 06DDIOXq015417; Mon, 13 Jul 2020 08:18:28 -0500 From: Tero Kristo To: , , CC: , Subject: [PATCHv3 2/4] watchdog: add support for adjusting last known HW keepalive time Date: Mon, 13 Jul 2020 16:18:16 +0300 Message-ID: <20200713131818.825-3-t-kristo@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200713131818.825-1-t-kristo@ti.com> References: <20200713131818.825-1-t-kristo@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org Certain watchdogs require the watchdog only to be pinged within a specific time window, pinging too early or too late cause the watchdog to fire. In cases where this sort of watchdog has been started before kernel comes up, we must adjust the watchdog keepalive window to match the actually running timer, so add a new driver API for this purpose. Signed-off-by: Tero Kristo --- .../watchdog/watchdog-kernel-api.rst | 12 ++++++++ drivers/watchdog/watchdog_dev.c | 30 +++++++++++++++++++ include/linux/watchdog.h | 2 ++ 3 files changed, 44 insertions(+) -- 2.17.1 -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki diff --git a/Documentation/watchdog/watchdog-kernel-api.rst b/Documentation/watchdog/watchdog-kernel-api.rst index 068a55ee0d4a..baf44e986b07 100644 --- a/Documentation/watchdog/watchdog-kernel-api.rst +++ b/Documentation/watchdog/watchdog-kernel-api.rst @@ -336,3 +336,15 @@ an action is taken by a preconfigured pretimeout governor preassigned to the watchdog device. If watchdog pretimeout governor framework is not enabled, watchdog_notify_pretimeout() prints a notification message to the kernel log buffer. + +To set the last known HW keepalive time for a watchdog, the following function +should be used:: + + int watchdog_set_last_hw_keepalive(struct watchdog_device *wdd, + unsigned int last_ping_ms) + +This function must be called immediately after watchdog registration. It +sets the last known hardware heartbeat to have happened last_ping_ms before +current time. Calling this is only needed if the watchdog is already running +when probe is called, and the watchdog can only be pinged after the +min_hw_heartbeat_ms time has passed from the last ping. diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c index bc1cfa288553..e74a0c6811b5 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchdog_dev.c @@ -1138,6 +1138,36 @@ void watchdog_dev_unregister(struct watchdog_device *wdd) watchdog_cdev_unregister(wdd); } +/* + * watchdog_set_last_hw_keepalive: set last HW keepalive time for watchdog + * @wdd: watchdog device + * @last_ping_ms: time since last HW heartbeat + * + * Adjusts the last known HW keepalive time for a watchdog timer. + * This is needed if the watchdog is already running when the probe + * function is called, and it can't be pinged immediately. This + * function must be called immediately after watchdog registration, + * and min_hw_heartbeat_ms must be set for this to be useful. + */ +int watchdog_set_last_hw_keepalive(struct watchdog_device *wdd, + unsigned int last_ping_ms) +{ + struct watchdog_core_data *wd_data; + ktime_t now; + + if (!wdd) + return -EINVAL; + + wd_data = wdd->wd_data; + + now = ktime_get(); + + wd_data->last_hw_keepalive = ktime_sub(now, ms_to_ktime(last_ping_ms)); + + return __watchdog_ping(wdd); +} +EXPORT_SYMBOL_GPL(watchdog_set_last_hw_keepalive); + /* * watchdog_dev_init: init dev part of watchdog core * diff --git a/include/linux/watchdog.h b/include/linux/watchdog.h index 1464ce6ffa31..9b19e6bb68b5 100644 --- a/include/linux/watchdog.h +++ b/include/linux/watchdog.h @@ -210,6 +210,8 @@ extern int watchdog_init_timeout(struct watchdog_device *wdd, extern int watchdog_register_device(struct watchdog_device *); extern void watchdog_unregister_device(struct watchdog_device *); +int watchdog_set_last_hw_keepalive(struct watchdog_device *, unsigned int); + /* devres register variant */ int devm_watchdog_register_device(struct device *dev, struct watchdog_device *); From patchwork Mon Jul 13 13:18:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 235395 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp2838983ilg; Mon, 13 Jul 2020 06:26:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx86fixwtFMzqyl7+of8B0Ulqt1PWKE5priZ/i/zWjBiOZfglz4SojEK1ZlKo01pLpilLIr X-Received: by 2002:a05:6402:363:: with SMTP id s3mr78181294edw.238.1594646774475; Mon, 13 Jul 2020 06:26:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594646774; cv=none; d=google.com; s=arc-20160816; b=CmN1iLh0+Ulx2AjpEfbf+LqQsUegluoFtnSdskQyxBkeow4wpWaWQcQ2/SR5+Zc1w3 Y7rT1zRok+/716GrPuZMFOYsQc1hFIfqh96NAC/2E+F32di1kUMpsCicttHa+Y6x7GMh 3Pt5d3KBNOCEAXEV7wyqzt7rdsm+fcIE2gWKzxC/wxL3dUxUNT+OZD+wTfq62j89+xh2 rbYmQdxjIt39XVmWTDxY01cEfPOpyNs5APoMceWN8xqjwQu8hnWLT/jomqnPULJku9G4 ZJV8HdlPSwMTAmMhFWzBxEvmjBaFVR23KKPvoRKsC59mueu+DWtcfsdXkSZnEh2Xdzgv xEbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=wQ0AjsWp9AHSyNL3eQMx/G1gq1SORFAJ4yWvonHRb60=; b=aaFU5C2X7kAiyFw9ObdZZ8r8sustWlIY4nAMJ+WJOIz9618rrubrjiebx4wnjjDlJo 9lfWxFkQGyOnrjJWp/wUmXLIz48nVxfXCTv+o1Yn7TFo9ZnBLwp1kpdbgJVvOiVM4yIz YiXLGX8jUJNUWPk5oYViFzQcZ5Uf/w0+K++xC5U7/SiH9Q0jixvHYK6Xmpz5gtzi6gTC fj/ldRklBcgPAj2wJ7FJ9RnoVwKv+IJDCsmmh5UFHUZDdtnJg2ENta4fVXFWWqwN9Ez+ cI2yjjoHPYnF5B3+TC1xSCcn7k5Ww54p8EXPLB4R4jnRxMnN8Z0rbhGGEmpFQNwZcQVo qmCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=p9556Dgm; spf=pass (google.com: domain of linux-watchdog-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-watchdog-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cb18si9064740ejb.534.2020.07.13.06.26.14 for ; Mon, 13 Jul 2020 06:26:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-watchdog-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=p9556Dgm; spf=pass (google.com: domain of linux-watchdog-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-watchdog-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729631AbgGMN0O (ORCPT ); Mon, 13 Jul 2020 09:26:14 -0400 Received: from lelv0143.ext.ti.com ([198.47.23.248]:55130 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729613AbgGMN0N (ORCPT ); Mon, 13 Jul 2020 09:26:13 -0400 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 06DDIWtv090683; Mon, 13 Jul 2020 08:18:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1594646312; bh=wQ0AjsWp9AHSyNL3eQMx/G1gq1SORFAJ4yWvonHRb60=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=p9556DgmA5at/waqCveAf70Ob6C7a91cGe4W6NKkiCiXGbX3fmFkmnHv4t5n882Wl ji53gF6bJqxeUmSG1n4XNb2NcK9KHGlCr6TXWhfVhMuuYWCpOhDX2Dkffx5tq5XGx7 9qZb7n1+pxFcYAGtVezOfgJQ3XMmiqRC2+yUlCak= Received: from DLEE101.ent.ti.com (dlee101.ent.ti.com [157.170.170.31]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 06DDIWbP042059 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 13 Jul 2020 08:18:32 -0500 Received: from DLEE102.ent.ti.com (157.170.170.32) by DLEE101.ent.ti.com (157.170.170.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Mon, 13 Jul 2020 08:18:31 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DLEE102.ent.ti.com (157.170.170.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Mon, 13 Jul 2020 08:18:31 -0500 Received: from sokoban.bb.dnainternet.fi (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 06DDIOXr015417; Mon, 13 Jul 2020 08:18:30 -0500 From: Tero Kristo To: , , CC: , Subject: [PATCHv3 3/4] watchdog: rti-wdt: attach to running watchdog during probe Date: Mon, 13 Jul 2020 16:18:17 +0300 Message-ID: <20200713131818.825-4-t-kristo@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200713131818.825-1-t-kristo@ti.com> References: <20200713131818.825-1-t-kristo@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org If the RTI watchdog is running already during probe, the driver must configure itself to match the HW. Window size and timeout is probed from hardware, and the last keepalive ping is adjusted to match it also. Signed-off-by: Tero Kristo --- drivers/watchdog/rti_wdt.c | 111 +++++++++++++++++++++++++++++++++---- 1 file changed, 101 insertions(+), 10 deletions(-) -- 2.17.1 -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki Reported-by: kernel test robot Reported-by: kernel test robot diff --git a/drivers/watchdog/rti_wdt.c b/drivers/watchdog/rti_wdt.c index d456dd72d99a..45dfc546e371 100644 --- a/drivers/watchdog/rti_wdt.c +++ b/drivers/watchdog/rti_wdt.c @@ -35,7 +35,11 @@ #define RTIWWDRX_NMI 0xa -#define RTIWWDSIZE_50P 0x50 +#define RTIWWDSIZE_50P 0x50 +#define RTIWWDSIZE_25P 0x500 +#define RTIWWDSIZE_12P5 0x5000 +#define RTIWWDSIZE_6P25 0x50000 +#define RTIWWDSIZE_3P125 0x500000 #define WDENABLE_KEY 0xa98559da @@ -48,7 +52,7 @@ #define DWDST BIT(1) -static int heartbeat; +static int heartbeat = DEFAULT_HEARTBEAT; /* * struct to hold data for each WDT device @@ -79,11 +83,9 @@ static int rti_wdt_start(struct watchdog_device *wdd) * be petted during the open window; not too early or not too late. * The HW configuration options only allow for the open window size * to be 50% or less than that; we obviouly want to configure the open - * window as large as possible so we select the 50% option. To avoid - * any glitches, we accommodate 5% safety margin also, so we setup - * the min_hw_hearbeat at 55% of the timeout period. + * window as large as possible so we select the 50% option. */ - wdd->min_hw_heartbeat_ms = 11 * wdd->timeout * 1000 / 20; + wdd->min_hw_heartbeat_ms = 500 * wdd->timeout; /* Generate NMI when wdt expires */ writel_relaxed(RTIWWDRX_NMI, wdt->base + RTIWWDRXCTRL); @@ -110,7 +112,48 @@ static int rti_wdt_ping(struct watchdog_device *wdd) return 0; } -static unsigned int rti_wdt_get_timeleft(struct watchdog_device *wdd) +static int rti_wdt_setup_hw_hb(struct watchdog_device *wdd, u32 wsize) +{ + /* + * RTI only supports a windowed mode, where the watchdog can only + * be petted during the open window; not too early or not too late. + * The HW configuration options only allow for the open window size + * to be 50% or less than that. + */ + switch (wsize) { + case RTIWWDSIZE_50P: + /* 50% open window => 50% min heartbeat */ + wdd->min_hw_heartbeat_ms = 500 * heartbeat; + break; + + case RTIWWDSIZE_25P: + /* 25% open window => 75% min heartbeat */ + wdd->min_hw_heartbeat_ms = 750 * heartbeat; + break; + + case RTIWWDSIZE_12P5: + /* 12.5% open window => 87.5% min heartbeat */ + wdd->min_hw_heartbeat_ms = 875 * heartbeat; + break; + + case RTIWWDSIZE_6P25: + /* 6.5% open window => 93.5% min heartbeat */ + wdd->min_hw_heartbeat_ms = 935 * heartbeat; + break; + + case RTIWWDSIZE_3P125: + /* 3.125% open window => 96.9% min heartbeat */ + wdd->min_hw_heartbeat_ms = 969 * heartbeat; + break; + + default: + return -EINVAL; + } + + return 0; +} + +static unsigned int rti_wdt_get_timeleft_ms(struct watchdog_device *wdd) { u64 timer_counter; u32 val; @@ -123,11 +166,18 @@ static unsigned int rti_wdt_get_timeleft(struct watchdog_device *wdd) timer_counter = readl_relaxed(wdt->base + RTIDWDCNTR); + timer_counter *= 1000; + do_div(timer_counter, wdt->freq); return timer_counter; } +static unsigned int rti_wdt_get_timeleft(struct watchdog_device *wdd) +{ + return rti_wdt_get_timeleft_ms(wdd) / 1000; +} + static const struct watchdog_info rti_wdt_info = { .options = WDIOF_KEEPALIVEPING, .identity = "K3 RTI Watchdog", @@ -148,6 +198,7 @@ static int rti_wdt_probe(struct platform_device *pdev) struct watchdog_device *wdd; struct rti_wdt_device *wdt; struct clk *clk; + u32 last_ping = 0; wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); if (!wdt) @@ -169,6 +220,14 @@ static int rti_wdt_probe(struct platform_device *pdev) return -EINVAL; } + /* + * If watchdog is running at 32k clock, it is not accurate. + * Adjust frequency down in this case so that we don't pet + * the watchdog too often. + */ + if (wdt->freq < 32768) + wdt->freq = wdt->freq * 9 / 10; + pm_runtime_enable(dev); ret = pm_runtime_get_sync(dev); if (ret) { @@ -185,11 +244,8 @@ static int rti_wdt_probe(struct platform_device *pdev) wdd->min_timeout = 1; wdd->max_hw_heartbeat_ms = (WDT_PRELOAD_MAX << WDT_PRELOAD_SHIFT) / wdt->freq * 1000; - wdd->timeout = DEFAULT_HEARTBEAT; wdd->parent = dev; - watchdog_init_timeout(wdd, heartbeat, dev); - watchdog_set_drvdata(wdd, wdt); watchdog_set_nowayout(wdd, 1); watchdog_set_restart_priority(wdd, 128); @@ -201,12 +257,47 @@ static int rti_wdt_probe(struct platform_device *pdev) goto err_iomap; } + if (readl(wdt->base + RTIDWDCTRL) == WDENABLE_KEY) { + u32 time_left_ms; + u64 heartbeat_ms; + u32 wsize; + + set_bit(WDOG_HW_RUNNING, &wdd->status); + time_left_ms = rti_wdt_get_timeleft_ms(wdd); + heartbeat_ms = readl(wdt->base + RTIDWDPRLD); + heartbeat_ms <<= WDT_PRELOAD_SHIFT; + heartbeat_ms *= 1000; + heartbeat_ms /= wdt->freq; + if (heartbeat_ms / 1000 != heartbeat) + dev_warn(dev, "watchdog already running, ignoring heartbeat config!\n"); + + heartbeat = heartbeat_ms / 1000; + + wsize = readl(wdt->base + RTIWWDSIZECTRL); + ret = rti_wdt_setup_hw_hb(wdd, wsize); + if (ret) { + dev_err(dev, "bad window size.\n"); + goto err_iomap; + } + + last_ping = heartbeat_ms - time_left_ms; + if (time_left_ms > heartbeat_ms) { + dev_warn(dev, "time_left > heartbeat? Assuming last ping just before now.\n"); + last_ping = 0; + } + } + + watchdog_init_timeout(wdd, heartbeat, dev); + ret = watchdog_register_device(wdd); if (ret) { dev_err(dev, "cannot register watchdog device\n"); goto err_iomap; } + if (last_ping) + watchdog_set_last_hw_keepalive(wdd, last_ping); + return 0; err_iomap: From patchwork Mon Jul 13 13:18:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 235394 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp2834465ilg; Mon, 13 Jul 2020 06:20:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9YDrQX8JmGi1s4e9iJvlrc1AMOWmjboo0mmzuih+I/DZ+dcIkJz7GdNlE9eOpMvAigydB X-Received: by 2002:a17:906:408c:: with SMTP id u12mr66653703ejj.162.1594646425367; Mon, 13 Jul 2020 06:20:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594646425; cv=none; d=google.com; s=arc-20160816; b=LNlcp1KzmUN7ZNRvtnIATlBckNvz1JtmQtSxDONbMPklnUKYwHsVUegaOz0zseKsLB escYnMYqNfXQgonIPAyN396xgOk/4YHBrWknQxDc5/aP9d7L7UPLpGyGd7EteXYaV1TI aUgVV5FANFx6fAyhoshLnVSuru9haQSgxM82khFyVNQfgYipyML4mndkiBJekvUG5xw+ jWTkzrXI3rJIk/F3wqk0tPk+2FQTY+vuAyxiDH4qvdu30Zpk/AW21yo9++qJJUwLkYXU KYagBM+5mRU/d26HPwaoRKPz/6GcMye/hTVOku5o/wTtUUrgie8ItUh7D4DxTPcsaAuC pyWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=IsCx21R9uOak9QcS7V2jheu5SR94fsyWHn32kBIsdH8=; b=F923axIctY6dpcQDdrDhzXWVkkX4Z0+n9i2Ox+L+jc52xysFxJI8P54YzTToQIpcJM 1tc2OQpcYoe97v3gPNHTE07tjGw/sl7AZYjSaKXxA0dgv7qGA7GF73LiPu3+GPr7nWd4 trbPuGqX1eYtJgVJ7YOASpm9PM0EuXEZKOv1W767JU80KB+tFnthzOA2KGmePN++9Sac wIBlpffDVVywLM+lOoQLivhf/A87X5n3wbRarfzlo0CqRWkx/3zivMBkwxb0nWgPnjIy 30bVMXLN6C9mFa+ebpy/4XwfdEu/kUsQFlKjvGO32OhgElpc0Sz29pIspQxXvlYCPxcw DPiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=kG09VKpe; spf=pass (google.com: domain of linux-watchdog-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-watchdog-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dr21si13075473ejc.489.2020.07.13.06.20.25 for ; Mon, 13 Jul 2020 06:20:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-watchdog-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=kG09VKpe; spf=pass (google.com: domain of linux-watchdog-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-watchdog-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729814AbgGMNUZ (ORCPT ); Mon, 13 Jul 2020 09:20:25 -0400 Received: from lelv0143.ext.ti.com ([198.47.23.248]:54502 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729751AbgGMNUY (ORCPT ); Mon, 13 Jul 2020 09:20:24 -0400 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 06DDIXOF090700; Mon, 13 Jul 2020 08:18:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1594646313; bh=IsCx21R9uOak9QcS7V2jheu5SR94fsyWHn32kBIsdH8=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=kG09VKpebNsw7WybqlaWAHpeMirfS/GUqi2jbftB9uIIaYJ9PqxqJcJIs+NIwezE9 U90FAyKAh8j4rGyGCXhJjVVutG/ocKEF+pQ4E2UYZqLeH5wsDpPF/PONyPXZZf711n 5as93xlL3tp+ZmR7PyRL/ZTYBUfLxREbZRgmDlhc= Received: from DFLE113.ent.ti.com (dfle113.ent.ti.com [10.64.6.34]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 06DDIXl9092260 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 13 Jul 2020 08:18:33 -0500 Received: from DFLE105.ent.ti.com (10.64.6.26) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Mon, 13 Jul 2020 08:18:33 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Mon, 13 Jul 2020 08:18:33 -0500 Received: from sokoban.bb.dnainternet.fi (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 06DDIOXs015417; Mon, 13 Jul 2020 08:18:32 -0500 From: Tero Kristo To: , , CC: , Subject: [PATCHv3 4/4] watchdog: rti-wdt: balance pm runtime enable calls Date: Mon, 13 Jul 2020 16:18:18 +0300 Message-ID: <20200713131818.825-5-t-kristo@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200713131818.825-1-t-kristo@ti.com> References: <20200713131818.825-1-t-kristo@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org PM runtime should be disabled in the fail path of probe and when the driver is removed. Fixes: 2d63908bdbfb ("watchdog: Add K3 RTI watchdog support") Signed-off-by: Tero Kristo Reviewed-by: Guenter Roeck --- drivers/watchdog/rti_wdt.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.17.1 -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki diff --git a/drivers/watchdog/rti_wdt.c b/drivers/watchdog/rti_wdt.c index 45dfc546e371..5cc1a1d654b6 100644 --- a/drivers/watchdog/rti_wdt.c +++ b/drivers/watchdog/rti_wdt.c @@ -302,6 +302,7 @@ static int rti_wdt_probe(struct platform_device *pdev) err_iomap: pm_runtime_put_sync(&pdev->dev); + pm_runtime_disable(&pdev->dev); return ret; } @@ -312,6 +313,7 @@ static int rti_wdt_remove(struct platform_device *pdev) watchdog_unregister_device(&wdt->wdd); pm_runtime_put(&pdev->dev); + pm_runtime_disable(&pdev->dev); return 0; }