staging: mei: registering the MEI driver with the kernel watchdog core interface
[deliverable/linux.git] / drivers / staging / mei / wd.c
CommitLineData
3ceb3e66
OW
1/*
2 *
3 * Intel Management Engine Interface (Intel MEI) Linux driver
4 * Copyright (c) 2003-2011, Intel Corporation.
5 *
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>
20#include <linux/pci.h>
21#include <linux/sched.h>
9ce178e5 22#include <linux/watchdog.h>
3ceb3e66
OW
23
24#include "mei_dev.h"
25#include "hw.h"
26#include "interface.h"
27#include "mei.h"
28
9ce178e5
OW
29/*
30 * Watchdog Device structs
31 */
32const struct watchdog_info wd_info = {
33 .identity = INTEL_AMT_WATCHDOG_ID,
34};
35
36struct watchdog_device amt_wd_dev = {
37 .info = &wd_info,
38 .timeout = AMT_WD_DEFAULT_TIMEOUT,
39 .min_timeout = AMT_WD_MIN_TIMEOUT,
40 .max_timeout = AMT_WD_MAX_TIMEOUT,
41};
42
43
3ceb3e66
OW
44/*
45 * MEI Watchdog Module Parameters
46 */
9ce178e5 47static u16 watchdog_timeout = AMT_WD_DEFAULT_TIMEOUT;
3ceb3e66
OW
48module_param(watchdog_timeout, ushort, 0);
49MODULE_PARM_DESC(watchdog_timeout,
50 "Intel(R) AMT Watchdog timeout value in seconds. (default="
9ce178e5 51 __MODULE_STRING(AMT_WD_DEFAULT_TIMEOUT)
3ceb3e66
OW
52 ", disable=0)");
53
54static const u8 mei_start_wd_params[] = { 0x02, 0x12, 0x13, 0x10 };
55static const u8 mei_stop_wd_params[] = { 0x02, 0x02, 0x14, 0x10 };
56
57const u8 mei_wd_state_independence_msg[3][4] = {
58 {0x05, 0x02, 0x51, 0x10},
59 {0x05, 0x02, 0x52, 0x10},
60 {0x07, 0x02, 0x01, 0x10}
61};
62
63/* UUIDs for AMT F/W clients */
64const uuid_le mei_wd_guid = UUID_LE(0x05B79A6F, 0x4628, 0x4D7F, 0x89,
65 0x9D, 0xA9, 0x15, 0x14, 0xCB,
66 0x32, 0xAB);
67
68
69void mei_wd_start_setup(struct mei_device *dev)
70{
71 dev_dbg(&dev->pdev->dev, "dev->wd_timeout=%d.\n", dev->wd_timeout);
72 memcpy(dev->wd_data, mei_start_wd_params, MEI_WD_PARAMS_SIZE);
73 memcpy(dev->wd_data + MEI_WD_PARAMS_SIZE,
74 &dev->wd_timeout, sizeof(u16));
75}
76
77/**
78 * host_init_wd - mei initialization wd.
79 *
80 * @dev: the device structure
81 */
617aa396 82bool mei_wd_host_init(struct mei_device *dev)
3ceb3e66 83{
617aa396
OW
84 bool ret = false;
85
c95efb74 86 mei_cl_init(&dev->wd_cl, dev);
3ceb3e66
OW
87
88 /* look for WD client and connect to it */
89 dev->wd_cl.state = MEI_FILE_DISCONNECTED;
90 dev->wd_timeout = watchdog_timeout;
91
92 if (dev->wd_timeout > 0) {
93 mei_wd_start_setup(dev);
94 /* find ME WD client */
95 mei_find_me_client_update_filext(dev, &dev->wd_cl,
96 &mei_wd_guid, MEI_WD_HOST_CLIENT_ID);
97
98 dev_dbg(&dev->pdev->dev, "check wd_cl\n");
99 if (MEI_FILE_CONNECTING == dev->wd_cl.state) {
100 if (!mei_connect(dev, &dev->wd_cl)) {
101 dev_dbg(&dev->pdev->dev, "Failed to connect to WD client\n");
102 dev->wd_cl.state = MEI_FILE_DISCONNECTED;
103 dev->wd_cl.host_client_id = 0;
617aa396
OW
104 ret = false;
105 goto end;
3ceb3e66
OW
106 } else {
107 dev->wd_cl.timer_count = CONNECT_TIMEOUT;
108 }
109 } else {
110 dev_dbg(&dev->pdev->dev, "Failed to find WD client\n");
617aa396
OW
111 ret = false;
112 goto end;
3ceb3e66
OW
113 }
114 } else {
115 dev->wd_bypass = true;
116 dev_dbg(&dev->pdev->dev, "WD requested to be disabled\n");
617aa396
OW
117 ret = false;
118 goto end;
3ceb3e66 119 }
617aa396
OW
120
121end:
122 return ret;
3ceb3e66
OW
123}
124
125/**
126 * mei_wd_send - sends watch dog message to fw.
127 *
128 * @dev: the device structure
129 *
130 * returns 0 if success,
131 * -EIO when message send fails
132 * -EINVAL when invalid message is to be sent
133 */
134int mei_wd_send(struct mei_device *dev)
135{
136 struct mei_msg_hdr *mei_hdr;
137
138 mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0];
139 mei_hdr->host_addr = dev->wd_cl.host_client_id;
140 mei_hdr->me_addr = dev->wd_cl.me_client_id;
141 mei_hdr->msg_complete = 1;
142 mei_hdr->reserved = 0;
143
144 if (!memcmp(dev->wd_data, mei_start_wd_params, MEI_WD_PARAMS_SIZE))
145 mei_hdr->length = MEI_START_WD_DATA_SIZE;
146 else if (!memcmp(dev->wd_data, mei_stop_wd_params, MEI_WD_PARAMS_SIZE))
147 mei_hdr->length = MEI_WD_PARAMS_SIZE;
148 else
149 return -EINVAL;
150
151 if (mei_write_message(dev, mei_hdr, dev->wd_data, mei_hdr->length))
152 return 0;
153 return -EIO;
154}
155
156int mei_wd_stop(struct mei_device *dev, bool preserve)
157{
158 int ret;
159 u16 wd_timeout = dev->wd_timeout;
160
161 cancel_delayed_work(&dev->wd_work);
162 if (dev->wd_cl.state != MEI_FILE_CONNECTED || !dev->wd_timeout)
163 return 0;
164
165 dev->wd_timeout = 0;
166 dev->wd_due_counter = 0;
167 memcpy(dev->wd_data, mei_stop_wd_params, MEI_WD_PARAMS_SIZE);
eb9af0ac 168 dev->stop = true;
3ceb3e66
OW
169
170 ret = mei_flow_ctrl_creds(dev, &dev->wd_cl);
171 if (ret < 0)
172 goto out;
173
174 if (ret && dev->mei_host_buffer_is_empty) {
175 ret = 0;
eb9af0ac 176 dev->mei_host_buffer_is_empty = false;
3ceb3e66
OW
177
178 if (!mei_wd_send(dev)) {
179 ret = mei_flow_ctrl_reduce(dev, &dev->wd_cl);
180 if (ret)
181 goto out;
182 } else {
183 dev_dbg(&dev->pdev->dev, "send stop WD failed\n");
184 }
185
eb9af0ac 186 dev->wd_pending = false;
3ceb3e66 187 } else {
eb9af0ac 188 dev->wd_pending = true;
3ceb3e66 189 }
eb9af0ac 190 dev->wd_stopped = false;
3ceb3e66
OW
191 mutex_unlock(&dev->device_lock);
192
193 ret = wait_event_interruptible_timeout(dev->wait_stop_wd,
194 dev->wd_stopped, 10 * HZ);
195 mutex_lock(&dev->device_lock);
a534bb6e
TW
196 if (dev->wd_stopped) {
197 dev_dbg(&dev->pdev->dev, "stop wd complete ret=%d.\n", ret);
198 ret = 0;
199 } else {
200 if (!ret)
201 ret = -ETIMEDOUT;
202 dev_warn(&dev->pdev->dev,
203 "stop wd failed to complete ret=%d.\n", ret);
204 }
3ceb3e66
OW
205
206 if (preserve)
207 dev->wd_timeout = wd_timeout;
208
209out:
210 return ret;
211}
212
This page took 0.069718 seconds and 5 git commands to generate.