From patchwork Tue Nov 3 08:28:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Gong X-Patchwork-Id: 7540761 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 00516BEEA4 for ; Tue, 3 Nov 2015 08:32:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D1E5F20534 for ; Tue, 3 Nov 2015 08:32:17 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ACBA5201EF for ; Tue, 3 Nov 2015 08:32:16 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZtWzH-0001aY-CX; Tue, 03 Nov 2015 08:30:39 +0000 Received: from mail-by2on0138.outbound.protection.outlook.com ([207.46.100.138] helo=na01-by2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZtWzC-0000zL-7L for linux-arm-kernel@lists.infradead.org; Tue, 03 Nov 2015 08:30:36 +0000 Received: from CO2PR03CA0038.namprd03.prod.outlook.com (10.141.194.165) by DM2PR0301MB0736.namprd03.prod.outlook.com (10.160.97.144) with Microsoft SMTP Server (TLS) id 15.1.312.18; Tue, 3 Nov 2015 08:30:12 +0000 Received: from BN1AFFO11FD025.protection.gbl (2a01:111:f400:7c10::118) by CO2PR03CA0038.outlook.office365.com (2a01:111:e400:1414::37) with Microsoft SMTP Server (TLS) id 15.1.318.9 via Frontend Transport; Tue, 3 Nov 2015 08:30:11 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; lists.infradead.org; dkim=none (message not signed) header.d=none;lists.infradead.org; dmarc=none action=none header.from=freescale.com; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD025.mail.protection.outlook.com (10.58.52.85) with Microsoft SMTP Server (TLS) id 15.1.318.9 via Frontend Transport; Tue, 3 Nov 2015 08:30:11 +0000 Received: from shlinux2.ap.freescale.net (shlinux2.ap.freescale.net [10.192.224.44]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id tA38U7e9003078; Tue, 3 Nov 2015 01:30:08 -0700 From: Robin Gong To: , , Subject: [PATCH v3 1/2] watchdog: add WDIOC_SETPRETIMEOUT and WDIOC_GETPRETIMEOUT Date: Tue, 3 Nov 2015 16:28:13 +0800 Message-ID: <1446539294-15419-1-git-send-email-b38343@freescale.com> X-Mailer: git-send-email 1.9.1 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD025; 1:fCTyHBjCYUbhXgxn2mIXXU//643IRzskl7W9ZT2T8FV4FICKrtgBW7vOJsBcthom+H7QmV/wqNOVtpQzLMQs3kKaWz8eV5/lViaDidt3pszgkO/AD8UYoUkym894IhVXg3D5MKpw0Pxv2HMiWpyRf2EhTr0xRSH/sTPLz6GdSydc+8qeh9cBV6Zbvry0yFlwlaTxgqaN/IKN/ljrwLy1dmFtRLSQsY054CMTjBRKLgFhMsf9xuRahYg5Qk7ddASNk06BWrhbEJYR7T/cTH6FY/HqCLGkcQ4R1cP43dYP0PVA+t1c0EiF/v1pvzsMgufVQiLyd3hEj3BnKCdfbEy4E2hTPJjhcZIIOcbRmfFOynLjWq4Bbapq9bscM31MGhmY X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(85426001)(50986999)(5001920100001)(87936001)(5001770100001)(575784001)(2201001)(48376002)(33646002)(105606002)(36756003)(50466002)(92566002)(19580395003)(77096005)(6806005)(104016004)(106466001)(5007970100001)(19580405001)(5003940100001)(229853001)(97736004)(81156007)(189998001)(5001960100002)(50226001)(47776003)(11100500001)(5008740100001)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:DM2PR0301MB0736; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0736; 2:nkQkUFHqr0bzbNvR2xUnemo0t5eYXK4X2jgnyV4nyauJOURokleo5Y3X/+hRfFLj+9c7hu5pLalPEzqx1qkUJBsECQBZllzGpi0qfUsKJYb1brCnmfpK58aLsbWc1KZ/glB+5DdMHKRAn9YiYYR8dbwCc8+h2cxQd2AvlCwAQNo=; 3:DjWh5TG8sJpPNg6x5Ar2diMS7wvfvxCG8RfMQO1RZIx3+PwOVOJC6kz+oj8alz9UU0SSGKFlsoaQVA/84HjPQJUnuup5AknzlMFUAVaTY+3n0V3uBNk68kGyXIDFAaOY++n2YY5bPS9Em9XG3UbRfG/sf4M5lntC40hJy7Lgpu+7hZGrnsvsmePKcyGKwfJw2S4g3DQwidWWgCxPe//ILrM6bzalujn/M+eR2O5AkhU=; 25:PuNHSBR34mOno1TXvMynEO7r+vesMGVVubPWsp6O1MJjveuLWWe29tRMB9bPeJvq4qOf24gphMbjhJ9Lq12GX/dZQKTM0d5XWvmgeys//57Y3kchATjdSerALaRCbzzV3mqRCFXcgd/CFjsTQfO9YBd22N7uiAn6Old9EkBGmwFvn2UZv6K6r0dOm0V3gCDirETmqNt0hEw9iNfMLleW3fG/Mz5Vgpoj4DNea5YO0YmMHz96HXQqbi5OMqE+GaOcDbF8DeE3G5SL8sBc5yEQog== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB0736; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0736; 20:/rYbFthcCHESGdHYZzBm3PmVS7eTCeqbMerRI5OLw0I3wANrnl0rBn2kl8iTX3E29nHA3jF5ok64Y0pad3wxB7mA2SsxHEcvDVrfmqjZjZInIAfB/7JqxSUswg50irW0IDYQSPwKd67ctbHcL+90rOOaloCXqQNyL54/lIuy1Ttjafo/r2iakLjUu5PEvWSalYDD1NzIA6vK1Mjv4dVV7yF9gzETDIk09M4xrtsQRlzlxJd2kOZ9SyjRv7P8lEUWaBtkUdahYfZViyXtWxxsQUZudBodtUYwnG9my+rTMiRLcFxLV8DLrCCG3jk9UBuC7oexlRboiePJm2u1bPU8iz3hLGfz6GADAzTsXimaO0I=; 4:Kaxtsl9lFoYqgtGmSfk3lkF+6Fcg8f2CT0/2MSCJCSskEq3GM2xvJ6EcnP1cYhOliC3YQEfB9evW7OeHF1pchTiHlioJo2K7k7ODT22iUxPOvSIo57PqAZvaIQhVm7R0yHsNahyTDasFx1AXojMj8OY9fKfFqG0TtKu3FCTW+u1e5Knu9jkN9ZFjY9OX+SR+zJi6HpW3pTQMChABvcTv7OZhF87/gS+dJW791+HgbBYSzJmE8r+RxPYo0AV1Oj1RBUxgrVHbyDXTXgdTbtWVWLLIMdhSzcNT9koSNVgz6l12Zj/rMvz3d9LP1N6cViw36PLW+1hkcnvHmz+n931Y9RtGR+kTlMz6Wts0eotHcCrt3c0ZsayD60NbA/w6lTBG X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(10201501046)(3002001); SRVR:DM2PR0301MB0736; BCL:0; PCL:0; RULEID:; SRVR:DM2PR0301MB0736; X-Forefront-PRVS: 0749DC2CE6 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR0301MB0736; 23:+axW+SrUF4ZORsrvuEDPlg9qY5j61kTH5jYFe4H?= =?us-ascii?Q?Gkx1tSuhnjKqXmMyTL1WLLWZDipkE80FHvc3RT2VOW4P+mSc2YPRmB4OhhFG?= =?us-ascii?Q?BsZWAHgN3xab26Nw6O3VCSPrTJlC23DATAAUPusNgZOz1eQadbwq9Dc256zC?= =?us-ascii?Q?eM5xdHBWNSgfA3HuA8i1C2dHR7sVYiCK/Y3cFp4pF23++ibLRV3pIlxjHBye?= =?us-ascii?Q?GAOfl7hh9GzNxKIod+lMT8nXVM6gXolM6bPXlTkwWDtGf0imUdA7TI2f0UJk?= =?us-ascii?Q?xWD60v9xwy4gpsNm2TohfuU1qqPxkZvp6KLlIG18QxE4XzQwcqBOGBRA+gvJ?= =?us-ascii?Q?ojZr8+Jwd094A5yJopmS8pmwnaLcFkRfJl/YIoM57dfQTEG719JC/G7JAg1Y?= =?us-ascii?Q?sJ1Uw8gGFsH04tBLYPeOd80BkS1UGgcKL1Wxxu6oyh0/MOHW+thCSiqLJq1F?= =?us-ascii?Q?Y6Jl1TjYljFZqY3ePQ65t3aO5vvys0IAcHzr+m0yQPAIaHGkZdFKy9BTcEcC?= =?us-ascii?Q?Y80Kgc5+PMBsqFfnDuSVbeRdGl8fOdDqMF+O+prNd/6tcEqtaYENFm9kH4f/?= =?us-ascii?Q?ufAX6XJFOSTUtttnuZgKmgq4ZbQC71s+66rmsKDI9ivignr3I2ptlUjA1UpJ?= =?us-ascii?Q?Sg/X8kbGTl/FYMU7/pG/67ChjXomYo9OA9j+6ZN2sNMt0lnsqqURutJl8Xyw?= =?us-ascii?Q?sZVIYxWqqPpsDq2Df3kjP5DLVfAvWxorBWigEt693YEr02XF8q02R2Kd2VOU?= =?us-ascii?Q?7qavaazynO6k8nLmSlLoHV1V/ghQ08k0NxP7SvdnUssP4KZyWELvplTZc/iK?= =?us-ascii?Q?IpUS6NbfArxjz33gLfybpHyquccFPlXZF8jmmTVNfJwmGhTCHtaousPUQebG?= =?us-ascii?Q?aFSsIQoyLrXwmgPJ1MM0Ue+2H/gzEe4FirB2lZIBD+6cg55YbwRizbRKVWTV?= =?us-ascii?Q?xgtDezKGTVxJXU+pd2VhbQLtNDzIBGF1c0x6ijUKPS9iIwX0k8khSLV8IhEM?= =?us-ascii?Q?gc0i1EjJLGpNuIB6b4WK2QTkmJkV8j/oFVxz2IfIpkP1avJBRp4AKfWC0QHo?= =?us-ascii?Q?cCRdu0tQ=3D?= X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0736; 5:zwsrRDoQVDd/3wG2imzkyoudZpZ+3no2r1eP9nxZU16Jra89heHqdhF/TdqAAzWEAhcgRUAdoH6xM8yL87rJVqxILx+QsfbNmoF6LcgCdHcH3oMQZglGcoOCMTx57azk/3Zva8tewR1QPPkU1Y7FxQ==; 24:1ojArekgWgbTEVP01WeFi0ICsC5e5bnYmScgZtFf1fyL6O++74j08hozEZgMgxXqJw+uU1PRcBy6dImA+jXX14s3hABuhtOsXxIhsGMqG6s=; 20:6IKoU0Am/p/AyfcWulIne1sooXZdiKPML2ybPBsDYb3hv8f4rIiTcbQDrLayxcclFg+fR1037z5o+Ncq/X0QMg== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2015 08:30:11.1869 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0301MB0736 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151103_003034_364893_3ABC09B2 X-CRM114-Status: GOOD ( 24.73 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since the watchdog common framework centrialize the IOCTL interfaces of device driver now, the SETPRETIMEOUT and GETPRETIMEOUT need to be added in the common code. Signed-off-by: Robin Gong --- Documentation/watchdog/watchdog-kernel-api.txt | 12 +++++++++ drivers/watchdog/watchdog_dev.c | 37 ++++++++++++++++++++++++++ include/linux/watchdog.h | 11 ++++++++ 3 files changed, 60 insertions(+) diff --git a/Documentation/watchdog/watchdog-kernel-api.txt b/Documentation/watchdog/watchdog-kernel-api.txt index d8b0d33..20aa841 100644 --- a/Documentation/watchdog/watchdog-kernel-api.txt +++ b/Documentation/watchdog/watchdog-kernel-api.txt @@ -51,6 +51,7 @@ struct watchdog_device { const struct watchdog_ops *ops; unsigned int bootstatus; unsigned int timeout; + unsigned int pretimeout; unsigned int min_timeout; unsigned int max_timeout; void *driver_data; @@ -73,6 +74,7 @@ It contains following fields: additional information about the watchdog timer itself. (Like it's unique name) * ops: a pointer to the list of watchdog operations that the watchdog supports. * timeout: the watchdog timer's timeout value (in seconds). +* pretimeout: The watchdog devices pre_timeout value. * min_timeout: the watchdog timer's minimum timeout value (in seconds). * max_timeout: the watchdog timer's maximum timeout value (in seconds). * bootstatus: status of the device after booting (reported with watchdog @@ -99,6 +101,7 @@ struct watchdog_ops { int (*ping)(struct watchdog_device *); unsigned int (*status)(struct watchdog_device *); int (*set_timeout)(struct watchdog_device *, unsigned int); + int (*set_pretimeout)(struct watchdog_device *, unsigned int); unsigned int (*get_timeleft)(struct watchdog_device *); void (*ref)(struct watchdog_device *); void (*unref)(struct watchdog_device *); @@ -163,6 +166,15 @@ they are supported. These optional routines/operations are: because the watchdog does not necessarily has a 1 second resolution). (Note: the WDIOF_SETTIMEOUT needs to be set in the options field of the watchdog's info structure). +* set_pretimeout: this routine check and changes the pre_timeout value of + the watchdog, because some watchdog device can trigger the pre_timeout + interrupt before watchdog timeout event happened, so that we have chance + to save some critical information or something else before watchdog + triggered. The pre_timeout value means the number of seconds before + watchdog timeout.It returns 0 on success, -EINVAL for "parameter out + of range" and and -EIO for "could not write value to the watchdog". + (Note: the WDIOF_SETPRETIMEOUT needs to be set in the options field of the + watchdog's info structure). * get_timeleft: this routines returns the time that's left before a reset. * ref: the operation that calls kref_get on the kref of a dynamically allocated watchdog_device struct. diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c index 6aaefba..f4a02e5 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchdog_dev.c @@ -218,6 +218,37 @@ out_timeout: } /* + * watchdog_set_pretimeout: set the watchdog timer pretimeout + * @wddev: the watchdog device to set the timeout for + * @timeout: pretimeout to set in seconds + */ + +static int watchdog_set_pretimeout(struct watchdog_device *wddev, + unsigned int timeout) +{ + int err; + + if (!wddev->ops->set_pretimeout || + !(wddev->info->options & WDIOF_PRETIMEOUT)) + return -EOPNOTSUPP; + if (watchdog_pretimeout_invalid(wddev, timeout)) + return -EINVAL; + + mutex_lock(&wddev->lock); + + if (test_bit(WDOG_UNREGISTERED, &wddev->status)) { + err = -ENODEV; + goto out_timeout; + } + + err = wddev->ops->set_pretimeout(wddev, timeout); + +out_timeout: + mutex_unlock(&wddev->lock); + return err; +} + +/* * watchdog_get_timeleft: wrapper to get the time left before a reboot * @wddev: the watchdog device to get the remaining time from * @timeleft: the time that's left @@ -393,6 +424,12 @@ static long watchdog_ioctl(struct file *file, unsigned int cmd, if (err) return err; return put_user(val, p); + case WDIOC_SETPRETIMEOUT: + if (get_user(val, p)) + return -EFAULT; + return watchdog_set_pretimeout(wdd, val); + case WDIOC_GETPRETIMEOUT: + return put_user(wdd->pretimeout, p); default: return -ENOTTY; } diff --git a/include/linux/watchdog.h b/include/linux/watchdog.h index d74a0e9..281b949 100644 --- a/include/linux/watchdog.h +++ b/include/linux/watchdog.h @@ -25,6 +25,7 @@ struct watchdog_device; * @ping: The routine that sends a keepalive ping to the watchdog device. * @status: The routine that shows the status of the watchdog device. * @set_timeout:The routine for setting the watchdog devices timeout value. + * @set_pretimeout:The routine for setting the watchdog devices pretimeout. * @get_timeleft:The routine that get's the time that's left before a reset. * @ref: The ref operation for dyn. allocated watchdog_device structs * @unref: The unref operation for dyn. allocated watchdog_device structs @@ -44,6 +45,7 @@ struct watchdog_ops { int (*ping)(struct watchdog_device *); unsigned int (*status)(struct watchdog_device *); int (*set_timeout)(struct watchdog_device *, unsigned int); + int (*set_pretimeout)(struct watchdog_device *, unsigned int); unsigned int (*get_timeleft)(struct watchdog_device *); void (*ref)(struct watchdog_device *); void (*unref)(struct watchdog_device *); @@ -60,6 +62,7 @@ struct watchdog_ops { * @ops: Pointer to the list of watchdog operations. * @bootstatus: Status of the watchdog device at boot. * @timeout: The watchdog devices timeout value. + * @pretimeout: The watchdog devices pre_timeout value. * @min_timeout:The watchdog devices minimum timeout value. * @max_timeout:The watchdog devices maximum timeout value. * @driver-data:Pointer to the drivers private data. @@ -86,6 +89,7 @@ struct watchdog_device { const struct watchdog_ops *ops; unsigned int bootstatus; unsigned int timeout; + unsigned int pretimeout; unsigned int min_timeout; unsigned int max_timeout; void *driver_data; @@ -123,6 +127,13 @@ static inline bool watchdog_timeout_invalid(struct watchdog_device *wdd, unsigne (t < wdd->min_timeout || t > wdd->max_timeout)); } +/* Use the following function to check if a pretimeout value is invalid */ +static inline bool watchdog_pretimeout_invalid(struct watchdog_device *wdd, + unsigned int t) +{ + return wdd->timeout && t >= wdd->timeout; +} + /* Use the following functions to manipulate watchdog driver specific data */ static inline void watchdog_set_drvdata(struct watchdog_device *wdd, void *data) {