Merge remote-tracking branch 'moduleh/module.h-split'
[linux-2.6/next.git] / drivers / staging / mei / wd.c
blob42f04efc90e4e477a6968be72aeb095e1a87554c
1 /*
3 * Intel Management Engine Interface (Intel MEI) Linux driver
4 * Copyright (c) 2003-2011, Intel Corporation.
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.
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.
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>
23 #include "mei_dev.h"
24 #include "hw.h"
25 #include "interface.h"
26 #include "mei.h"
29 * MEI Watchdog Module Parameters
31 static u16 watchdog_timeout = AMT_WD_VALUE;
32 module_param(watchdog_timeout, ushort, 0);
33 MODULE_PARM_DESC(watchdog_timeout,
34 "Intel(R) AMT Watchdog timeout value in seconds. (default="
35 __MODULE_STRING(AMT_WD_VALUE)
36 ", disable=0)");
38 static const u8 mei_start_wd_params[] = { 0x02, 0x12, 0x13, 0x10 };
39 static const u8 mei_stop_wd_params[] = { 0x02, 0x02, 0x14, 0x10 };
41 const u8 mei_wd_state_independence_msg[3][4] = {
42 {0x05, 0x02, 0x51, 0x10},
43 {0x05, 0x02, 0x52, 0x10},
44 {0x07, 0x02, 0x01, 0x10}
47 /* UUIDs for AMT F/W clients */
48 const uuid_le mei_wd_guid = UUID_LE(0x05B79A6F, 0x4628, 0x4D7F, 0x89,
49 0x9D, 0xA9, 0x15, 0x14, 0xCB,
50 0x32, 0xAB);
53 void mei_wd_start_setup(struct mei_device *dev)
55 dev_dbg(&dev->pdev->dev, "dev->wd_timeout=%d.\n", dev->wd_timeout);
56 memcpy(dev->wd_data, mei_start_wd_params, MEI_WD_PARAMS_SIZE);
57 memcpy(dev->wd_data + MEI_WD_PARAMS_SIZE,
58 &dev->wd_timeout, sizeof(u16));
61 /**
62 * host_init_wd - mei initialization wd.
64 * @dev: the device structure
66 void mei_wd_host_init(struct mei_device *dev)
68 mei_cl_init(&dev->wd_cl, dev);
70 /* look for WD client and connect to it */
71 dev->wd_cl.state = MEI_FILE_DISCONNECTED;
72 dev->wd_timeout = watchdog_timeout;
74 if (dev->wd_timeout > 0) {
75 mei_wd_start_setup(dev);
76 /* find ME WD client */
77 mei_find_me_client_update_filext(dev, &dev->wd_cl,
78 &mei_wd_guid, MEI_WD_HOST_CLIENT_ID);
80 dev_dbg(&dev->pdev->dev, "check wd_cl\n");
81 if (MEI_FILE_CONNECTING == dev->wd_cl.state) {
82 if (!mei_connect(dev, &dev->wd_cl)) {
83 dev_dbg(&dev->pdev->dev, "Failed to connect to WD client\n");
84 dev->wd_cl.state = MEI_FILE_DISCONNECTED;
85 dev->wd_cl.host_client_id = 0;
86 mei_host_init_iamthif(dev) ;
87 } else {
88 dev->wd_cl.timer_count = CONNECT_TIMEOUT;
90 } else {
91 dev_dbg(&dev->pdev->dev, "Failed to find WD client\n");
92 mei_host_init_iamthif(dev) ;
94 } else {
95 dev->wd_bypass = true;
96 dev_dbg(&dev->pdev->dev, "WD requested to be disabled\n");
97 mei_host_init_iamthif(dev) ;
102 * mei_wd_send - sends watch dog message to fw.
104 * @dev: the device structure
106 * returns 0 if success,
107 * -EIO when message send fails
108 * -EINVAL when invalid message is to be sent
110 int mei_wd_send(struct mei_device *dev)
112 struct mei_msg_hdr *mei_hdr;
114 mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0];
115 mei_hdr->host_addr = dev->wd_cl.host_client_id;
116 mei_hdr->me_addr = dev->wd_cl.me_client_id;
117 mei_hdr->msg_complete = 1;
118 mei_hdr->reserved = 0;
120 if (!memcmp(dev->wd_data, mei_start_wd_params, MEI_WD_PARAMS_SIZE))
121 mei_hdr->length = MEI_START_WD_DATA_SIZE;
122 else if (!memcmp(dev->wd_data, mei_stop_wd_params, MEI_WD_PARAMS_SIZE))
123 mei_hdr->length = MEI_WD_PARAMS_SIZE;
124 else
125 return -EINVAL;
127 if (mei_write_message(dev, mei_hdr, dev->wd_data, mei_hdr->length))
128 return 0;
129 return -EIO;
132 int mei_wd_stop(struct mei_device *dev, bool preserve)
134 int ret;
135 u16 wd_timeout = dev->wd_timeout;
137 cancel_delayed_work(&dev->wd_work);
138 if (dev->wd_cl.state != MEI_FILE_CONNECTED || !dev->wd_timeout)
139 return 0;
141 dev->wd_timeout = 0;
142 dev->wd_due_counter = 0;
143 memcpy(dev->wd_data, mei_stop_wd_params, MEI_WD_PARAMS_SIZE);
144 dev->stop = true;
146 ret = mei_flow_ctrl_creds(dev, &dev->wd_cl);
147 if (ret < 0)
148 goto out;
150 if (ret && dev->mei_host_buffer_is_empty) {
151 ret = 0;
152 dev->mei_host_buffer_is_empty = false;
154 if (!mei_wd_send(dev)) {
155 ret = mei_flow_ctrl_reduce(dev, &dev->wd_cl);
156 if (ret)
157 goto out;
158 } else {
159 dev_dbg(&dev->pdev->dev, "send stop WD failed\n");
162 dev->wd_pending = false;
163 } else {
164 dev->wd_pending = true;
166 dev->wd_stopped = false;
167 mutex_unlock(&dev->device_lock);
169 ret = wait_event_interruptible_timeout(dev->wait_stop_wd,
170 dev->wd_stopped, 10 * HZ);
171 mutex_lock(&dev->device_lock);
172 if (dev->wd_stopped) {
173 dev_dbg(&dev->pdev->dev, "stop wd complete ret=%d.\n", ret);
174 ret = 0;
175 } else {
176 if (!ret)
177 ret = -ETIMEDOUT;
178 dev_warn(&dev->pdev->dev,
179 "stop wd failed to complete ret=%d.\n", ret);
182 if (preserve)
183 dev->wd_timeout = wd_timeout;
185 out:
186 return ret;