From patchwork Tue Nov 3 08:26:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Gong X-Patchwork-Id: 7540721 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 5B216BEEA4 for ; Tue, 3 Nov 2015 08:31:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 39C2420729 for ; Tue, 3 Nov 2015 08:31:12 +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 2264F2071B for ; Tue, 3 Nov 2015 08:31:11 +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 1ZtWxz-00080d-Oc; Tue, 03 Nov 2015 08:29:19 +0000 Received: from mail-bn1on0146.outbound.protection.outlook.com ([157.56.110.146] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZtWxw-0007nw-7W for linux-arm-kernel@lists.infradead.org; Tue, 03 Nov 2015 08:29:17 +0000 Received: from CH1PR03CA010.namprd03.prod.outlook.com (10.255.156.155) by BN1PR0301MB0724.namprd03.prod.outlook.com (10.160.78.143) with Microsoft SMTP Server (TLS) id 15.1.312.18; Tue, 3 Nov 2015 08:28:52 +0000 Received: from BL2FFO11FD053.protection.gbl (10.255.156.132) by CH1PR03CA010.outlook.office365.com (10.255.156.155) with Microsoft SMTP Server (TLS) id 15.1.312.18 via Frontend Transport; Tue, 3 Nov 2015 08:28:52 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) 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.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BL2FFO11FD053.mail.protection.outlook.com (10.173.161.181) with Microsoft SMTP Server (TLS) id 15.1.318.9 via Frontend Transport; Tue, 3 Nov 2015 08:28:52 +0000 Received: from shlinux2.ap.freescale.net (shlinux2.ap.freescale.net [10.192.224.44]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id tA38Sljv020608; Tue, 3 Nov 2015 01:28:49 -0700 From: Robin Gong To: , , Subject: [PATCH v3 1/2] watchdog: add WDIOC_SETPRETIMEOUT and WDIOC_GETPRETIMEOUT Date: Tue, 3 Nov 2015 16:26:45 +0800 Message-ID: <1446539206-8213-1-git-send-email-b38343@freescale.com> X-Mailer: git-send-email 1.9.1 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD053; 1:LCxQnK2a2TItuMtzv1A/ZFD/ILUkpIQZFqdMiLHeqeL6N9tFodZpyLdSLLdl9PxbqqXyDMUXARbnPnnvyFp2vFNyjJz/XXi9bUUpS7eJ5QFwiZn5Mcl5gOe8FctPOuqZjry/VdFRtnzW1tnAQNj4dM7ol3ITwUtPJHkVDbdEap1EC9APpc7AsngsXOkPR/iClZ7sxNQlXCeOy44T0xQ03xMi0EO9cnAw2+dEQUDEKkx9euU2tMT9JiQ7W5v8+ebJ8Kz9EDP1AxxkdRXUr/wM4Iq5dVvm7N/72GEnmmV3V5emyOTs60BxcQOT/QPF/2QMOcCd/IcTNGMfBV83MXulDq+KJa+Zkc+ZQXbGhsN2BFjCp0p9vjVcTHkjMoKjE33m X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(5001770100001)(36756003)(5008740100001)(189998001)(11100500001)(105606002)(229853001)(5001960100002)(33646002)(6806005)(50226001)(106466001)(2201001)(5007970100001)(81156007)(19580395003)(50986999)(97736004)(104016004)(77096005)(5001920100001)(87936001)(575784001)(85426001)(47776003)(5003940100001)(50466002)(92566002)(48376002)(69596002)(19580405001)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:BN1PR0301MB0724; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0724; 2:UzFUkuFcYXXBtp6ZUuP4D6F6IxUJA2AUcuv5wbJ/bauNK35wk8SpPHnLdPDpRwCiUVaPTg3ifZzxUSdj/k6kenPOIwmu2SqtOf7nVT5zUpZN49R+bkYQwttd0W6nf34gjpaMUU1A1yk/IAiSE5TJSKJ2UFQKH4ANSagt1ZuHYUo=; 3:xj4F60a9hV0Yn4BN8FbcWQzGlO1hGXtUI2OE6KRM77qVcJoXyUel4pm6jit61bx6FjtaRt6oEld1Y86oi7hC6xvhvaWVxAWWat5lsEzMV/vZeDOdys9+cpQAHSWJDMSEY3EdDcKXJjHgxM//MY8BjCwCfW0lxlJCrVmPT6yRpu7wCJbKz08doyY/5JgavuHv9+I+monu0Re5XWoew+IkYFtl4qIgPls4OIGdUa6nX2U=; 25:WcHM0M213MmSRR3P2c/+JrZNvP++MCqibUKnbMKTh4Az3UYzh4pu1q/vOpr+8KyrX8HqyTr69VIaP0ot0qSHeAJfttn0EabQ/Z+q0O/QeWt3HxjW4GjYItkMPsV0ZUq2fTv7/1zBS4g9GEFBTDGKzPXskGooX5hoX42I90g8udO1sR1Cy4vLSoYMC0ohIGwoDLomaLd4ZFjn7Evo8VGCd43aIM8cjjf4JLTNtDe1sIRSKsIgMowUJcqtthQkCFy63VXrIdgIdb2SRImCfmWAKw== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN1PR0301MB0724; X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0724; 20:FvKoDfxmRVcOeSx1kus/ilhbiAsRxO+1p8+tPUrixMteJnEabluouZYmiEaArCNEYgqjNXdDvJvOXiOS/Mw8mJtMylwr2Tpxjim7arJzM8mebwvZkWl3SqJJqDaYiL+zy7QWiHHb7drwugHpbAwOqd71CTbtZeWPdxv5uNDndWNrtFSx7cmREu8NLmnxwcxJaXmXDUJHsH1lic9mi1Zyu9xbu4wvyeJOS7rJh2Rr1QDwhMhbFGACpOl/bRCvJeqFcSgfST3epuI34lVeHgrgZqUDl9a28k0bNHEuNt1zHF+l1e4nUC1XPSmIsiPdAGoCg/Fu5Tof7hdTgh2JMYaxQgP9fjGxWJQyFpb2z3P1XKM=; 4:Rd7tizOekGp4oO2Zpyw7qaIgKKNa6myK+A7cRnWPN8BocOdZf5/iDdIsdYJL4Z9O3+m2f1fwlNeUH6zoBWJa8whkqtFsVsUJILyFvFwT0Kc4I06f8xGa3YseI+HY9UTNcNk/LXAGsZV4pLdhjAZBvNRcZdC79OS/FAMFLGtD5ejXCo3IK20SJpiavaCrHd8tpY734zR/R6YPqzEiYLoNhzWVKvQpXBnPiQlp37XNKigth6cOy6VIk8Y1YBFX10JNyFNdvvST3VRaJS958/qNU70S8r0PcJkzIGLJymC2yxgt4hTF+pzRvDIgcOoitHvZR9WV4a+S08J1OdN/tkvmVUn1A/ZrjN2cJgMh/Jr+EyxBspbnLxUEvpYZ1+MdfRQ9 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(520078)(5005006)(10201501046)(3002001); SRVR:BN1PR0301MB0724; BCL:0; PCL:0; RULEID:; SRVR:BN1PR0301MB0724; X-Forefront-PRVS: 0749DC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G4wX02wKuBK/cdzf2qiMuJ2KnGCfVY+dC36AHaoyJRR1+/qjC+9rdq?= =?us-ascii?Q?6gnLUKnnkJiBENtrnz8QnFn8M+kE+ahAw6lZXxM1qS2MHYDPdyG7ZB/iolPz?= =?us-ascii?Q?g2g/tAFHI2qSgemc8duObuci+iipQodL76YMvw5apTVbkF0mo95CIHwxXBN8?= =?us-ascii?Q?VIblkdmjfuwVXAU8KT2DSvf9E5vidUv9Qzd0qRiTUEzV6zjX/WnHGhYFaT4x?= =?us-ascii?Q?NQs3SQ7YnLLf7kC2Ulx6N7nPED2aB?= X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0724; 5:84awPVaKhsmxog9SMg2Jb2krZllonUQ6BKMd0ak+h8uDSVMHKCKGAqKE2TwsHgn9e49Iinc73a80UYAj5Q5SIh6ysVw1S4xXH0czuU0eMGJEL6+AIkMc304Zr75oN0wbSUL0YI6XzKvAUPX6g80ugw==; 24:FMeZRz+IG6Ht0Tr7pbw3RqCzgLOsflsB9LrhOnGCrsoo2zZBAGeCFwTDxrXU9YaezFC4o8+mkbzPzJ+w3hsY2K/ecOm4oSvFqTKQ9u0BKhc=; 20:VcHo8vkvkwojb9hqOvN5TXaMdO4lRetz9cig1YNrZ2IIBqQQ0MOoGsFS7wwHvMEUw4iZ/ll8tjoa3wizgOH8Pw== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2015 08:28:52.5096 (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.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN1PR0301MB0724 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151103_002916_503267_5CC639F4 X-CRM114-Status: GOOD ( 20.18 ) 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: inux-doc@vger.kernel.org, linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@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) {