From patchwork Fri Jul 3 12:04:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 229076 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp2328141ilg; Fri, 3 Jul 2020 05:06:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUrEUckfCMbIkDpX8dBi52IZV2N26Pr+T+yOm1CjW9G+AyjvkE+07JszgGNL947im0MO9q X-Received: by 2002:a05:6402:1bdd:: with SMTP id ch29mr29356435edb.134.1593777972165; Fri, 03 Jul 2020 05:06:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593777972; cv=none; d=google.com; s=arc-20160816; b=zhDSNncbozhGt1bpsxSg1yHyXm1S8yWsOEpjamlB7E4bF3M71pob9aVrpx3y7q8TrX HwqjtL8x8xuy+UeCFPE2sYcgxbWCLGB4o3m/jcU0yiN9IsYPjm7xSIAjlCLuUYdVyYCm TWypcTEitpSyJ33UyDJmr/wSdSHvVBDyDmCS5c+Q5zqni8FDkWcM4nU54vdBhnjfjPYu PGglmP24oNV2tX4fjTSNt3GrNdcEzkwfqPw3Fn3cxhmmNd8MDcCE4EdV8UjbFDhNXgxR 2KYCDsuiZIRHMmAU8HefezcY9eNip66thAuQfkIU7Mc8M6SvESouJ1N0poKwY0bKgUrw uLlA== 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=VKk0r+2wsoL3MjGVaSjznFzV0l/708UsUjZION0spOs=; b=kCWfE9Geghxx3KTJWJdtwwmxa27+WnVtOhUjMm53ies8j0o/7hZCWSphRAz/D9hb3F f6w9FWv3ifcpzQMpWxU2NZtqJ9aPZoi023c145oqZbrmh5vRkr8ffwu/95LsD8X+yLqQ 3Xi845Depgnp3C+oXaIC00owpAjmjQh8u1Ipd7XFkJw7Tb+36gTgkw+vDDWqJjGw9no7 3bnnjp8pFBLdDgYGaLm9+6h0rZVH6rFj0fl/a4GaYYMxdgOrjUb4pKPR5acabtSJ0zeK JlSwV2bVL0GdvG1Dl4EvsGMcUYbqaaqa/+N92JmKW5TpW39vC3uuAET+29T5/YeTVoOr p9sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=vJak7I7p; 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 v8si7728873edr.557.2020.07.03.05.06.12 for ; Fri, 03 Jul 2020 05:06:12 -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=vJak7I7p; 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 S1726318AbgGCMGI (ORCPT ); Fri, 3 Jul 2020 08:06:08 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:59096 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726309AbgGCMGI (ORCPT ); Fri, 3 Jul 2020 08:06:08 -0400 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 063C4LFa110388; Fri, 3 Jul 2020 07:04:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1593777861; bh=VKk0r+2wsoL3MjGVaSjznFzV0l/708UsUjZION0spOs=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=vJak7I7pdR9dVnLtJNJMzzOnoT3Co0g30uf7HmTWOh+Edp8tM75ysPDea8zbs13Ga bYNf6ELJjrcXMHuHbjCUNeUXJT18Mcmmo/3ohx6b0M1f1lZnjSC2Hp5H+DnF5h57p/ /aSL6wKGXqUyICfH/1syS4H7I9mM6As2D6gOqEWc= Received: from DFLE108.ent.ti.com (dfle108.ent.ti.com [10.64.6.29]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 063C4LDl068734 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 3 Jul 2020 07:04:21 -0500 Received: from DFLE111.ent.ti.com (10.64.6.32) by DFLE108.ent.ti.com (10.64.6.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Fri, 3 Jul 2020 07:04:20 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE111.ent.ti.com (10.64.6.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; Fri, 3 Jul 2020 07:04:20 -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 063C4Fkg109800; Fri, 3 Jul 2020 07:04:19 -0500 From: Tero Kristo To: , , CC: , Subject: [PATCHv2 2/5] watchdog: add support for adjusting last known HW keepalive time Date: Fri, 3 Jul 2020 15:04:03 +0300 Message-ID: <20200703120406.7092-3-t-kristo@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200703120406.7092-1-t-kristo@ti.com> References: <20200703120406.7092-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 --- drivers/watchdog/watchdog_dev.c | 23 +++++++++++++++++++++++ include/linux/watchdog.h | 2 ++ 2 files 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/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c index bc1cfa288553..5848551cf29d 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchdog_dev.c @@ -1138,6 +1138,29 @@ void watchdog_dev_unregister(struct watchdog_device *wdd) watchdog_cdev_unregister(wdd); } +/* + * watchdog_set_last_hw_keepalive: set last HW keepalive time for watchdog + * + * Adjusts the last known HW keepalive time for a watchdog timer. + * This is needed in case where watchdog has been started before + * kernel by someone like bootloader, and it can't be pinged + * immediately. This adjusts the watchdog ping period to match + * the currently running timer. + */ +int watchdog_set_last_hw_keepalive(struct watchdog_device *wdd, + unsigned int last_ping_ms) +{ + struct watchdog_core_data *wd_data = wdd->wd_data; + ktime_t now; + + 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 *);