blob: b346638833b0cd7bfbc97b022c8e0ae25fa88872 [file] [log] [blame]
Oren Weil3ceb3e62011-05-15 13:43:47 +03001/*
2 *
3 * Intel Management Engine Interface (Intel MEI) Linux driver
Tomas Winkler733ba912012-02-09 19:25:53 +02004 * Copyright (c) 2003-2012, Intel Corporation.
Oren Weil3ceb3e62011-05-15 13:43:47 +03005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 */
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/moduleparam.h>
19#include <linux/device.h>
Oren Weil3ceb3e62011-05-15 13:43:47 +030020#include <linux/sched.h>
Oren Weil9ce178e2011-09-07 09:03:09 +030021#include <linux/watchdog.h>
Oren Weil3ceb3e62011-05-15 13:43:47 +030022
Tomas Winkler4f3afe12012-05-09 16:38:59 +030023#include <linux/mei.h>
Oren Weil3ceb3e62011-05-15 13:43:47 +030024
Tomas Winkler47a73802012-12-25 19:06:03 +020025#include "mei_dev.h"
Tomas Winkler0edb23f2013-01-08 23:07:12 +020026#include "hbm.h"
Tomas Winkler90e0b5f2013-01-08 23:07:14 +020027#include "client.h"
Tomas Winkler47a73802012-12-25 19:06:03 +020028
Oren Weil3ceb3e62011-05-15 13:43:47 +030029static const u8 mei_start_wd_params[] = { 0x02, 0x12, 0x13, 0x10 };
30static const u8 mei_stop_wd_params[] = { 0x02, 0x02, 0x14, 0x10 };
31
Tomas Winkler70cd5332011-12-22 18:50:50 +020032/*
33 * AMT Watchdog Device
34 */
35#define INTEL_AMT_WATCHDOG_ID "INTCAMT"
36
Oren Weil3ceb3e62011-05-15 13:43:47 +030037/* UUIDs for AMT F/W clients */
38const uuid_le mei_wd_guid = UUID_LE(0x05B79A6F, 0x4628, 0x4D7F, 0x89,
39 0x9D, 0xA9, 0x15, 0x14, 0xCB,
40 0x32, 0xAB);
41
Tomas Winkler5192dda2012-03-19 17:58:43 +020042static void mei_wd_set_start_timeout(struct mei_device *dev, u16 timeout)
Oren Weil3ceb3e62011-05-15 13:43:47 +030043{
Tomas Winkler2bf94cab2014-09-29 16:31:42 +030044 dev_dbg(dev->dev, "wd: set timeout=%d.\n", timeout);
Tomas Winkler248ffdf2012-08-16 19:39:42 +030045 memcpy(dev->wd_data, mei_start_wd_params, MEI_WD_HDR_SIZE);
46 memcpy(dev->wd_data + MEI_WD_HDR_SIZE, &timeout, sizeof(u16));
Oren Weil3ceb3e62011-05-15 13:43:47 +030047}
48
49/**
Tomas Winkler7cb1ba92012-07-04 19:24:51 +030050 * mei_wd_host_init - connect to the watchdog client
Oren Weil3ceb3e62011-05-15 13:43:47 +030051 *
52 * @dev: the device structure
Alexander Usyskind49ed642015-05-04 09:43:54 +030053 * @me_cl: me client
Masanari Iida393b1482013-04-05 01:05:05 +090054 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +030055 * Return: -ENOTTY if wd client cannot be found
Tomas Winkler9487eb02012-04-03 23:34:58 +030056 * -EIO if write has failed
Tomas Winkler7cb1ba92012-07-04 19:24:51 +030057 * 0 on success
Oren Weil3ceb3e62011-05-15 13:43:47 +030058 */
Alexander Usyskind49ed642015-05-04 09:43:54 +030059int mei_wd_host_init(struct mei_device *dev, struct mei_me_client *me_cl)
Oren Weil3ceb3e62011-05-15 13:43:47 +030060{
Tomas Winkler781d0d82013-01-08 23:07:22 +020061 struct mei_cl *cl = &dev->wd_cl;
Tomas Winkler781d0d82013-01-08 23:07:22 +020062 int ret;
Oren Weil3ceb3e62011-05-15 13:43:47 +030063
Tomas Winkler781d0d82013-01-08 23:07:22 +020064 mei_cl_init(cl, dev);
65
Tomas Winkler248ffdf2012-08-16 19:39:42 +030066 dev->wd_timeout = MEI_WD_DEFAULT_TIMEOUT;
Tomas Winklerc216fde2012-08-16 19:39:43 +030067 dev->wd_state = MEI_WD_IDLE;
Oren Weil3ceb3e62011-05-15 13:43:47 +030068
Tomas Winkler781d0d82013-01-08 23:07:22 +020069 ret = mei_cl_link(cl, MEI_WD_HOST_CLIENT_ID);
Tomas Winkler781d0d82013-01-08 23:07:22 +020070 if (ret < 0) {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +030071 dev_info(dev->dev, "wd: failed link client\n");
Tomas Winkler50f67a02013-10-21 22:05:39 +030072 return ret;
Tomas Winkler781d0d82013-01-08 23:07:22 +020073 }
74
Alexander Usyskind49ed642015-05-04 09:43:54 +030075 ret = mei_cl_connect(cl, me_cl, NULL);
Tomas Winkler64092852014-02-17 15:13:21 +020076 if (ret) {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +030077 dev_err(dev->dev, "wd: failed to connect = %d\n", ret);
Tomas Winkler64092852014-02-17 15:13:21 +020078 mei_cl_unlink(cl);
79 return ret;
80 }
81
82 ret = mei_watchdog_register(dev);
83 if (ret) {
84 mei_cl_disconnect(cl);
85 mei_cl_unlink(cl);
86 }
87 return ret;
Oren Weil3ceb3e62011-05-15 13:43:47 +030088}
89
90/**
91 * mei_wd_send - sends watch dog message to fw.
92 *
93 * @dev: the device structure
94 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +030095 * Return: 0 if success,
Oren Weil3ceb3e62011-05-15 13:43:47 +030096 * -EIO when message send fails
97 * -EINVAL when invalid message is to be sent
Tomas Winklerb6d81fd2014-02-19 17:35:50 +020098 * -ENODEV on flow control failure
Oren Weil3ceb3e62011-05-15 13:43:47 +030099 */
100int mei_wd_send(struct mei_device *dev)
101{
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200102 struct mei_cl *cl = &dev->wd_cl;
Tomas Winklere46f1872012-12-25 19:06:10 +0200103 struct mei_msg_hdr hdr;
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200104 int ret;
Oren Weil3ceb3e62011-05-15 13:43:47 +0300105
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200106 hdr.host_addr = cl->host_client_id;
Alexander Usyskind49ed642015-05-04 09:43:54 +0300107 hdr.me_addr = mei_cl_me_id(cl);
Tomas Winklere46f1872012-12-25 19:06:10 +0200108 hdr.msg_complete = 1;
109 hdr.reserved = 0;
Tomas Winkler479327f2013-12-17 15:56:56 +0200110 hdr.internal = 0;
Oren Weil3ceb3e62011-05-15 13:43:47 +0300111
Tomas Winkler248ffdf2012-08-16 19:39:42 +0300112 if (!memcmp(dev->wd_data, mei_start_wd_params, MEI_WD_HDR_SIZE))
Tomas Winklere46f1872012-12-25 19:06:10 +0200113 hdr.length = MEI_WD_START_MSG_SIZE;
Tomas Winkler248ffdf2012-08-16 19:39:42 +0300114 else if (!memcmp(dev->wd_data, mei_stop_wd_params, MEI_WD_HDR_SIZE))
Tomas Winklere46f1872012-12-25 19:06:10 +0200115 hdr.length = MEI_WD_STOP_MSG_SIZE;
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200116 else {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300117 dev_err(dev->dev, "wd: invalid message is to be sent, aborting\n");
Oren Weil3ceb3e62011-05-15 13:43:47 +0300118 return -EINVAL;
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200119 }
Oren Weil3ceb3e62011-05-15 13:43:47 +0300120
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200121 ret = mei_write_message(dev, &hdr, dev->wd_data);
122 if (ret) {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300123 dev_err(dev->dev, "wd: write message failed\n");
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200124 return ret;
125 }
126
127 ret = mei_cl_flow_ctrl_reduce(cl);
128 if (ret) {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300129 dev_err(dev->dev, "wd: flow_ctrl_reduce failed.\n");
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200130 return ret;
131 }
132
133 return 0;
Oren Weil3ceb3e62011-05-15 13:43:47 +0300134}
135
Oren Weild8deca32011-09-07 09:03:17 +0300136/**
137 * mei_wd_stop - sends watchdog stop message to fw.
138 *
139 * @dev: the device structure
Oren Weild8deca32011-09-07 09:03:17 +0300140 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300141 * Return: 0 if success
Tomas Winkler58772552014-02-19 17:35:51 +0200142 * on error:
143 * -EIO when message send fails
Oren Weild8deca32011-09-07 09:03:17 +0300144 * -EINVAL when invalid message is to be sent
Tomas Winkler58772552014-02-19 17:35:51 +0200145 * -ETIME on message timeout
Oren Weild8deca32011-09-07 09:03:17 +0300146 */
Tomas Winklerc216fde2012-08-16 19:39:43 +0300147int mei_wd_stop(struct mei_device *dev)
Oren Weil3ceb3e62011-05-15 13:43:47 +0300148{
Tomas Winklerf3de9b62015-03-27 00:27:58 +0200149 struct mei_cl *cl = &dev->wd_cl;
Oren Weil3ceb3e62011-05-15 13:43:47 +0300150 int ret;
Oren Weil3ceb3e62011-05-15 13:43:47 +0300151
Tomas Winklerf3de9b62015-03-27 00:27:58 +0200152 if (!mei_cl_is_connected(cl) ||
Tomas Winklerc216fde2012-08-16 19:39:43 +0300153 dev->wd_state != MEI_WD_RUNNING)
Oren Weil3ceb3e62011-05-15 13:43:47 +0300154 return 0;
155
Tomas Winkler248ffdf2012-08-16 19:39:42 +0300156 memcpy(dev->wd_data, mei_stop_wd_params, MEI_WD_STOP_MSG_SIZE);
Tomas Winklerc216fde2012-08-16 19:39:43 +0300157
158 dev->wd_state = MEI_WD_STOPPING;
Oren Weil3ceb3e62011-05-15 13:43:47 +0300159
Tomas Winklerf3de9b62015-03-27 00:27:58 +0200160 ret = mei_cl_flow_ctrl_creds(cl);
Oren Weil3ceb3e62011-05-15 13:43:47 +0300161 if (ret < 0)
Tomas Winkler58772552014-02-19 17:35:51 +0200162 goto err;
Oren Weil3ceb3e62011-05-15 13:43:47 +0300163
Tomas Winkler6aae48f2014-02-19 17:35:47 +0200164 if (ret && mei_hbuf_acquire(dev)) {
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200165 ret = mei_wd_send(dev);
166 if (ret)
Tomas Winkler58772552014-02-19 17:35:51 +0200167 goto err;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300168 dev->wd_pending = false;
Oren Weil3ceb3e62011-05-15 13:43:47 +0300169 } else {
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300170 dev->wd_pending = true;
Oren Weil3ceb3e62011-05-15 13:43:47 +0300171 }
Tomas Winklerc216fde2012-08-16 19:39:43 +0300172
Oren Weil3ceb3e62011-05-15 13:43:47 +0300173 mutex_unlock(&dev->device_lock);
174
Tomas Winkler58772552014-02-19 17:35:51 +0200175 ret = wait_event_timeout(dev->wait_stop_wd,
176 dev->wd_state == MEI_WD_IDLE,
177 msecs_to_jiffies(MEI_WD_STOP_TIMEOUT));
Oren Weil3ceb3e62011-05-15 13:43:47 +0300178 mutex_lock(&dev->device_lock);
Tomas Winkler58772552014-02-19 17:35:51 +0200179 if (dev->wd_state != MEI_WD_IDLE) {
180 /* timeout */
181 ret = -ETIME;
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300182 dev_warn(dev->dev, "wd: stop failed to complete ret=%d\n", ret);
Tomas Winkler58772552014-02-19 17:35:51 +0200183 goto err;
Tomas Winklera534bb62011-06-13 16:39:31 +0300184 }
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300185 dev_dbg(dev->dev, "wd: stop completed after %u msec\n",
Tomas Winkler58772552014-02-19 17:35:51 +0200186 MEI_WD_STOP_TIMEOUT - jiffies_to_msecs(ret));
187 return 0;
188err:
Oren Weil3ceb3e62011-05-15 13:43:47 +0300189 return ret;
190}
191
Alexander Usyskin3908be62015-02-10 10:39:35 +0200192/**
Oren Weil4a3cafd2011-09-07 09:03:10 +0300193 * mei_wd_ops_start - wd start command from the watchdog core.
194 *
Alexander Usyskin3908be62015-02-10 10:39:35 +0200195 * @wd_dev: watchdog device struct
Oren Weil4a3cafd2011-09-07 09:03:10 +0300196 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300197 * Return: 0 if success, negative errno code for failure
Oren Weil4a3cafd2011-09-07 09:03:10 +0300198 */
199static int mei_wd_ops_start(struct watchdog_device *wd_dev)
200{
Oren Weil4a3cafd2011-09-07 09:03:10 +0300201 struct mei_device *dev;
Tomas Winklerf3de9b62015-03-27 00:27:58 +0200202 struct mei_cl *cl;
203 int err = -ENODEV;
Oren Weil4a3cafd2011-09-07 09:03:10 +0300204
Tomas Winkler09649a82012-08-16 19:39:44 +0300205 dev = watchdog_get_drvdata(wd_dev);
Oren Weil4a3cafd2011-09-07 09:03:10 +0300206 if (!dev)
207 return -ENODEV;
208
Tomas Winklerf3de9b62015-03-27 00:27:58 +0200209 cl = &dev->wd_cl;
210
Oren Weil4a3cafd2011-09-07 09:03:10 +0300211 mutex_lock(&dev->device_lock);
212
Tomas Winklerb210d752012-08-07 00:03:56 +0300213 if (dev->dev_state != MEI_DEV_ENABLED) {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300214 dev_dbg(dev->dev, "wd: dev_state != MEI_DEV_ENABLED dev_state = %s\n",
Tomas Winklerb210d752012-08-07 00:03:56 +0300215 mei_dev_state_str(dev->dev_state));
Oren Weil4a3cafd2011-09-07 09:03:10 +0300216 goto end_unlock;
217 }
218
Tomas Winklerf3de9b62015-03-27 00:27:58 +0200219 if (!mei_cl_is_connected(cl)) {
220 cl_dbg(dev, cl, "MEI Driver is not connected to Watchdog Client\n");
Oren Weil4a3cafd2011-09-07 09:03:10 +0300221 goto end_unlock;
222 }
223
Oren Weil55d33852011-09-07 09:03:12 +0300224 mei_wd_set_start_timeout(dev, dev->wd_timeout);
Oren Weil4a3cafd2011-09-07 09:03:10 +0300225
226 err = 0;
227end_unlock:
228 mutex_unlock(&dev->device_lock);
229 return err;
230}
231
Alexander Usyskin3908be62015-02-10 10:39:35 +0200232/**
Oren Weil4a3cafd2011-09-07 09:03:10 +0300233 * mei_wd_ops_stop - wd stop command from the watchdog core.
234 *
Alexander Usyskin3908be62015-02-10 10:39:35 +0200235 * @wd_dev: watchdog device struct
Oren Weil4a3cafd2011-09-07 09:03:10 +0300236 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300237 * Return: 0 if success, negative errno code for failure
Oren Weil4a3cafd2011-09-07 09:03:10 +0300238 */
239static int mei_wd_ops_stop(struct watchdog_device *wd_dev)
240{
241 struct mei_device *dev;
Oren Weil4a3cafd2011-09-07 09:03:10 +0300242
Tomas Winkler09649a82012-08-16 19:39:44 +0300243 dev = watchdog_get_drvdata(wd_dev);
Oren Weil4a3cafd2011-09-07 09:03:10 +0300244 if (!dev)
245 return -ENODEV;
246
247 mutex_lock(&dev->device_lock);
Tomas Winklerc216fde2012-08-16 19:39:43 +0300248 mei_wd_stop(dev);
Oren Weil4a3cafd2011-09-07 09:03:10 +0300249 mutex_unlock(&dev->device_lock);
250
251 return 0;
252}
253
Alexander Usyskin3908be62015-02-10 10:39:35 +0200254/**
Oren Weil8c4a59a2011-09-07 09:03:11 +0300255 * mei_wd_ops_ping - wd ping command from the watchdog core.
256 *
Alexander Usyskin3908be62015-02-10 10:39:35 +0200257 * @wd_dev: watchdog device struct
Oren Weil8c4a59a2011-09-07 09:03:11 +0300258 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300259 * Return: 0 if success, negative errno code for failure
Oren Weil8c4a59a2011-09-07 09:03:11 +0300260 */
261static int mei_wd_ops_ping(struct watchdog_device *wd_dev)
262{
Oren Weil8c4a59a2011-09-07 09:03:11 +0300263 struct mei_device *dev;
Tomas Winkler3d32cf02014-10-02 13:39:32 +0300264 struct mei_cl *cl;
Tomas Winkler6aae48f2014-02-19 17:35:47 +0200265 int ret;
Oren Weil8c4a59a2011-09-07 09:03:11 +0300266
Tomas Winkler09649a82012-08-16 19:39:44 +0300267 dev = watchdog_get_drvdata(wd_dev);
Oren Weil8c4a59a2011-09-07 09:03:11 +0300268 if (!dev)
269 return -ENODEV;
270
Tomas Winkler3d32cf02014-10-02 13:39:32 +0300271 cl = &dev->wd_cl;
272
Oren Weil8c4a59a2011-09-07 09:03:11 +0300273 mutex_lock(&dev->device_lock);
274
Tomas Winklerf3de9b62015-03-27 00:27:58 +0200275 if (!mei_cl_is_connected(cl)) {
276 cl_err(dev, cl, "wd: not connected.\n");
Oren Weil8c4a59a2011-09-07 09:03:11 +0300277 ret = -ENODEV;
278 goto end;
279 }
280
Tomas Winklerc216fde2012-08-16 19:39:43 +0300281 dev->wd_state = MEI_WD_RUNNING;
282
Tomas Winkler3d32cf02014-10-02 13:39:32 +0300283 ret = mei_cl_flow_ctrl_creds(cl);
Tomas Winkler6aae48f2014-02-19 17:35:47 +0200284 if (ret < 0)
285 goto end;
Tomas Winkler3d32cf02014-10-02 13:39:32 +0300286
Oren Weil8c4a59a2011-09-07 09:03:11 +0300287 /* Check if we can send the ping to HW*/
Tomas Winkler6aae48f2014-02-19 17:35:47 +0200288 if (ret && mei_hbuf_acquire(dev)) {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300289 dev_dbg(dev->dev, "wd: sending ping\n");
Oren Weil8c4a59a2011-09-07 09:03:11 +0300290
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200291 ret = mei_wd_send(dev);
292 if (ret)
Oren Weil8c4a59a2011-09-07 09:03:11 +0300293 goto end;
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200294 dev->wd_pending = false;
Oren Weil8c4a59a2011-09-07 09:03:11 +0300295 } else {
296 dev->wd_pending = true;
297 }
298
299end:
300 mutex_unlock(&dev->device_lock);
301 return ret;
302}
303
Alexander Usyskin3908be62015-02-10 10:39:35 +0200304/**
Oren Weil55d33852011-09-07 09:03:12 +0300305 * mei_wd_ops_set_timeout - wd set timeout command from the watchdog core.
306 *
Alexander Usyskin3908be62015-02-10 10:39:35 +0200307 * @wd_dev: watchdog device struct
308 * @timeout: timeout value to set
Oren Weil55d33852011-09-07 09:03:12 +0300309 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300310 * Return: 0 if success, negative errno code for failure
Oren Weil55d33852011-09-07 09:03:12 +0300311 */
Tomas Winkler5f1e54e2013-04-13 23:41:25 +0300312static int mei_wd_ops_set_timeout(struct watchdog_device *wd_dev,
313 unsigned int timeout)
Oren Weil55d33852011-09-07 09:03:12 +0300314{
315 struct mei_device *dev;
Oren Weil55d33852011-09-07 09:03:12 +0300316
Tomas Winkler09649a82012-08-16 19:39:44 +0300317 dev = watchdog_get_drvdata(wd_dev);
Oren Weil55d33852011-09-07 09:03:12 +0300318 if (!dev)
319 return -ENODEV;
320
321 /* Check Timeout value */
Tomas Winkler248ffdf2012-08-16 19:39:42 +0300322 if (timeout < MEI_WD_MIN_TIMEOUT || timeout > MEI_WD_MAX_TIMEOUT)
Oren Weil55d33852011-09-07 09:03:12 +0300323 return -EINVAL;
324
325 mutex_lock(&dev->device_lock);
326
327 dev->wd_timeout = timeout;
Wim Van Sebroeck0197c1c2012-02-29 20:20:58 +0100328 wd_dev->timeout = timeout;
Oren Weil55d33852011-09-07 09:03:12 +0300329 mei_wd_set_start_timeout(dev, dev->wd_timeout);
330
331 mutex_unlock(&dev->device_lock);
332
333 return 0;
334}
335
336/*
Oren Weil4a3cafd2011-09-07 09:03:10 +0300337 * Watchdog Device structs
338 */
Tomas Winkler575c1e42011-10-23 18:30:39 +0200339static const struct watchdog_ops wd_ops = {
Oren Weil4a3cafd2011-09-07 09:03:10 +0300340 .owner = THIS_MODULE,
341 .start = mei_wd_ops_start,
342 .stop = mei_wd_ops_stop,
Oren Weil8c4a59a2011-09-07 09:03:11 +0300343 .ping = mei_wd_ops_ping,
Oren Weil55d33852011-09-07 09:03:12 +0300344 .set_timeout = mei_wd_ops_set_timeout,
Oren Weil4a3cafd2011-09-07 09:03:10 +0300345};
Tomas Winkler575c1e42011-10-23 18:30:39 +0200346static const struct watchdog_info wd_info = {
Oren Weil4a3cafd2011-09-07 09:03:10 +0300347 .identity = INTEL_AMT_WATCHDOG_ID,
Tomas Winklerc8df7292012-08-16 19:39:41 +0300348 .options = WDIOF_KEEPALIVEPING |
349 WDIOF_SETTIMEOUT |
350 WDIOF_ALARMONLY,
Oren Weil4a3cafd2011-09-07 09:03:10 +0300351};
352
Tomas Winkler68d923d2012-04-02 20:32:38 +0300353static struct watchdog_device amt_wd_dev = {
Oren Weil4a3cafd2011-09-07 09:03:10 +0300354 .info = &wd_info,
355 .ops = &wd_ops,
Tomas Winkler248ffdf2012-08-16 19:39:42 +0300356 .timeout = MEI_WD_DEFAULT_TIMEOUT,
357 .min_timeout = MEI_WD_MIN_TIMEOUT,
358 .max_timeout = MEI_WD_MAX_TIMEOUT,
Oren Weil4a3cafd2011-09-07 09:03:10 +0300359};
360
361
Tomas Winkler64092852014-02-17 15:13:21 +0200362int mei_watchdog_register(struct mei_device *dev)
Tomas Winkler70cd5332011-12-22 18:50:50 +0200363{
Tomas Winkler64092852014-02-17 15:13:21 +0200364
365 int ret;
366
Pratyush Anand65518812015-08-20 14:05:01 +0530367 amt_wd_dev.parent = dev->dev;
Tomas Winkler64092852014-02-17 15:13:21 +0200368 /* unlock to perserve correct locking order */
369 mutex_unlock(&dev->device_lock);
370 ret = watchdog_register_device(&amt_wd_dev);
371 mutex_lock(&dev->device_lock);
372 if (ret) {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300373 dev_err(dev->dev, "wd: unable to register watchdog device = %d.\n",
Tomas Winkler64092852014-02-17 15:13:21 +0200374 ret);
375 return ret;
Tomas Winkler70cd5332011-12-22 18:50:50 +0200376 }
Tomas Winkler09649a82012-08-16 19:39:44 +0300377
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300378 dev_dbg(dev->dev, "wd: successfully register watchdog interface.\n");
Tomas Winkler09649a82012-08-16 19:39:44 +0300379 watchdog_set_drvdata(&amt_wd_dev, dev);
Tomas Winkler64092852014-02-17 15:13:21 +0200380 return 0;
Tomas Winkler70cd5332011-12-22 18:50:50 +0200381}
382
383void mei_watchdog_unregister(struct mei_device *dev)
384{
Tomas Winklerd6921702012-12-16 13:23:17 +0200385 if (watchdog_get_drvdata(&amt_wd_dev) == NULL)
Tomas Winkler09649a82012-08-16 19:39:44 +0300386 return;
387
388 watchdog_set_drvdata(&amt_wd_dev, NULL);
389 watchdog_unregister_device(&amt_wd_dev);
Tomas Winkler70cd5332011-12-22 18:50:50 +0200390}
391