From patchwork Wed Jun 24 11:45:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 191641 Delivered-To: patch@linaro.org Received: by 2002:a92:1f07:0:0:0:0:0 with SMTP id i7csp508159ile; Wed, 24 Jun 2020 04:47:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyv3DoiIP1eW4bEbebgCO5Kbk0thsqJULdTEwD3bfJO0aec3VteRt1poSW9GZF7SjRX8oi9 X-Received: by 2002:aa7:c496:: with SMTP id m22mr27028536edq.187.1592999245341; Wed, 24 Jun 2020 04:47:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592999245; cv=none; d=google.com; s=arc-20160816; b=QS2BfysUdhP5PnFRV0bmoJCPeWWze/nKS8Y2G30G8XVKdMuDTMoijBLEu07VwlyxeY GO3bJVREb0E0ym9bcqiowP/HVtaJNzjuem7cnebMT7zv/V2QuGUMjz948sITKuHNPbQt p4B0HJH6gWsmuZ1lry6su7WfWE4Mo8CBxdfsxnmIg3f27Wd6zBDDcgX9ejMR6Jc9kvYw IKhiiFjk69xmpeTlmIdm8mmK7KUAMTGVPi0/X4Mg4/UivCdl+odXIVH+yBLkrToJkXMb WnPu6Md0PqXg5Ep+naWg5uHv0KDuuxp2S3yuAGEhZMJFri1JhuIh2+w5ODq6jSn1TVCA 8NEA== 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=bjbtiNoFP+h73n0U4OOkVxf8+tj7HqP/e0mgYCiHNb0=; b=0oiR/Aa/ac8saCI4fTf6ovRBdeWTFt+5CyID+hjumJYjQdOoB2gsviJpWW7t9YOc59 QNi9tsckVLGqo1wTbrjeXB0fHasZg9T4qpa7PU9/a4uWZXUb+I61yt3bR7xZ9c2FBMqT XWJBlS/D+6YBm6Rj7mDtT/7aRFH8MqpTmoqUv/mJd1kPWGRabHkTeGpY0XK5WhFOV3/Z xPFjwEzL9XajbYCqu55uN4gN4kkKEcqBngcMo1myA8HpHW5OBkmUSkdlZk1JbOpPucwg X0011sx8shOyNrbNILsnug6ciIxl+rYPlTRKIbSVpHFJqYcG4hoYlW/eZdMx7A0d967D MY6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="fC/zHVXQ"; 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 n14si6807439ejs.745.2020.06.24.04.47.25 for ; Wed, 24 Jun 2020 04:47: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="fC/zHVXQ"; 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 S2390712AbgFXLrY (ORCPT ); Wed, 24 Jun 2020 07:47:24 -0400 Received: from lelv0143.ext.ti.com ([198.47.23.248]:39522 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388491AbgFXLrY (ORCPT ); Wed, 24 Jun 2020 07:47:24 -0400 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 05OBjo1k091844; Wed, 24 Jun 2020 06:45:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1592999150; bh=bjbtiNoFP+h73n0U4OOkVxf8+tj7HqP/e0mgYCiHNb0=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=fC/zHVXQ4FDKULA9y3I/ZeJloco/w5BGkh08TBSUbT8V6jtvqKRbLgw+CbMI429S8 muLysdm5EAYLIKmB7pU5GofTAAYbsOuS8ow4cMo6Lk9PpxjWJ8N1WJpsX18DomvKDs tLGxuoJ1QlUt1ZqSGlu4zCVJ94ue6yd4Qmk4W3ZA= Received: from DLEE109.ent.ti.com (dlee109.ent.ti.com [157.170.170.41]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id 05OBjogs076319; Wed, 24 Jun 2020 06:45:50 -0500 Received: from DLEE115.ent.ti.com (157.170.170.26) by DLEE109.ent.ti.com (157.170.170.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Wed, 24 Jun 2020 06:45:49 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) 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; Wed, 24 Jun 2020 06:45:49 -0500 Received: from sokoban.bb.dnainternet.fi (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 05OBjkCM118804; Wed, 24 Jun 2020 06:45:48 -0500 From: Tero Kristo To: , , CC: , Subject: [PATCH 1/2] watchdog: use __watchdog_ping in startup Date: Wed, 24 Jun 2020 14:45:33 +0300 Message-ID: <20200624114534.1362-2-t-kristo@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200624114534.1362-1-t-kristo@ti.com> References: <20200624114534.1362-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 --- 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 Reviewed-by: Guenter Roeck 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 Wed Jun 24 11:45:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 191642 Delivered-To: patch@linaro.org Received: by 2002:a92:1f07:0:0:0:0:0 with SMTP id i7csp508282ile; Wed, 24 Jun 2020 04:47:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBhgZB5WuCxYzAeMRSJt1oE4P2L1pX7nUhAqvcSALtJ/2eMsj70U4OoRhyEG7M7CHTlsS9 X-Received: by 2002:a05:6402:1c8b:: with SMTP id cy11mr25710603edb.122.1592999258021; Wed, 24 Jun 2020 04:47:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592999258; cv=none; d=google.com; s=arc-20160816; b=kE+ZRO06sHUudnVWKD6kglgJ/IDlW9qDPd+JXjOB3RGLTdSyqMhTamsISzQdU1DmhV go0uP3aA6I6UQ/2eAHNzfdz7ftnUFfBsLGMplPfDRT+AvQEwRd7Z2ctBpUnOWWWKym1x fyrk1XEVpiSVpbrbrIa8pPI1fBd4W3+w8wA5ujhdyfIb3KAAKIb/TFcSpAoXEiNZT7Pk TNd7/GJ6LTTXLYijBj7HMoc6LZxCRSsM2gGh4l2/GcaBvlfjs9bcH7gYK4P6b1onl4JD tMlMDUpsPGdDM3uqUSU9poiGGH0X/IbEG/UxcMlOHFvowADTmpoxBP9+N1AM9di7jNLE vxeg== 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=6X9zZUsoFQTdU0DIGFIuVsDvl3k1u78biIHYBoola70=; b=DReDiLNFMPNHWvjlugRgeZfQQ3C/JAv465g2i9lBTDQpXCToubLRNt7h6ub8/o5QDK 2drMCRfhU4Lo+Ej1MaB4w0aFfNrJiqsFaIBtp92+CUffV0mohSkNRT7ZIWay0A+zmkf3 aIXipPY5VS5RGFNkO9c5frCKTn08JKen4cL2V8iYJrrVCQwdfRz6xou/E7gHq8nBBOIn 4L6+dZpL+VYATwc2xk3kMvt8wtiq7xK8dgGrk0rEHOd78N9dfKOwJ6hNd9pTtK3JsY+d fDfkqbtscLT6EwK+CzUapXtRpEAHeKil3VY7XAUmykl8ja0bEwcmnA0zYIAmkJwnAtrr kTjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=IRwG4JIz; 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 y19si1111339eje.247.2020.06.24.04.47.37 for ; Wed, 24 Jun 2020 04:47:38 -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=IRwG4JIz; 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 S2389315AbgFXLrh (ORCPT ); Wed, 24 Jun 2020 07:47:37 -0400 Received: from fllv0015.ext.ti.com ([198.47.19.141]:42410 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388491AbgFXLrh (ORCPT ); Wed, 24 Jun 2020 07:47:37 -0400 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 05OBjqYb027297; Wed, 24 Jun 2020 06:45:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1592999152; bh=6X9zZUsoFQTdU0DIGFIuVsDvl3k1u78biIHYBoola70=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=IRwG4JIzY464dSINOVUTDq2mdgfxdkE4PwrWioubCV4tnlJexcL6eNMPqR1xX41Pm cUl2QXkTnqrylpa8f5IvLG2PwQGo1THbA/hk6dm5a44vndGFTrA8XFEzDzYiCvjOZv L11csoT38o/KQ62gTYyecv/MKpcii4aoS0yRicSQ= Received: from DLEE105.ent.ti.com (dlee105.ent.ti.com [157.170.170.35]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id 05OBjpl1076329; Wed, 24 Jun 2020 06:45:52 -0500 Received: from DLEE109.ent.ti.com (157.170.170.41) by DLEE105.ent.ti.com (157.170.170.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Wed, 24 Jun 2020 06:45:51 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DLEE109.ent.ti.com (157.170.170.41) 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; Wed, 24 Jun 2020 06:45:51 -0500 Received: from sokoban.bb.dnainternet.fi (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 05OBjkCN118804; Wed, 24 Jun 2020 06:45:50 -0500 From: Tero Kristo To: , , CC: , Subject: [PATCH 2/2] watchdog: rti: tweak min_hw_heartbeat_ms to match initial allowed window Date: Wed, 24 Jun 2020 14:45:34 +0300 Message-ID: <20200624114534.1362-3-t-kristo@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200624114534.1362-1-t-kristo@ti.com> References: <20200624114534.1362-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 has been started by someone (like bootloader) when the driver probes, we must adjust the initial ping timeout to match the currently running watchdog window to avoid generating watchdog reset. Signed-off-by: Tero Kristo --- drivers/watchdog/rti_wdt.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 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 d456dd72d99a..02ea2b2435f5 100644 --- a/drivers/watchdog/rti_wdt.c +++ b/drivers/watchdog/rti_wdt.c @@ -55,11 +55,13 @@ static int heartbeat; * @base - base io address of WD device * @freq - source clock frequency of WDT * @wdd - hold watchdog device as is in WDT core + * @min_hw_heartbeat_save - save of the min hw heartbeat value */ struct rti_wdt_device { void __iomem *base; unsigned long freq; struct watchdog_device wdd; + unsigned int min_hw_heartbeat_save; }; static int rti_wdt_start(struct watchdog_device *wdd) @@ -107,6 +109,11 @@ static int rti_wdt_ping(struct watchdog_device *wdd) /* put watchdog in active state */ writel_relaxed(WDKEY_SEQ1, wdt->base + RTIWDKEY); + if (wdt->min_hw_heartbeat_save) { + wdd->min_hw_heartbeat_ms = wdt->min_hw_heartbeat_save; + wdt->min_hw_heartbeat_save = 0; + } + return 0; } @@ -201,6 +208,24 @@ static int rti_wdt_probe(struct platform_device *pdev) goto err_iomap; } + if (readl(wdt->base + RTIDWDCTRL) == WDENABLE_KEY) { + u32 time_left; + u32 heartbeat; + + set_bit(WDOG_HW_RUNNING, &wdd->status); + time_left = rti_wdt_get_timeleft(wdd); + heartbeat = readl(wdt->base + RTIDWDPRLD); + heartbeat <<= WDT_PRELOAD_SHIFT; + heartbeat /= wdt->freq; + if (time_left < heartbeat / 2) + wdd->min_hw_heartbeat_ms = 0; + else + wdd->min_hw_heartbeat_ms = + (time_left - heartbeat / 2 + 1) * 1000; + + wdt->min_hw_heartbeat_save = 11 * heartbeat * 1000 / 20; + } + ret = watchdog_register_device(wdd); if (ret) { dev_err(dev, "cannot register watchdog device\n");