staging: mei: removing wd module parameters
[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
3ceb3e66
OW
29static const u8 mei_start_wd_params[] = { 0x02, 0x12, 0x13, 0x10 };
30static const u8 mei_stop_wd_params[] = { 0x02, 0x02, 0x14, 0x10 };
31
32const u8 mei_wd_state_independence_msg[3][4] = {
33 {0x05, 0x02, 0x51, 0x10},
34 {0x05, 0x02, 0x52, 0x10},
35 {0x07, 0x02, 0x01, 0x10}
36};
37
38/* UUIDs for AMT F/W clients */
39const uuid_le mei_wd_guid = UUID_LE(0x05B79A6F, 0x4628, 0x4D7F, 0x89,
40 0x9D, 0xA9, 0x15, 0x14, 0xCB,
41 0x32, 0xAB);
42
43
55d33856 44void mei_wd_set_start_timeout(struct mei_device *dev, u16 timeout)
3ceb3e66 45{
55d33856 46 dev_dbg(&dev->pdev->dev, "timeout=%d.\n", timeout);
3ceb3e66
OW
47 memcpy(dev->wd_data, mei_start_wd_params, MEI_WD_PARAMS_SIZE);
48 memcpy(dev->wd_data + MEI_WD_PARAMS_SIZE,
55d33856 49 &timeout, sizeof(u16));
3ceb3e66
OW
50}
51
52/**
53 * host_init_wd - mei initialization wd.
54 *
55 * @dev: the device structure
56 */
617aa396 57bool mei_wd_host_init(struct mei_device *dev)
3ceb3e66 58{
617aa396
OW
59 bool ret = false;
60
c95efb74 61 mei_cl_init(&dev->wd_cl, dev);
3ceb3e66
OW
62
63 /* look for WD client and connect to it */
64 dev->wd_cl.state = MEI_FILE_DISCONNECTED;
2ad64ba8 65 dev->wd_timeout = AMT_WD_DEFAULT_TIMEOUT;
3ceb3e66 66
2ad64ba8
OW
67 /* find ME WD client */
68 mei_find_me_client_update_filext(dev, &dev->wd_cl,
69 &mei_wd_guid, MEI_WD_HOST_CLIENT_ID);
3ceb3e66 70
2ad64ba8
OW
71 dev_dbg(&dev->pdev->dev, "check wd_cl\n");
72 if (MEI_FILE_CONNECTING == dev->wd_cl.state) {
73 if (!mei_connect(dev, &dev->wd_cl)) {
74 dev_dbg(&dev->pdev->dev, "Failed to connect to WD client\n");
75 dev->wd_cl.state = MEI_FILE_DISCONNECTED;
76 dev->wd_cl.host_client_id = 0;
617aa396
OW
77 ret = false;
78 goto end;
2ad64ba8
OW
79 } else {
80 dev->wd_cl.timer_count = CONNECT_TIMEOUT;
3ceb3e66
OW
81 }
82 } else {
2ad64ba8 83 dev_dbg(&dev->pdev->dev, "Failed to find WD client\n");
617aa396
OW
84 ret = false;
85 goto end;
3ceb3e66 86 }
617aa396
OW
87
88end:
89 return ret;
3ceb3e66
OW
90}
91
92/**
93 * mei_wd_send - sends watch dog message to fw.
94 *
95 * @dev: the device structure
96 *
97 * returns 0 if success,
98 * -EIO when message send fails
99 * -EINVAL when invalid message is to be sent
100 */
101int mei_wd_send(struct mei_device *dev)
102{
103 struct mei_msg_hdr *mei_hdr;
104
105 mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0];
106 mei_hdr->host_addr = dev->wd_cl.host_client_id;
107 mei_hdr->me_addr = dev->wd_cl.me_client_id;
108 mei_hdr->msg_complete = 1;
109 mei_hdr->reserved = 0;
110
111 if (!memcmp(dev->wd_data, mei_start_wd_params, MEI_WD_PARAMS_SIZE))
112 mei_hdr->length = MEI_START_WD_DATA_SIZE;
113 else if (!memcmp(dev->wd_data, mei_stop_wd_params, MEI_WD_PARAMS_SIZE))
114 mei_hdr->length = MEI_WD_PARAMS_SIZE;
115 else
116 return -EINVAL;
117
118 if (mei_write_message(dev, mei_hdr, dev->wd_data, mei_hdr->length))
119 return 0;
120 return -EIO;
121}
122
123int mei_wd_stop(struct mei_device *dev, bool preserve)
124{
125 int ret;
126 u16 wd_timeout = dev->wd_timeout;
127
a61c6530 128 cancel_delayed_work(&dev->timer_work);
3ceb3e66
OW
129 if (dev->wd_cl.state != MEI_FILE_CONNECTED || !dev->wd_timeout)
130 return 0;
131
132 dev->wd_timeout = 0;
133 dev->wd_due_counter = 0;
134 memcpy(dev->wd_data, mei_stop_wd_params, MEI_WD_PARAMS_SIZE);
eb9af0ac 135 dev->stop = true;
3ceb3e66
OW
136
137 ret = mei_flow_ctrl_creds(dev, &dev->wd_cl);
138 if (ret < 0)
139 goto out;
140
141 if (ret && dev->mei_host_buffer_is_empty) {
142 ret = 0;
eb9af0ac 143 dev->mei_host_buffer_is_empty = false;
3ceb3e66
OW
144
145 if (!mei_wd_send(dev)) {
146 ret = mei_flow_ctrl_reduce(dev, &dev->wd_cl);
147 if (ret)
148 goto out;
149 } else {
150 dev_dbg(&dev->pdev->dev, "send stop WD failed\n");
151 }
152
eb9af0ac 153 dev->wd_pending = false;
3ceb3e66 154 } else {
eb9af0ac 155 dev->wd_pending = true;
3ceb3e66 156 }
eb9af0ac 157 dev->wd_stopped = false;
3ceb3e66
OW
158 mutex_unlock(&dev->device_lock);
159
160 ret = wait_event_interruptible_timeout(dev->wait_stop_wd,
161 dev->wd_stopped, 10 * HZ);
162 mutex_lock(&dev->device_lock);
a534bb6e
TW
163 if (dev->wd_stopped) {
164 dev_dbg(&dev->pdev->dev, "stop wd complete ret=%d.\n", ret);
165 ret = 0;
166 } else {
167 if (!ret)
168 ret = -ETIMEDOUT;
169 dev_warn(&dev->pdev->dev,
170 "stop wd failed to complete ret=%d.\n", ret);
171 }
3ceb3e66
OW
172
173 if (preserve)
174 dev->wd_timeout = wd_timeout;
175
176out:
177 return ret;
178}
179
4a3cafd5
OW
180/*
181 * mei_wd_ops_start - wd start command from the watchdog core.
182 *
183 * @wd_dev - watchdog device struct
184 *
185 * returns 0 if success, negative errno code for failure
186 */
187static int mei_wd_ops_start(struct watchdog_device *wd_dev)
188{
189 int err = -ENODEV;
190 struct mei_device *dev;
191
192 dev = pci_get_drvdata(mei_device);
193 if (!dev)
194 return -ENODEV;
195
196 mutex_lock(&dev->device_lock);
197
198 if (dev->mei_state != MEI_ENABLED) {
199 dev_dbg(&dev->pdev->dev, "mei_state != MEI_ENABLED mei_state= %d\n",
200 dev->mei_state);
201 goto end_unlock;
202 }
203
204 if (dev->wd_cl.state != MEI_FILE_CONNECTED) {
205 dev_dbg(&dev->pdev->dev, "MEI Driver is not connected to Watchdog Client\n");
206 goto end_unlock;
207 }
208
55d33856 209 mei_wd_set_start_timeout(dev, dev->wd_timeout);
4a3cafd5
OW
210
211 err = 0;
212end_unlock:
213 mutex_unlock(&dev->device_lock);
214 return err;
215}
216
217/*
218 * mei_wd_ops_stop - wd stop command from the watchdog core.
219 *
220 * @wd_dev - watchdog device struct
221 *
222 * returns 0 if success, negative errno code for failure
223 */
224static int mei_wd_ops_stop(struct watchdog_device *wd_dev)
225{
226 struct mei_device *dev;
227 dev = pci_get_drvdata(mei_device);
228
229 if (!dev)
230 return -ENODEV;
231
232 mutex_lock(&dev->device_lock);
233 mei_wd_stop(dev, false);
234 mutex_unlock(&dev->device_lock);
235
236 return 0;
237}
238
8c4a59a7
OW
239/*
240 * mei_wd_ops_ping - wd ping command from the watchdog core.
241 *
242 * @wd_dev - watchdog device struct
243 *
244 * returns 0 if success, negative errno code for failure
245 */
246static int mei_wd_ops_ping(struct watchdog_device *wd_dev)
247{
248 int ret = 0;
249 struct mei_device *dev;
250 dev = pci_get_drvdata(mei_device);
251
252 if (!dev)
253 return -ENODEV;
254
255 mutex_lock(&dev->device_lock);
256
257 if (dev->wd_cl.state != MEI_FILE_CONNECTED) {
258 dev_dbg(&dev->pdev->dev, "wd is not connected.\n");
259 ret = -ENODEV;
260 goto end;
261 }
262
263 /* Check if we can send the ping to HW*/
264 if (dev->mei_host_buffer_is_empty &&
265 mei_flow_ctrl_creds(dev, &dev->wd_cl) > 0) {
266
267 dev->mei_host_buffer_is_empty = false;
268 dev_dbg(&dev->pdev->dev, "sending watchdog ping\n");
269
270 if (mei_wd_send(dev)) {
271 dev_dbg(&dev->pdev->dev, "wd send failed.\n");
272 ret = -EIO;
273 goto end;
274 }
275
276 if (mei_flow_ctrl_reduce(dev, &dev->wd_cl)) {
277 dev_dbg(&dev->pdev->dev, "mei_flow_ctrl_reduce() failed.\n");
278 ret = -EIO;
279 goto end;
280 }
281
282 } else {
283 dev->wd_pending = true;
284 }
285
286end:
287 mutex_unlock(&dev->device_lock);
288 return ret;
289}
290
55d33856
OW
291/*
292 * mei_wd_ops_set_timeout - wd set timeout command from the watchdog core.
293 *
294 * @wd_dev - watchdog device struct
295 * @timeout - timeout value to set
296 *
297 * returns 0 if success, negative errno code for failure
298 */
299static int mei_wd_ops_set_timeout(struct watchdog_device *wd_dev, unsigned int timeout)
300{
301 struct mei_device *dev;
302 dev = pci_get_drvdata(mei_device);
303
304 if (!dev)
305 return -ENODEV;
306
307 /* Check Timeout value */
308 if (timeout < AMT_WD_MIN_TIMEOUT || timeout > AMT_WD_MAX_TIMEOUT)
309 return -EINVAL;
310
311 mutex_lock(&dev->device_lock);
312
313 dev->wd_timeout = timeout;
314 mei_wd_set_start_timeout(dev, dev->wd_timeout);
315
316 mutex_unlock(&dev->device_lock);
317
318 return 0;
319}
320
4a3cafd5
OW
321/*
322 * Watchdog Device structs
323 */
324const struct watchdog_ops wd_ops = {
325 .owner = THIS_MODULE,
326 .start = mei_wd_ops_start,
327 .stop = mei_wd_ops_stop,
8c4a59a7 328 .ping = mei_wd_ops_ping,
55d33856 329 .set_timeout = mei_wd_ops_set_timeout,
4a3cafd5
OW
330};
331const struct watchdog_info wd_info = {
332 .identity = INTEL_AMT_WATCHDOG_ID,
8c4a59a7 333 .options = WDIOF_KEEPALIVEPING,
4a3cafd5
OW
334};
335
336struct watchdog_device amt_wd_dev = {
337 .info = &wd_info,
338 .ops = &wd_ops,
339 .timeout = AMT_WD_DEFAULT_TIMEOUT,
340 .min_timeout = AMT_WD_MIN_TIMEOUT,
341 .max_timeout = AMT_WD_MAX_TIMEOUT,
342};
343
344
This page took 0.07407 seconds and 5 git commands to generate.