blob: 2725f865c3d6b814ef7b532069f42c6902572e8f [file] [log] [blame]
Oren Weil3ceb3e62011-05-15 13:43:47 +03001/*
2 *
3 * Intel Management Engine Interface (Intel MEI) Linux driver
Tomas Winkler733ba91c2012-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
Masanari Iida393b1482013-04-05 01:05:05 +090053 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +030054 * Return: -ENOTTY if wd client cannot be found
Tomas Winkler9487eb02012-04-03 23:34:58 +030055 * -EIO if write has failed
Tomas Winkler7cb1ba92012-07-04 19:24:51 +030056 * 0 on success
Oren Weil3ceb3e62011-05-15 13:43:47 +030057 */
Tomas Winkler9487eb02012-04-03 23:34:58 +030058int mei_wd_host_init(struct mei_device *dev)
Oren Weil3ceb3e62011-05-15 13:43:47 +030059{
Tomas Winkler781d0d82013-01-08 23:07:22 +020060 struct mei_cl *cl = &dev->wd_cl;
Tomas Winklerd3208322014-08-24 12:08:55 +030061 struct mei_me_client *me_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
Oren Weil3ceb3e62011-05-15 13:43:47 +030069
Tomas Winkler781d0d82013-01-08 23:07:22 +020070 /* check for valid client id */
Tomas Winklerd3208322014-08-24 12:08:55 +030071 me_cl = mei_me_cl_by_uuid(dev, &mei_wd_guid);
72 if (!me_cl) {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +030073 dev_info(dev->dev, "wd: failed to find the client\n");
Alexander Usyskin7ca96aa2014-02-19 17:35:49 +020074 return -ENOTTY;
Oren Weil3ceb3e62011-05-15 13:43:47 +030075 }
Oren Weil617aa392011-09-07 09:03:07 +030076
Tomas Winklerd3208322014-08-24 12:08:55 +030077 cl->me_client_id = me_cl->client_id;
Tomas Winklerd880f322014-08-21 14:29:15 +030078 cl->cl_uuid = me_cl->props.protocol_name;
Tomas Winkler79563db2015-01-11 00:07:16 +020079 mei_me_cl_put(me_cl);
Tomas Winkler781d0d82013-01-08 23:07:22 +020080
81 ret = mei_cl_link(cl, MEI_WD_HOST_CLIENT_ID);
82
83 if (ret < 0) {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +030084 dev_info(dev->dev, "wd: failed link client\n");
Tomas Winkler50f67a02013-10-21 22:05:39 +030085 return ret;
Tomas Winkler781d0d82013-01-08 23:07:22 +020086 }
87
Tomas Winkler64092852014-02-17 15:13:21 +020088 ret = mei_cl_connect(cl, NULL);
Tomas Winkler9487eb02012-04-03 23:34:58 +030089
Tomas Winkler64092852014-02-17 15:13:21 +020090 if (ret) {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +030091 dev_err(dev->dev, "wd: failed to connect = %d\n", ret);
Tomas Winkler64092852014-02-17 15:13:21 +020092 mei_cl_unlink(cl);
93 return ret;
94 }
95
96 ret = mei_watchdog_register(dev);
97 if (ret) {
98 mei_cl_disconnect(cl);
99 mei_cl_unlink(cl);
100 }
101 return ret;
Oren Weil3ceb3e62011-05-15 13:43:47 +0300102}
103
104/**
105 * mei_wd_send - sends watch dog message to fw.
106 *
107 * @dev: the device structure
108 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300109 * Return: 0 if success,
Oren Weil3ceb3e62011-05-15 13:43:47 +0300110 * -EIO when message send fails
111 * -EINVAL when invalid message is to be sent
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200112 * -ENODEV on flow control failure
Oren Weil3ceb3e62011-05-15 13:43:47 +0300113 */
114int mei_wd_send(struct mei_device *dev)
115{
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200116 struct mei_cl *cl = &dev->wd_cl;
Tomas Winklere46f1872012-12-25 19:06:10 +0200117 struct mei_msg_hdr hdr;
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200118 int ret;
Oren Weil3ceb3e62011-05-15 13:43:47 +0300119
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200120 hdr.host_addr = cl->host_client_id;
121 hdr.me_addr = cl->me_client_id;
Tomas Winklere46f1872012-12-25 19:06:10 +0200122 hdr.msg_complete = 1;
123 hdr.reserved = 0;
Tomas Winkler479327f2013-12-17 15:56:56 +0200124 hdr.internal = 0;
Oren Weil3ceb3e62011-05-15 13:43:47 +0300125
Tomas Winkler248ffdf2012-08-16 19:39:42 +0300126 if (!memcmp(dev->wd_data, mei_start_wd_params, MEI_WD_HDR_SIZE))
Tomas Winklere46f1872012-12-25 19:06:10 +0200127 hdr.length = MEI_WD_START_MSG_SIZE;
Tomas Winkler248ffdf2012-08-16 19:39:42 +0300128 else if (!memcmp(dev->wd_data, mei_stop_wd_params, MEI_WD_HDR_SIZE))
Tomas Winklere46f1872012-12-25 19:06:10 +0200129 hdr.length = MEI_WD_STOP_MSG_SIZE;
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200130 else {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300131 dev_err(dev->dev, "wd: invalid message is to be sent, aborting\n");
Oren Weil3ceb3e62011-05-15 13:43:47 +0300132 return -EINVAL;
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200133 }
Oren Weil3ceb3e62011-05-15 13:43:47 +0300134
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200135 ret = mei_write_message(dev, &hdr, dev->wd_data);
136 if (ret) {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300137 dev_err(dev->dev, "wd: write message failed\n");
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200138 return ret;
139 }
140
141 ret = mei_cl_flow_ctrl_reduce(cl);
142 if (ret) {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300143 dev_err(dev->dev, "wd: flow_ctrl_reduce failed.\n");
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200144 return ret;
145 }
146
147 return 0;
Oren Weil3ceb3e62011-05-15 13:43:47 +0300148}
149
Oren Weild8deca32011-09-07 09:03:17 +0300150/**
151 * mei_wd_stop - sends watchdog stop message to fw.
152 *
153 * @dev: the device structure
Oren Weild8deca32011-09-07 09:03:17 +0300154 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300155 * Return: 0 if success
Tomas Winkler58772552014-02-19 17:35:51 +0200156 * on error:
157 * -EIO when message send fails
Oren Weild8deca32011-09-07 09:03:17 +0300158 * -EINVAL when invalid message is to be sent
Tomas Winkler58772552014-02-19 17:35:51 +0200159 * -ETIME on message timeout
Oren Weild8deca32011-09-07 09:03:17 +0300160 */
Tomas Winklerc216fde2012-08-16 19:39:43 +0300161int mei_wd_stop(struct mei_device *dev)
Oren Weil3ceb3e62011-05-15 13:43:47 +0300162{
Tomas Winklerf3de9b62015-03-27 00:27:58 +0200163 struct mei_cl *cl = &dev->wd_cl;
Oren Weil3ceb3e62011-05-15 13:43:47 +0300164 int ret;
Oren Weil3ceb3e62011-05-15 13:43:47 +0300165
Tomas Winklerf3de9b62015-03-27 00:27:58 +0200166 if (!mei_cl_is_connected(cl) ||
Tomas Winklerc216fde2012-08-16 19:39:43 +0300167 dev->wd_state != MEI_WD_RUNNING)
Oren Weil3ceb3e62011-05-15 13:43:47 +0300168 return 0;
169
Tomas Winkler248ffdf2012-08-16 19:39:42 +0300170 memcpy(dev->wd_data, mei_stop_wd_params, MEI_WD_STOP_MSG_SIZE);
Tomas Winklerc216fde2012-08-16 19:39:43 +0300171
172 dev->wd_state = MEI_WD_STOPPING;
Oren Weil3ceb3e62011-05-15 13:43:47 +0300173
Tomas Winklerf3de9b62015-03-27 00:27:58 +0200174 ret = mei_cl_flow_ctrl_creds(cl);
Oren Weil3ceb3e62011-05-15 13:43:47 +0300175 if (ret < 0)
Tomas Winkler58772552014-02-19 17:35:51 +0200176 goto err;
Oren Weil3ceb3e62011-05-15 13:43:47 +0300177
Tomas Winkler6aae48f2014-02-19 17:35:47 +0200178 if (ret && mei_hbuf_acquire(dev)) {
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200179 ret = mei_wd_send(dev);
180 if (ret)
Tomas Winkler58772552014-02-19 17:35:51 +0200181 goto err;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300182 dev->wd_pending = false;
Oren Weil3ceb3e62011-05-15 13:43:47 +0300183 } else {
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300184 dev->wd_pending = true;
Oren Weil3ceb3e62011-05-15 13:43:47 +0300185 }
Tomas Winklerc216fde2012-08-16 19:39:43 +0300186
Oren Weil3ceb3e62011-05-15 13:43:47 +0300187 mutex_unlock(&dev->device_lock);
188
Tomas Winkler58772552014-02-19 17:35:51 +0200189 ret = wait_event_timeout(dev->wait_stop_wd,
190 dev->wd_state == MEI_WD_IDLE,
191 msecs_to_jiffies(MEI_WD_STOP_TIMEOUT));
Oren Weil3ceb3e62011-05-15 13:43:47 +0300192 mutex_lock(&dev->device_lock);
Tomas Winkler58772552014-02-19 17:35:51 +0200193 if (dev->wd_state != MEI_WD_IDLE) {
194 /* timeout */
195 ret = -ETIME;
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300196 dev_warn(dev->dev, "wd: stop failed to complete ret=%d\n", ret);
Tomas Winkler58772552014-02-19 17:35:51 +0200197 goto err;
Tomas Winklera534bb62011-06-13 16:39:31 +0300198 }
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300199 dev_dbg(dev->dev, "wd: stop completed after %u msec\n",
Tomas Winkler58772552014-02-19 17:35:51 +0200200 MEI_WD_STOP_TIMEOUT - jiffies_to_msecs(ret));
201 return 0;
202err:
Oren Weil3ceb3e62011-05-15 13:43:47 +0300203 return ret;
204}
205
Alexander Usyskin3908be62015-02-10 10:39:35 +0200206/**
Oren Weil4a3cafd2011-09-07 09:03:10 +0300207 * mei_wd_ops_start - wd start command from the watchdog core.
208 *
Alexander Usyskin3908be62015-02-10 10:39:35 +0200209 * @wd_dev: watchdog device struct
Oren Weil4a3cafd2011-09-07 09:03:10 +0300210 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300211 * Return: 0 if success, negative errno code for failure
Oren Weil4a3cafd2011-09-07 09:03:10 +0300212 */
213static int mei_wd_ops_start(struct watchdog_device *wd_dev)
214{
Oren Weil4a3cafd2011-09-07 09:03:10 +0300215 struct mei_device *dev;
Tomas Winklerf3de9b62015-03-27 00:27:58 +0200216 struct mei_cl *cl;
217 int err = -ENODEV;
Oren Weil4a3cafd2011-09-07 09:03:10 +0300218
Tomas Winkler09649a82012-08-16 19:39:44 +0300219 dev = watchdog_get_drvdata(wd_dev);
Oren Weil4a3cafd2011-09-07 09:03:10 +0300220 if (!dev)
221 return -ENODEV;
222
Tomas Winklerf3de9b62015-03-27 00:27:58 +0200223 cl = &dev->wd_cl;
224
Oren Weil4a3cafd2011-09-07 09:03:10 +0300225 mutex_lock(&dev->device_lock);
226
Tomas Winklerb210d752012-08-07 00:03:56 +0300227 if (dev->dev_state != MEI_DEV_ENABLED) {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300228 dev_dbg(dev->dev, "wd: dev_state != MEI_DEV_ENABLED dev_state = %s\n",
Tomas Winklerb210d752012-08-07 00:03:56 +0300229 mei_dev_state_str(dev->dev_state));
Oren Weil4a3cafd2011-09-07 09:03:10 +0300230 goto end_unlock;
231 }
232
Tomas Winklerf3de9b62015-03-27 00:27:58 +0200233 if (!mei_cl_is_connected(cl)) {
234 cl_dbg(dev, cl, "MEI Driver is not connected to Watchdog Client\n");
Oren Weil4a3cafd2011-09-07 09:03:10 +0300235 goto end_unlock;
236 }
237
Oren Weil55d33852011-09-07 09:03:12 +0300238 mei_wd_set_start_timeout(dev, dev->wd_timeout);
Oren Weil4a3cafd2011-09-07 09:03:10 +0300239
240 err = 0;
241end_unlock:
242 mutex_unlock(&dev->device_lock);
243 return err;
244}
245
Alexander Usyskin3908be62015-02-10 10:39:35 +0200246/**
Oren Weil4a3cafd2011-09-07 09:03:10 +0300247 * mei_wd_ops_stop - wd stop command from the watchdog core.
248 *
Alexander Usyskin3908be62015-02-10 10:39:35 +0200249 * @wd_dev: watchdog device struct
Oren Weil4a3cafd2011-09-07 09:03:10 +0300250 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300251 * Return: 0 if success, negative errno code for failure
Oren Weil4a3cafd2011-09-07 09:03:10 +0300252 */
253static int mei_wd_ops_stop(struct watchdog_device *wd_dev)
254{
255 struct mei_device *dev;
Oren Weil4a3cafd2011-09-07 09:03:10 +0300256
Tomas Winkler09649a82012-08-16 19:39:44 +0300257 dev = watchdog_get_drvdata(wd_dev);
Oren Weil4a3cafd2011-09-07 09:03:10 +0300258 if (!dev)
259 return -ENODEV;
260
261 mutex_lock(&dev->device_lock);
Tomas Winklerc216fde2012-08-16 19:39:43 +0300262 mei_wd_stop(dev);
Oren Weil4a3cafd2011-09-07 09:03:10 +0300263 mutex_unlock(&dev->device_lock);
264
265 return 0;
266}
267
Alexander Usyskin3908be62015-02-10 10:39:35 +0200268/**
Oren Weil8c4a59a2011-09-07 09:03:11 +0300269 * mei_wd_ops_ping - wd ping command from the watchdog core.
270 *
Alexander Usyskin3908be62015-02-10 10:39:35 +0200271 * @wd_dev: watchdog device struct
Oren Weil8c4a59a2011-09-07 09:03:11 +0300272 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300273 * Return: 0 if success, negative errno code for failure
Oren Weil8c4a59a2011-09-07 09:03:11 +0300274 */
275static int mei_wd_ops_ping(struct watchdog_device *wd_dev)
276{
Oren Weil8c4a59a2011-09-07 09:03:11 +0300277 struct mei_device *dev;
Tomas Winkler3d32cf02014-10-02 13:39:32 +0300278 struct mei_cl *cl;
Tomas Winkler6aae48f2014-02-19 17:35:47 +0200279 int ret;
Oren Weil8c4a59a2011-09-07 09:03:11 +0300280
Tomas Winkler09649a82012-08-16 19:39:44 +0300281 dev = watchdog_get_drvdata(wd_dev);
Oren Weil8c4a59a2011-09-07 09:03:11 +0300282 if (!dev)
283 return -ENODEV;
284
Tomas Winkler3d32cf02014-10-02 13:39:32 +0300285 cl = &dev->wd_cl;
286
Oren Weil8c4a59a2011-09-07 09:03:11 +0300287 mutex_lock(&dev->device_lock);
288
Tomas Winklerf3de9b62015-03-27 00:27:58 +0200289 if (!mei_cl_is_connected(cl)) {
290 cl_err(dev, cl, "wd: not connected.\n");
Oren Weil8c4a59a2011-09-07 09:03:11 +0300291 ret = -ENODEV;
292 goto end;
293 }
294
Tomas Winklerc216fde2012-08-16 19:39:43 +0300295 dev->wd_state = MEI_WD_RUNNING;
296
Tomas Winkler3d32cf02014-10-02 13:39:32 +0300297 ret = mei_cl_flow_ctrl_creds(cl);
Tomas Winkler6aae48f2014-02-19 17:35:47 +0200298 if (ret < 0)
299 goto end;
Tomas Winkler3d32cf02014-10-02 13:39:32 +0300300
Oren Weil8c4a59a2011-09-07 09:03:11 +0300301 /* Check if we can send the ping to HW*/
Tomas Winkler6aae48f2014-02-19 17:35:47 +0200302 if (ret && mei_hbuf_acquire(dev)) {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300303 dev_dbg(dev->dev, "wd: sending ping\n");
Oren Weil8c4a59a2011-09-07 09:03:11 +0300304
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200305 ret = mei_wd_send(dev);
306 if (ret)
Oren Weil8c4a59a2011-09-07 09:03:11 +0300307 goto end;
Tomas Winklerb6d81fd2014-02-19 17:35:50 +0200308 dev->wd_pending = false;
Oren Weil8c4a59a2011-09-07 09:03:11 +0300309 } else {
310 dev->wd_pending = true;
311 }
312
313end:
314 mutex_unlock(&dev->device_lock);
315 return ret;
316}
317
Alexander Usyskin3908be62015-02-10 10:39:35 +0200318/**
Oren Weil55d33852011-09-07 09:03:12 +0300319 * mei_wd_ops_set_timeout - wd set timeout command from the watchdog core.
320 *
Alexander Usyskin3908be62015-02-10 10:39:35 +0200321 * @wd_dev: watchdog device struct
322 * @timeout: timeout value to set
Oren Weil55d33852011-09-07 09:03:12 +0300323 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300324 * Return: 0 if success, negative errno code for failure
Oren Weil55d33852011-09-07 09:03:12 +0300325 */
Tomas Winkler5f1e54e2013-04-13 23:41:25 +0300326static int mei_wd_ops_set_timeout(struct watchdog_device *wd_dev,
327 unsigned int timeout)
Oren Weil55d33852011-09-07 09:03:12 +0300328{
329 struct mei_device *dev;
Oren Weil55d33852011-09-07 09:03:12 +0300330
Tomas Winkler09649a82012-08-16 19:39:44 +0300331 dev = watchdog_get_drvdata(wd_dev);
Oren Weil55d33852011-09-07 09:03:12 +0300332 if (!dev)
333 return -ENODEV;
334
335 /* Check Timeout value */
Tomas Winkler248ffdf2012-08-16 19:39:42 +0300336 if (timeout < MEI_WD_MIN_TIMEOUT || timeout > MEI_WD_MAX_TIMEOUT)
Oren Weil55d33852011-09-07 09:03:12 +0300337 return -EINVAL;
338
339 mutex_lock(&dev->device_lock);
340
341 dev->wd_timeout = timeout;
Wim Van Sebroeck0197c1c2012-02-29 20:20:58 +0100342 wd_dev->timeout = timeout;
Oren Weil55d33852011-09-07 09:03:12 +0300343 mei_wd_set_start_timeout(dev, dev->wd_timeout);
344
345 mutex_unlock(&dev->device_lock);
346
347 return 0;
348}
349
350/*
Oren Weil4a3cafd2011-09-07 09:03:10 +0300351 * Watchdog Device structs
352 */
Tomas Winkler575c1e42011-10-23 18:30:39 +0200353static const struct watchdog_ops wd_ops = {
Oren Weil4a3cafd2011-09-07 09:03:10 +0300354 .owner = THIS_MODULE,
355 .start = mei_wd_ops_start,
356 .stop = mei_wd_ops_stop,
Oren Weil8c4a59a2011-09-07 09:03:11 +0300357 .ping = mei_wd_ops_ping,
Oren Weil55d33852011-09-07 09:03:12 +0300358 .set_timeout = mei_wd_ops_set_timeout,
Oren Weil4a3cafd2011-09-07 09:03:10 +0300359};
Tomas Winkler575c1e42011-10-23 18:30:39 +0200360static const struct watchdog_info wd_info = {
Oren Weil4a3cafd2011-09-07 09:03:10 +0300361 .identity = INTEL_AMT_WATCHDOG_ID,
Tomas Winklerc8df7292012-08-16 19:39:41 +0300362 .options = WDIOF_KEEPALIVEPING |
363 WDIOF_SETTIMEOUT |
364 WDIOF_ALARMONLY,
Oren Weil4a3cafd2011-09-07 09:03:10 +0300365};
366
Tomas Winkler68d923d2012-04-02 20:32:38 +0300367static struct watchdog_device amt_wd_dev = {
Oren Weil4a3cafd2011-09-07 09:03:10 +0300368 .info = &wd_info,
369 .ops = &wd_ops,
Tomas Winkler248ffdf2012-08-16 19:39:42 +0300370 .timeout = MEI_WD_DEFAULT_TIMEOUT,
371 .min_timeout = MEI_WD_MIN_TIMEOUT,
372 .max_timeout = MEI_WD_MAX_TIMEOUT,
Oren Weil4a3cafd2011-09-07 09:03:10 +0300373};
374
375
Tomas Winkler64092852014-02-17 15:13:21 +0200376int mei_watchdog_register(struct mei_device *dev)
Tomas Winkler70cd5332011-12-22 18:50:50 +0200377{
Tomas Winkler64092852014-02-17 15:13:21 +0200378
379 int ret;
380
381 /* unlock to perserve correct locking order */
382 mutex_unlock(&dev->device_lock);
383 ret = watchdog_register_device(&amt_wd_dev);
384 mutex_lock(&dev->device_lock);
385 if (ret) {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300386 dev_err(dev->dev, "wd: unable to register watchdog device = %d.\n",
Tomas Winkler64092852014-02-17 15:13:21 +0200387 ret);
388 return ret;
Tomas Winkler70cd5332011-12-22 18:50:50 +0200389 }
Tomas Winkler09649a82012-08-16 19:39:44 +0300390
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300391 dev_dbg(dev->dev, "wd: successfully register watchdog interface.\n");
Tomas Winkler09649a82012-08-16 19:39:44 +0300392 watchdog_set_drvdata(&amt_wd_dev, dev);
Tomas Winkler64092852014-02-17 15:13:21 +0200393 return 0;
Tomas Winkler70cd5332011-12-22 18:50:50 +0200394}
395
396void mei_watchdog_unregister(struct mei_device *dev)
397{
Tomas Winklerd6921702012-12-16 13:23:17 +0200398 if (watchdog_get_drvdata(&amt_wd_dev) == NULL)
Tomas Winkler09649a82012-08-16 19:39:44 +0300399 return;
400
401 watchdog_set_drvdata(&amt_wd_dev, NULL);
402 watchdog_unregister_device(&amt_wd_dev);
Tomas Winkler70cd5332011-12-22 18:50:50 +0200403}
404