blob: 95f05d97a1154702e2e852df42c16fa5eff9c72b [file] [log] [blame]
Oren Weilab841162011-05-15 13:43:41 +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 Weilab841162011-05-15 13:43:41 +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
Tomas Winkler2f3d2b42012-03-19 22:38:13 +020017#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
Oren Weilab841162011-05-15 13:43:41 +030019#include <linux/module.h>
20#include <linux/moduleparam.h>
21#include <linux/kernel.h>
22#include <linux/device.h>
23#include <linux/fs.h>
24#include <linux/errno.h>
25#include <linux/types.h>
26#include <linux/fcntl.h>
27#include <linux/aio.h>
28#include <linux/pci.h>
29#include <linux/poll.h>
30#include <linux/init.h>
31#include <linux/ioctl.h>
32#include <linux/cdev.h>
Oren Weilab841162011-05-15 13:43:41 +030033#include <linux/sched.h>
34#include <linux/uuid.h>
35#include <linux/compat.h>
36#include <linux/jiffies.h>
37#include <linux/interrupt.h>
Oren Weil5b881e32011-11-13 09:41:14 +020038#include <linux/miscdevice.h>
Oren Weilab841162011-05-15 13:43:41 +030039
Tomas Winkler4f3afe12012-05-09 16:38:59 +030040#include <linux/mei.h>
Tomas Winkler47a73802012-12-25 19:06:03 +020041
42#include "mei_dev.h"
Oren Weilab841162011-05-15 13:43:41 +030043#include "interface.h"
Tomas Winkler90e0b5f2013-01-08 23:07:14 +020044#include "client.h"
Oren Weilab841162011-05-15 13:43:41 +030045
Tomas Winklerdaed6b52012-08-17 09:54:23 +030046/* AMT device is a singleton on the platform */
47static struct pci_dev *mei_pdev;
Oren Weilab841162011-05-15 13:43:41 +030048
Oren Weilab841162011-05-15 13:43:41 +030049/* mei_pci_tbl - PCI Device ID Table */
50static DEFINE_PCI_DEVICE_TABLE(mei_pci_tbl) = {
51 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82946GZ)},
52 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82G35)},
53 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82Q965)},
54 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82G965)},
55 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82GM965)},
56 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82GME965)},
57 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_82Q35)},
58 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_82G33)},
59 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_82Q33)},
60 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_82X38)},
61 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_3200)},
62 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_6)},
63 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_7)},
64 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_8)},
65 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_9)},
66 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_10)},
67 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9M_1)},
68 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9M_2)},
69 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9M_3)},
70 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9M_4)},
71 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH10_1)},
72 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH10_2)},
73 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH10_3)},
74 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH10_4)},
75 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_IBXPK_1)},
76 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_IBXPK_2)},
77 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_CPT_1)},
78 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_PBG_1)},
79 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_PPT_1)},
80 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_PPT_2)},
81 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_PPT_3)},
Tomas Winkler9af51422012-08-29 01:15:50 +030082 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_LPT)},
83 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_LPT_LP)},
Oren Weilab841162011-05-15 13:43:41 +030084
85 /* required last entry */
86 {0, }
87};
88
89MODULE_DEVICE_TABLE(pci, mei_pci_tbl);
90
91static DEFINE_MUTEX(mei_mutex);
92
Oren Weilab841162011-05-15 13:43:41 +030093
94/**
Oren Weilab841162011-05-15 13:43:41 +030095 * mei_open - the open function
96 *
97 * @inode: pointer to inode structure
98 * @file: pointer to file structure
99 *
100 * returns 0 on success, <0 on error
101 */
102static int mei_open(struct inode *inode, struct file *file)
103{
104 struct mei_cl *cl;
Oren Weilab841162011-05-15 13:43:41 +0300105 struct mei_device *dev;
Tomas Winkler6f37aca2011-11-13 09:41:15 +0200106 unsigned long cl_id;
107 int err;
Oren Weilab841162011-05-15 13:43:41 +0300108
109 err = -ENODEV;
Tomas Winklerdaed6b52012-08-17 09:54:23 +0300110 if (!mei_pdev)
Oren Weilab841162011-05-15 13:43:41 +0300111 goto out;
112
Tomas Winklerdaed6b52012-08-17 09:54:23 +0300113 dev = pci_get_drvdata(mei_pdev);
Oren Weil5b881e32011-11-13 09:41:14 +0200114 if (!dev)
Oren Weilab841162011-05-15 13:43:41 +0300115 goto out;
116
117 mutex_lock(&dev->device_lock);
118 err = -ENOMEM;
Tomas Winklerc95efb72011-05-25 17:28:21 +0300119 cl = mei_cl_allocate(dev);
Oren Weilab841162011-05-15 13:43:41 +0300120 if (!cl)
Alexey Khoroshilov303dfbf2011-08-31 00:41:14 +0400121 goto out_unlock;
Oren Weilab841162011-05-15 13:43:41 +0300122
123 err = -ENODEV;
Tomas Winklerb210d752012-08-07 00:03:56 +0300124 if (dev->dev_state != MEI_DEV_ENABLED) {
125 dev_dbg(&dev->pdev->dev, "dev_state != MEI_ENABLED dev_state = %s\n",
126 mei_dev_state_str(dev->dev_state));
Oren Weilab841162011-05-15 13:43:41 +0300127 goto out_unlock;
128 }
129 err = -EMFILE;
Tomas Winkler1b812942012-09-11 00:43:20 +0300130 if (dev->open_handle_count >= MEI_MAX_OPEN_HANDLE_COUNT) {
131 dev_err(&dev->pdev->dev, "open_handle_count exceded %d",
132 MEI_MAX_OPEN_HANDLE_COUNT);
Oren Weilab841162011-05-15 13:43:41 +0300133 goto out_unlock;
Tomas Winkler1b812942012-09-11 00:43:20 +0300134 }
Oren Weilab841162011-05-15 13:43:41 +0300135
Tomas Winkler6f37aca2011-11-13 09:41:15 +0200136 cl_id = find_first_zero_bit(dev->host_clients_map, MEI_CLIENTS_MAX);
Tomas Winkler1b812942012-09-11 00:43:20 +0300137 if (cl_id >= MEI_CLIENTS_MAX) {
138 dev_err(&dev->pdev->dev, "client_id exceded %d",
139 MEI_CLIENTS_MAX) ;
Oren Weilab841162011-05-15 13:43:41 +0300140 goto out_unlock;
Tomas Winkler1b812942012-09-11 00:43:20 +0300141 }
Oren Weilab841162011-05-15 13:43:41 +0300142
Tomas Winkler6f37aca2011-11-13 09:41:15 +0200143 cl->host_client_id = cl_id;
144
Oren Weilab841162011-05-15 13:43:41 +0300145 dev_dbg(&dev->pdev->dev, "client_id = %d\n", cl->host_client_id);
146
147 dev->open_handle_count++;
Tomas Winkler6f37aca2011-11-13 09:41:15 +0200148
Oren Weilab841162011-05-15 13:43:41 +0300149 list_add_tail(&cl->link, &dev->file_list);
150
151 set_bit(cl->host_client_id, dev->host_clients_map);
152 cl->state = MEI_FILE_INITIALIZING;
153 cl->sm_state = 0;
154
155 file->private_data = cl;
156 mutex_unlock(&dev->device_lock);
157
Oren Weil5b881e32011-11-13 09:41:14 +0200158 return nonseekable_open(inode, file);
Oren Weilab841162011-05-15 13:43:41 +0300159
160out_unlock:
161 mutex_unlock(&dev->device_lock);
162 kfree(cl);
163out:
164 return err;
165}
166
167/**
168 * mei_release - the release function
169 *
170 * @inode: pointer to inode structure
171 * @file: pointer to file structure
172 *
173 * returns 0 on success, <0 on error
174 */
175static int mei_release(struct inode *inode, struct file *file)
176{
177 struct mei_cl *cl = file->private_data;
178 struct mei_cl_cb *cb;
179 struct mei_device *dev;
180 int rets = 0;
181
182 if (WARN_ON(!cl || !cl->dev))
183 return -ENODEV;
184
185 dev = cl->dev;
186
187 mutex_lock(&dev->device_lock);
Tomas Winklera562d5c2012-11-11 17:38:01 +0200188 if (cl == &dev->iamthif_cl) {
189 rets = mei_amthif_release(dev, file);
190 goto out;
191 }
192 if (cl->state == MEI_FILE_CONNECTED) {
193 cl->state = MEI_FILE_DISCONNECTING;
194 dev_dbg(&dev->pdev->dev,
195 "disconnecting client host client = %d, "
196 "ME client = %d\n",
Oren Weilab841162011-05-15 13:43:41 +0300197 cl->host_client_id,
198 cl->me_client_id);
Tomas Winkler90e0b5f2013-01-08 23:07:14 +0200199 rets = mei_cl_disconnect(cl);
Oren Weilab841162011-05-15 13:43:41 +0300200 }
Tomas Winklera562d5c2012-11-11 17:38:01 +0200201 mei_cl_flush_queues(cl);
202 dev_dbg(&dev->pdev->dev, "remove client host client = %d, ME client = %d\n",
203 cl->host_client_id,
204 cl->me_client_id);
205
206 if (dev->open_handle_count > 0) {
207 clear_bit(cl->host_client_id, dev->host_clients_map);
208 dev->open_handle_count--;
209 }
Tomas Winkler90e0b5f2013-01-08 23:07:14 +0200210 mei_cl_unlink(cl);
Tomas Winklera562d5c2012-11-11 17:38:01 +0200211
212 /* free read cb */
213 cb = NULL;
214 if (cl->read_cb) {
Tomas Winkler90e0b5f2013-01-08 23:07:14 +0200215 cb = mei_cl_find_read_cb(cl);
Tomas Winklera562d5c2012-11-11 17:38:01 +0200216 /* Remove entry from read list */
217 if (cb)
218 list_del(&cb->list);
219
220 cb = cl->read_cb;
221 cl->read_cb = NULL;
222 }
223
224 file->private_data = NULL;
225
226 if (cb) {
227 mei_io_cb_free(cb);
228 cb = NULL;
229 }
230
231 kfree(cl);
232out:
Oren Weilab841162011-05-15 13:43:41 +0300233 mutex_unlock(&dev->device_lock);
234 return rets;
235}
236
237
238/**
239 * mei_read - the read function.
240 *
241 * @file: pointer to file structure
242 * @ubuf: pointer to user buffer
243 * @length: buffer length
244 * @offset: data offset in buffer
245 *
246 * returns >=0 data length on success , <0 on error
247 */
248static ssize_t mei_read(struct file *file, char __user *ubuf,
Tomas Winkler441ab502011-12-13 23:39:34 +0200249 size_t length, loff_t *offset)
Oren Weilab841162011-05-15 13:43:41 +0300250{
251 struct mei_cl *cl = file->private_data;
252 struct mei_cl_cb *cb_pos = NULL;
253 struct mei_cl_cb *cb = NULL;
254 struct mei_device *dev;
255 int i;
256 int rets;
257 int err;
258
259
260 if (WARN_ON(!cl || !cl->dev))
261 return -ENODEV;
262
263 dev = cl->dev;
264
265 mutex_lock(&dev->device_lock);
Tomas Winklerb210d752012-08-07 00:03:56 +0300266 if (dev->dev_state != MEI_DEV_ENABLED) {
Oren Weilab841162011-05-15 13:43:41 +0300267 rets = -ENODEV;
268 goto out;
269 }
270
271 if ((cl->sm_state & MEI_WD_STATE_INDEPENDENCE_MSG_SENT) == 0) {
272 /* Do not allow to read watchdog client */
Tomas Winkler07b509b2012-07-23 14:05:39 +0300273 i = mei_me_cl_by_uuid(dev, &mei_wd_guid);
Oren Weilab841162011-05-15 13:43:41 +0300274 if (i >= 0) {
275 struct mei_me_client *me_client = &dev->me_clients[i];
Oren Weilab841162011-05-15 13:43:41 +0300276 if (cl->me_client_id == me_client->client_id) {
277 rets = -EBADF;
278 goto out;
279 }
280 }
281 } else {
282 cl->sm_state &= ~MEI_WD_STATE_INDEPENDENCE_MSG_SENT;
283 }
284
285 if (cl == &dev->iamthif_cl) {
Tomas Winkler19838fb2012-11-01 21:17:15 +0200286 rets = mei_amthif_read(dev, file, ubuf, length, offset);
Oren Weilab841162011-05-15 13:43:41 +0300287 goto out;
288 }
289
Tomas Winklerebb108ef2012-10-09 16:50:16 +0200290 if (cl->read_cb && cl->read_cb->buf_idx > *offset) {
Oren Weilab841162011-05-15 13:43:41 +0300291 cb = cl->read_cb;
292 goto copy_buffer;
Tomas Winklerebb108ef2012-10-09 16:50:16 +0200293 } else if (cl->read_cb && cl->read_cb->buf_idx > 0 &&
294 cl->read_cb->buf_idx <= *offset) {
Oren Weilab841162011-05-15 13:43:41 +0300295 cb = cl->read_cb;
296 rets = 0;
297 goto free;
Tomas Winklerebb108ef2012-10-09 16:50:16 +0200298 } else if ((!cl->read_cb || !cl->read_cb->buf_idx) && *offset > 0) {
Justin P. Mattock5f9092f32012-03-12 07:18:09 -0700299 /*Offset needs to be cleaned for contiguous reads*/
Oren Weilab841162011-05-15 13:43:41 +0300300 *offset = 0;
301 rets = 0;
302 goto out;
303 }
304
Tomas Winkler90e0b5f2013-01-08 23:07:14 +0200305 err = mei_cl_read_start(cl);
Oren Weilab841162011-05-15 13:43:41 +0300306 if (err && err != -EBUSY) {
307 dev_dbg(&dev->pdev->dev,
308 "mei start read failure with status = %d\n", err);
309 rets = err;
310 goto out;
311 }
312
313 if (MEI_READ_COMPLETE != cl->reading_state &&
314 !waitqueue_active(&cl->rx_wait)) {
315 if (file->f_flags & O_NONBLOCK) {
316 rets = -EAGAIN;
317 goto out;
318 }
319
320 mutex_unlock(&dev->device_lock);
321
322 if (wait_event_interruptible(cl->rx_wait,
323 (MEI_READ_COMPLETE == cl->reading_state ||
324 MEI_FILE_INITIALIZING == cl->state ||
325 MEI_FILE_DISCONNECTED == cl->state ||
326 MEI_FILE_DISCONNECTING == cl->state))) {
327 if (signal_pending(current))
328 return -EINTR;
329 return -ERESTARTSYS;
330 }
331
332 mutex_lock(&dev->device_lock);
333 if (MEI_FILE_INITIALIZING == cl->state ||
334 MEI_FILE_DISCONNECTED == cl->state ||
335 MEI_FILE_DISCONNECTING == cl->state) {
336 rets = -EBUSY;
337 goto out;
338 }
339 }
340
341 cb = cl->read_cb;
342
343 if (!cb) {
344 rets = -ENODEV;
345 goto out;
346 }
347 if (cl->reading_state != MEI_READ_COMPLETE) {
348 rets = 0;
349 goto out;
350 }
351 /* now copy the data to user space */
352copy_buffer:
353 dev_dbg(&dev->pdev->dev, "cb->response_buffer size - %d\n",
354 cb->response_buffer.size);
Tomas Winklerebb108ef2012-10-09 16:50:16 +0200355 dev_dbg(&dev->pdev->dev, "cb->buf_idx - %lu\n", cb->buf_idx);
356 if (length == 0 || ubuf == NULL || *offset > cb->buf_idx) {
Oren Weilab841162011-05-15 13:43:41 +0300357 rets = -EMSGSIZE;
358 goto free;
359 }
360
Tomas Winklerebb108ef2012-10-09 16:50:16 +0200361 /* length is being truncated to PAGE_SIZE,
362 * however buf_idx may point beyond that */
363 length = min_t(size_t, length, cb->buf_idx - *offset);
Oren Weilab841162011-05-15 13:43:41 +0300364
Tomas Winkler441ab502011-12-13 23:39:34 +0200365 if (copy_to_user(ubuf, cb->response_buffer.data + *offset, length)) {
Oren Weilab841162011-05-15 13:43:41 +0300366 rets = -EFAULT;
367 goto free;
368 }
369
370 rets = length;
371 *offset += length;
Tomas Winklerebb108ef2012-10-09 16:50:16 +0200372 if ((unsigned long)*offset < cb->buf_idx)
Oren Weilab841162011-05-15 13:43:41 +0300373 goto out;
374
375free:
Tomas Winkler90e0b5f2013-01-08 23:07:14 +0200376 cb_pos = mei_cl_find_read_cb(cl);
Oren Weilab841162011-05-15 13:43:41 +0300377 /* Remove entry from read list */
378 if (cb_pos)
Tomas Winklerfb601ad2012-10-15 12:06:48 +0200379 list_del(&cb_pos->list);
Tomas Winkler601a1ef2012-10-09 16:50:20 +0200380 mei_io_cb_free(cb);
Oren Weilab841162011-05-15 13:43:41 +0300381 cl->reading_state = MEI_IDLE;
382 cl->read_cb = NULL;
383 cl->read_pending = 0;
384out:
385 dev_dbg(&dev->pdev->dev, "end mei read rets= %d\n", rets);
386 mutex_unlock(&dev->device_lock);
387 return rets;
388}
Tomas Winkler33d28c92012-10-09 16:50:17 +0200389/**
Oren Weilab841162011-05-15 13:43:41 +0300390 * mei_write - the write function.
391 *
392 * @file: pointer to file structure
393 * @ubuf: pointer to user buffer
394 * @length: buffer length
395 * @offset: data offset in buffer
396 *
397 * returns >=0 data length on success , <0 on error
398 */
399static ssize_t mei_write(struct file *file, const char __user *ubuf,
Tomas Winkler441ab502011-12-13 23:39:34 +0200400 size_t length, loff_t *offset)
Oren Weilab841162011-05-15 13:43:41 +0300401{
402 struct mei_cl *cl = file->private_data;
403 struct mei_cl_cb *write_cb = NULL;
404 struct mei_msg_hdr mei_hdr;
405 struct mei_device *dev;
406 unsigned long timeout = 0;
407 int rets;
408 int i;
409
410 if (WARN_ON(!cl || !cl->dev))
411 return -ENODEV;
412
413 dev = cl->dev;
414
415 mutex_lock(&dev->device_lock);
416
Tomas Winklerb210d752012-08-07 00:03:56 +0300417 if (dev->dev_state != MEI_DEV_ENABLED) {
Tomas Winkler75f0ee12012-10-09 16:50:18 +0200418 rets = -ENODEV;
Tomas Winklerb0d0cf72012-11-01 21:17:13 +0200419 goto err;
Oren Weilab841162011-05-15 13:43:41 +0300420 }
421
Tomas Winkler75f0ee12012-10-09 16:50:18 +0200422 i = mei_me_cl_by_id(dev, cl->me_client_id);
423 if (i < 0) {
424 rets = -ENODEV;
Tomas Winklerb0d0cf72012-11-01 21:17:13 +0200425 goto err;
Tomas Winkler75f0ee12012-10-09 16:50:18 +0200426 }
427 if (length > dev->me_clients[i].props.max_msg_length || length <= 0) {
428 rets = -EMSGSIZE;
Tomas Winklerb0d0cf72012-11-01 21:17:13 +0200429 goto err;
Tomas Winkler75f0ee12012-10-09 16:50:18 +0200430 }
431
432 if (cl->state != MEI_FILE_CONNECTED) {
433 rets = -ENODEV;
434 dev_err(&dev->pdev->dev, "host client = %d, is not connected to ME client = %d",
435 cl->host_client_id, cl->me_client_id);
Tomas Winklerb0d0cf72012-11-01 21:17:13 +0200436 goto err;
Tomas Winkler75f0ee12012-10-09 16:50:18 +0200437 }
Oren Weilab841162011-05-15 13:43:41 +0300438 if (cl == &dev->iamthif_cl) {
Tomas Winkler19838fb2012-11-01 21:17:15 +0200439 write_cb = mei_amthif_find_read_list_entry(dev, file);
Oren Weilab841162011-05-15 13:43:41 +0300440
441 if (write_cb) {
442 timeout = write_cb->read_time +
Tomas Winkler3870c322012-11-01 21:17:14 +0200443 mei_secs_to_jiffies(MEI_IAMTHIF_READ_TIMER);
Oren Weilab841162011-05-15 13:43:41 +0300444
445 if (time_after(jiffies, timeout) ||
Tomas Winkler75f0ee12012-10-09 16:50:18 +0200446 cl->reading_state == MEI_READ_COMPLETE) {
447 *offset = 0;
Tomas Winklerfb601ad2012-10-15 12:06:48 +0200448 list_del(&write_cb->list);
Tomas Winkler601a1ef2012-10-09 16:50:20 +0200449 mei_io_cb_free(write_cb);
Tomas Winkler75f0ee12012-10-09 16:50:18 +0200450 write_cb = NULL;
Oren Weilab841162011-05-15 13:43:41 +0300451 }
452 }
453 }
454
455 /* free entry used in read */
456 if (cl->reading_state == MEI_READ_COMPLETE) {
457 *offset = 0;
Tomas Winkler90e0b5f2013-01-08 23:07:14 +0200458 write_cb = mei_cl_find_read_cb(cl);
Oren Weilab841162011-05-15 13:43:41 +0300459 if (write_cb) {
Tomas Winklerfb601ad2012-10-15 12:06:48 +0200460 list_del(&write_cb->list);
Tomas Winkler601a1ef2012-10-09 16:50:20 +0200461 mei_io_cb_free(write_cb);
Oren Weilab841162011-05-15 13:43:41 +0300462 write_cb = NULL;
463 cl->reading_state = MEI_IDLE;
464 cl->read_cb = NULL;
465 cl->read_pending = 0;
466 }
Tomas Winkler441ab502011-12-13 23:39:34 +0200467 } else if (cl->reading_state == MEI_IDLE && !cl->read_pending)
Oren Weilab841162011-05-15 13:43:41 +0300468 *offset = 0;
469
470
Tomas Winkler33d28c92012-10-09 16:50:17 +0200471 write_cb = mei_io_cb_init(cl, file);
Oren Weilab841162011-05-15 13:43:41 +0300472 if (!write_cb) {
Tomas Winkler33d28c92012-10-09 16:50:17 +0200473 dev_err(&dev->pdev->dev, "write cb allocation failed\n");
474 rets = -ENOMEM;
Tomas Winklerb0d0cf72012-11-01 21:17:13 +0200475 goto err;
Oren Weilab841162011-05-15 13:43:41 +0300476 }
Tomas Winkler33d28c92012-10-09 16:50:17 +0200477 rets = mei_io_cb_alloc_req_buf(write_cb, length);
478 if (rets)
Tomas Winklerb0d0cf72012-11-01 21:17:13 +0200479 goto err;
Oren Weilab841162011-05-15 13:43:41 +0300480
Tomas Winkler33d28c92012-10-09 16:50:17 +0200481 dev_dbg(&dev->pdev->dev, "cb request size = %zd\n", length);
Oren Weilab841162011-05-15 13:43:41 +0300482
Tomas Winkler75f0ee12012-10-09 16:50:18 +0200483 rets = copy_from_user(write_cb->request_buffer.data, ubuf, length);
484 if (rets)
Tomas Winklerb0d0cf72012-11-01 21:17:13 +0200485 goto err;
Oren Weilab841162011-05-15 13:43:41 +0300486
487 cl->sm_state = 0;
488 if (length == 4 &&
489 ((memcmp(mei_wd_state_independence_msg[0],
490 write_cb->request_buffer.data, 4) == 0) ||
491 (memcmp(mei_wd_state_independence_msg[1],
492 write_cb->request_buffer.data, 4) == 0) ||
493 (memcmp(mei_wd_state_independence_msg[2],
494 write_cb->request_buffer.data, 4) == 0)))
495 cl->sm_state |= MEI_WD_STATE_INDEPENDENCE_MSG_SENT;
496
Oren Weilab841162011-05-15 13:43:41 +0300497 if (cl == &dev->iamthif_cl) {
Tomas Winklerab5c4a52012-11-01 21:17:18 +0200498 rets = mei_amthif_write(dev, write_cb);
499
500 if (rets) {
501 dev_err(&dev->pdev->dev,
502 "amthi write failed with status = %d\n", rets);
Tomas Winklerb0d0cf72012-11-01 21:17:13 +0200503 goto err;
Oren Weilab841162011-05-15 13:43:41 +0300504 }
505 mutex_unlock(&dev->device_lock);
Tomas Winkler75f0ee12012-10-09 16:50:18 +0200506 return length;
Oren Weilab841162011-05-15 13:43:41 +0300507 }
508
Tomas Winkler4b8960b2012-11-11 17:38:00 +0200509 write_cb->fop_type = MEI_FOP_WRITE;
Oren Weilab841162011-05-15 13:43:41 +0300510
511 dev_dbg(&dev->pdev->dev, "host client = %d, ME client = %d\n",
512 cl->host_client_id, cl->me_client_id);
Tomas Winkler90e0b5f2013-01-08 23:07:14 +0200513 rets = mei_cl_flow_ctrl_creds(cl);
Oren Weilab841162011-05-15 13:43:41 +0300514 if (rets < 0)
Tomas Winklerb0d0cf72012-11-01 21:17:13 +0200515 goto err;
Oren Weilab841162011-05-15 13:43:41 +0300516
Tomas Winklerb0d0cf72012-11-01 21:17:13 +0200517 if (rets == 0 || dev->mei_host_buffer_is_empty == false) {
Tomas Winklerebb108ef2012-10-09 16:50:16 +0200518 write_cb->buf_idx = 0;
Tomas Winklerb0d0cf72012-11-01 21:17:13 +0200519 mei_hdr.msg_complete = 0;
Oren Weilab841162011-05-15 13:43:41 +0300520 cl->writing_state = MEI_WRITING;
Tomas Winklerb0d0cf72012-11-01 21:17:13 +0200521 goto out;
522 }
523
524 dev->mei_host_buffer_is_empty = false;
525 if (length > mei_hbuf_max_data(dev)) {
526 mei_hdr.length = mei_hbuf_max_data(dev);
527 mei_hdr.msg_complete = 0;
528 } else {
529 mei_hdr.length = length;
530 mei_hdr.msg_complete = 1;
531 }
532 mei_hdr.host_addr = cl->host_client_id;
533 mei_hdr.me_addr = cl->me_client_id;
534 mei_hdr.reserved = 0;
Tomas Winkler15d4acc2012-12-25 19:06:00 +0200535
536 dev_dbg(&dev->pdev->dev, "write " MEI_HDR_FMT "\n",
537 MEI_HDR_PRM(&mei_hdr));
Tomas Winkler438763f2012-12-25 19:05:59 +0200538 if (mei_write_message(dev, &mei_hdr, write_cb->request_buffer.data)) {
Tomas Winklerb0d0cf72012-11-01 21:17:13 +0200539 rets = -ENODEV;
540 goto err;
541 }
542 cl->writing_state = MEI_WRITING;
543 write_cb->buf_idx = mei_hdr.length;
544
545out:
546 if (mei_hdr.msg_complete) {
Tomas Winkler90e0b5f2013-01-08 23:07:14 +0200547 if (mei_cl_flow_ctrl_reduce(cl)) {
Tomas Winklerb0d0cf72012-11-01 21:17:13 +0200548 rets = -ENODEV;
549 goto err;
550 }
551 list_add_tail(&write_cb->list, &dev->write_waiting_list.list);
552 } else {
Tomas Winklerfb601ad2012-10-15 12:06:48 +0200553 list_add_tail(&write_cb->list, &dev->write_list.list);
Oren Weilab841162011-05-15 13:43:41 +0300554 }
Tomas Winklerb0d0cf72012-11-01 21:17:13 +0200555
Oren Weilab841162011-05-15 13:43:41 +0300556 mutex_unlock(&dev->device_lock);
557 return length;
558
Tomas Winklerb0d0cf72012-11-01 21:17:13 +0200559err:
Oren Weilab841162011-05-15 13:43:41 +0300560 mutex_unlock(&dev->device_lock);
Tomas Winkler601a1ef2012-10-09 16:50:20 +0200561 mei_io_cb_free(write_cb);
Oren Weilab841162011-05-15 13:43:41 +0300562 return rets;
563}
564
565
566/**
567 * mei_ioctl - the IOCTL function
568 *
569 * @file: pointer to file structure
570 * @cmd: ioctl command
571 * @data: pointer to mei message structure
572 *
573 * returns 0 on success , <0 on error
574 */
575static long mei_ioctl(struct file *file, unsigned int cmd, unsigned long data)
576{
577 struct mei_device *dev;
578 struct mei_cl *cl = file->private_data;
579 struct mei_connect_client_data *connect_data = NULL;
580 int rets;
581
582 if (cmd != IOCTL_MEI_CONNECT_CLIENT)
583 return -EINVAL;
584
585 if (WARN_ON(!cl || !cl->dev))
586 return -ENODEV;
587
588 dev = cl->dev;
589
590 dev_dbg(&dev->pdev->dev, "IOCTL cmd = 0x%x", cmd);
591
592 mutex_lock(&dev->device_lock);
Tomas Winklerb210d752012-08-07 00:03:56 +0300593 if (dev->dev_state != MEI_DEV_ENABLED) {
Oren Weilab841162011-05-15 13:43:41 +0300594 rets = -ENODEV;
595 goto out;
596 }
597
598 dev_dbg(&dev->pdev->dev, ": IOCTL_MEI_CONNECT_CLIENT.\n");
599
600 connect_data = kzalloc(sizeof(struct mei_connect_client_data),
601 GFP_KERNEL);
602 if (!connect_data) {
603 rets = -ENOMEM;
604 goto out;
605 }
606 dev_dbg(&dev->pdev->dev, "copy connect data from user\n");
607 if (copy_from_user(connect_data, (char __user *)data,
608 sizeof(struct mei_connect_client_data))) {
609 dev_dbg(&dev->pdev->dev, "failed to copy data from userland\n");
610 rets = -EFAULT;
611 goto out;
612 }
613 rets = mei_ioctl_connect_client(file, connect_data);
614
615 /* if all is ok, copying the data back to user. */
616 if (rets)
617 goto out;
618
619 dev_dbg(&dev->pdev->dev, "copy connect data to user\n");
620 if (copy_to_user((char __user *)data, connect_data,
621 sizeof(struct mei_connect_client_data))) {
622 dev_dbg(&dev->pdev->dev, "failed to copy data to userland\n");
623 rets = -EFAULT;
624 goto out;
625 }
626
627out:
628 kfree(connect_data);
629 mutex_unlock(&dev->device_lock);
630 return rets;
631}
632
633/**
634 * mei_compat_ioctl - the compat IOCTL function
635 *
636 * @file: pointer to file structure
637 * @cmd: ioctl command
638 * @data: pointer to mei message structure
639 *
640 * returns 0 on success , <0 on error
641 */
642#ifdef CONFIG_COMPAT
643static long mei_compat_ioctl(struct file *file,
Tomas Winkler441ab502011-12-13 23:39:34 +0200644 unsigned int cmd, unsigned long data)
Oren Weilab841162011-05-15 13:43:41 +0300645{
646 return mei_ioctl(file, cmd, (unsigned long)compat_ptr(data));
647}
648#endif
649
650
651/**
652 * mei_poll - the poll function
653 *
654 * @file: pointer to file structure
655 * @wait: pointer to poll_table structure
656 *
657 * returns poll mask
658 */
659static unsigned int mei_poll(struct file *file, poll_table *wait)
660{
661 struct mei_cl *cl = file->private_data;
662 struct mei_device *dev;
663 unsigned int mask = 0;
664
665 if (WARN_ON(!cl || !cl->dev))
666 return mask;
667
668 dev = cl->dev;
669
670 mutex_lock(&dev->device_lock);
671
Tomas Winklerb210d752012-08-07 00:03:56 +0300672 if (dev->dev_state != MEI_DEV_ENABLED)
Oren Weilab841162011-05-15 13:43:41 +0300673 goto out;
674
675
676 if (cl == &dev->iamthif_cl) {
Tomas Winkler744f0f22012-11-11 17:38:02 +0200677 mask = mei_amthif_poll(dev, file, wait);
Oren Weilab841162011-05-15 13:43:41 +0300678 goto out;
679 }
680
681 mutex_unlock(&dev->device_lock);
682 poll_wait(file, &cl->tx_wait, wait);
683 mutex_lock(&dev->device_lock);
684 if (MEI_WRITE_COMPLETE == cl->writing_state)
685 mask |= (POLLIN | POLLRDNORM);
686
687out:
688 mutex_unlock(&dev->device_lock);
689 return mask;
690}
691
Oren Weil5b881e32011-11-13 09:41:14 +0200692/*
693 * file operations structure will be used for mei char device.
694 */
695static const struct file_operations mei_fops = {
696 .owner = THIS_MODULE,
697 .read = mei_read,
698 .unlocked_ioctl = mei_ioctl,
699#ifdef CONFIG_COMPAT
700 .compat_ioctl = mei_compat_ioctl,
701#endif
702 .open = mei_open,
703 .release = mei_release,
704 .write = mei_write,
705 .poll = mei_poll,
706 .llseek = no_llseek
707};
708
709
710/*
711 * Misc Device Struct
712 */
713static struct miscdevice mei_misc_device = {
Tomas Winklerc38ea242012-04-02 20:32:39 +0300714 .name = "mei",
Oren Weil5b881e32011-11-13 09:41:14 +0200715 .fops = &mei_fops,
716 .minor = MISC_DYNAMIC_MINOR,
717};
718
719/**
Tomas Winkler9a123f12012-08-06 15:23:55 +0300720 * mei_quirk_probe - probe for devices that doesn't valid ME interface
721 * @pdev: PCI device structure
722 * @ent: entry into pci_device_table
723 *
724 * returns true if ME Interface is valid, false otherwise
725 */
Bill Pemberton80c8ae22012-11-19 13:23:05 -0500726static bool mei_quirk_probe(struct pci_dev *pdev,
Tomas Winkler9a123f12012-08-06 15:23:55 +0300727 const struct pci_device_id *ent)
728{
729 u32 reg;
730 if (ent->device == MEI_DEV_ID_PBG_1) {
731 pci_read_config_dword(pdev, 0x48, &reg);
732 /* make sure that bit 9 is up and bit 10 is down */
733 if ((reg & 0x600) == 0x200) {
734 dev_info(&pdev->dev, "Device doesn't have valid ME Interface\n");
735 return false;
736 }
737 }
738 return true;
739}
740/**
Oren Weil5b881e32011-11-13 09:41:14 +0200741 * mei_probe - Device Initialization Routine
742 *
743 * @pdev: PCI device structure
744 * @ent: entry in kcs_pci_tbl
745 *
746 * returns 0 on success, <0 on failure.
747 */
Bill Pemberton80c8ae22012-11-19 13:23:05 -0500748static int mei_probe(struct pci_dev *pdev,
Oren Weil5b881e32011-11-13 09:41:14 +0200749 const struct pci_device_id *ent)
750{
751 struct mei_device *dev;
752 int err;
753
754 mutex_lock(&mei_mutex);
Tomas Winkler9a123f12012-08-06 15:23:55 +0300755
756 if (!mei_quirk_probe(pdev, ent)) {
757 err = -ENODEV;
758 goto end;
759 }
760
Tomas Winklerdaed6b52012-08-17 09:54:23 +0300761 if (mei_pdev) {
Oren Weil5b881e32011-11-13 09:41:14 +0200762 err = -EEXIST;
763 goto end;
764 }
765 /* enable pci dev */
766 err = pci_enable_device(pdev);
767 if (err) {
Tomas Winkler32c826b2012-05-08 23:04:56 +0300768 dev_err(&pdev->dev, "failed to enable pci device.\n");
Oren Weil5b881e32011-11-13 09:41:14 +0200769 goto end;
770 }
771 /* set PCI host mastering */
772 pci_set_master(pdev);
773 /* pci request regions for mei driver */
Tomas Winkler068c0ae2012-08-07 00:03:54 +0300774 err = pci_request_regions(pdev, KBUILD_MODNAME);
Oren Weil5b881e32011-11-13 09:41:14 +0200775 if (err) {
Tomas Winkler32c826b2012-05-08 23:04:56 +0300776 dev_err(&pdev->dev, "failed to get pci regions.\n");
Oren Weil5b881e32011-11-13 09:41:14 +0200777 goto disable_device;
778 }
779 /* allocates and initializes the mei dev structure */
780 dev = mei_device_init(pdev);
781 if (!dev) {
782 err = -ENOMEM;
783 goto release_regions;
784 }
785 /* mapping IO device memory */
786 dev->mem_addr = pci_iomap(pdev, 0, 0);
787 if (!dev->mem_addr) {
Tomas Winkler32c826b2012-05-08 23:04:56 +0300788 dev_err(&pdev->dev, "mapping I/O device memory failure.\n");
Oren Weil5b881e32011-11-13 09:41:14 +0200789 err = -ENOMEM;
790 goto free_device;
791 }
792 pci_enable_msi(pdev);
793
794 /* request and enable interrupt */
795 if (pci_dev_msi_enabled(pdev))
796 err = request_threaded_irq(pdev->irq,
797 NULL,
798 mei_interrupt_thread_handler,
Tomas Winkler068c0ae2012-08-07 00:03:54 +0300799 IRQF_ONESHOT, KBUILD_MODNAME, dev);
Oren Weil5b881e32011-11-13 09:41:14 +0200800 else
801 err = request_threaded_irq(pdev->irq,
802 mei_interrupt_quick_handler,
803 mei_interrupt_thread_handler,
Tomas Winkler068c0ae2012-08-07 00:03:54 +0300804 IRQF_SHARED, KBUILD_MODNAME, dev);
Oren Weil5b881e32011-11-13 09:41:14 +0200805
806 if (err) {
Tomas Winkler32c826b2012-05-08 23:04:56 +0300807 dev_err(&pdev->dev, "request_threaded_irq failure. irq = %d\n",
Oren Weil5b881e32011-11-13 09:41:14 +0200808 pdev->irq);
Samuel Ortiz169dc382012-06-11 12:18:30 +0300809 goto disable_msi;
Oren Weil5b881e32011-11-13 09:41:14 +0200810 }
811 INIT_DELAYED_WORK(&dev->timer_work, mei_timer);
Samuel Ortizc1174c02012-11-18 15:13:20 +0200812 INIT_WORK(&dev->init_work, mei_host_client_init);
813
Oren Weil5b881e32011-11-13 09:41:14 +0200814 if (mei_hw_init(dev)) {
Tomas Winkler32c826b2012-05-08 23:04:56 +0300815 dev_err(&pdev->dev, "init hw failure.\n");
Oren Weil5b881e32011-11-13 09:41:14 +0200816 err = -ENODEV;
817 goto release_irq;
818 }
819
820 err = misc_register(&mei_misc_device);
821 if (err)
822 goto release_irq;
823
Tomas Winklerdaed6b52012-08-17 09:54:23 +0300824 mei_pdev = pdev;
Oren Weil5b881e32011-11-13 09:41:14 +0200825 pci_set_drvdata(pdev, dev);
826
827
828 schedule_delayed_work(&dev->timer_work, HZ);
829
830 mutex_unlock(&mei_mutex);
831
Tomas Winkler2f3d2b42012-03-19 22:38:13 +0200832 pr_debug("initialization successful.\n");
Oren Weil5b881e32011-11-13 09:41:14 +0200833
834 return 0;
835
836release_irq:
837 /* disable interrupts */
838 dev->host_hw_state = mei_hcsr_read(dev);
839 mei_disable_interrupts(dev);
840 flush_scheduled_work();
841 free_irq(pdev->irq, dev);
Samuel Ortiz169dc382012-06-11 12:18:30 +0300842disable_msi:
Oren Weil5b881e32011-11-13 09:41:14 +0200843 pci_disable_msi(pdev);
Oren Weil5b881e32011-11-13 09:41:14 +0200844 pci_iounmap(pdev, dev->mem_addr);
845free_device:
846 kfree(dev);
847release_regions:
848 pci_release_regions(pdev);
849disable_device:
850 pci_disable_device(pdev);
851end:
852 mutex_unlock(&mei_mutex);
Tomas Winkler32c826b2012-05-08 23:04:56 +0300853 dev_err(&pdev->dev, "initialization failed.\n");
Oren Weil5b881e32011-11-13 09:41:14 +0200854 return err;
855}
856
857/**
858 * mei_remove - Device Removal Routine
859 *
860 * @pdev: PCI device structure
861 *
862 * mei_remove is called by the PCI subsystem to alert the driver
863 * that it should release a PCI device.
864 */
Bill Pemberton486a5c22012-11-19 13:26:02 -0500865static void mei_remove(struct pci_dev *pdev)
Oren Weil5b881e32011-11-13 09:41:14 +0200866{
867 struct mei_device *dev;
868
Tomas Winklerdaed6b52012-08-17 09:54:23 +0300869 if (mei_pdev != pdev)
Oren Weil5b881e32011-11-13 09:41:14 +0200870 return;
871
872 dev = pci_get_drvdata(pdev);
873 if (!dev)
874 return;
875
876 mutex_lock(&dev->device_lock);
877
Tomas Winklerc216fde2012-08-16 19:39:43 +0300878 cancel_delayed_work(&dev->timer_work);
879
880 mei_wd_stop(dev);
Oren Weil5b881e32011-11-13 09:41:14 +0200881
Tomas Winklerdaed6b52012-08-17 09:54:23 +0300882 mei_pdev = NULL;
Oren Weil5b881e32011-11-13 09:41:14 +0200883
884 if (dev->iamthif_cl.state == MEI_FILE_CONNECTED) {
885 dev->iamthif_cl.state = MEI_FILE_DISCONNECTING;
Tomas Winkler90e0b5f2013-01-08 23:07:14 +0200886 mei_cl_disconnect(&dev->iamthif_cl);
Oren Weil5b881e32011-11-13 09:41:14 +0200887 }
888 if (dev->wd_cl.state == MEI_FILE_CONNECTED) {
889 dev->wd_cl.state = MEI_FILE_DISCONNECTING;
Tomas Winkler90e0b5f2013-01-08 23:07:14 +0200890 mei_cl_disconnect(&dev->wd_cl);
Oren Weil5b881e32011-11-13 09:41:14 +0200891 }
892
893 /* Unregistering watchdog device */
Tomas Winkler70cd5332011-12-22 18:50:50 +0200894 mei_watchdog_unregister(dev);
Oren Weil5b881e32011-11-13 09:41:14 +0200895
896 /* remove entry if already in list */
897 dev_dbg(&pdev->dev, "list del iamthif and wd file list.\n");
Tomas Winkler90e0b5f2013-01-08 23:07:14 +0200898 mei_cl_unlink(&dev->wd_cl);
899 mei_cl_unlink(&dev->iamthif_cl);
Oren Weil5b881e32011-11-13 09:41:14 +0200900
901 dev->iamthif_current_cb = NULL;
902 dev->me_clients_num = 0;
903
904 mutex_unlock(&dev->device_lock);
905
906 flush_scheduled_work();
907
908 /* disable interrupts */
909 mei_disable_interrupts(dev);
910
911 free_irq(pdev->irq, dev);
912 pci_disable_msi(pdev);
913 pci_set_drvdata(pdev, NULL);
914
915 if (dev->mem_addr)
916 pci_iounmap(pdev, dev->mem_addr);
917
918 kfree(dev);
919
920 pci_release_regions(pdev);
921 pci_disable_device(pdev);
Tomas Winklera44cab42012-05-29 16:39:11 +0300922
923 misc_deregister(&mei_misc_device);
Oren Weil5b881e32011-11-13 09:41:14 +0200924}
Oren Weilab841162011-05-15 13:43:41 +0300925#ifdef CONFIG_PM
926static int mei_pci_suspend(struct device *device)
927{
928 struct pci_dev *pdev = to_pci_dev(device);
929 struct mei_device *dev = pci_get_drvdata(pdev);
930 int err;
931
932 if (!dev)
933 return -ENODEV;
934 mutex_lock(&dev->device_lock);
Tomas Winklerc216fde2012-08-16 19:39:43 +0300935
936 cancel_delayed_work(&dev->timer_work);
937
Oren Weilab841162011-05-15 13:43:41 +0300938 /* Stop watchdog if exists */
Tomas Winklerc216fde2012-08-16 19:39:43 +0300939 err = mei_wd_stop(dev);
Oren Weilab841162011-05-15 13:43:41 +0300940 /* Set new mei state */
Tomas Winklerb210d752012-08-07 00:03:56 +0300941 if (dev->dev_state == MEI_DEV_ENABLED ||
942 dev->dev_state == MEI_DEV_RECOVERING_FROM_RESET) {
943 dev->dev_state = MEI_DEV_POWER_DOWN;
Oren Weilab841162011-05-15 13:43:41 +0300944 mei_reset(dev, 0);
945 }
946 mutex_unlock(&dev->device_lock);
947
948 free_irq(pdev->irq, dev);
Tomas Winkler4f61a7a2011-07-14 20:11:25 +0300949 pci_disable_msi(pdev);
Oren Weilab841162011-05-15 13:43:41 +0300950
951 return err;
952}
953
954static int mei_pci_resume(struct device *device)
955{
956 struct pci_dev *pdev = to_pci_dev(device);
957 struct mei_device *dev;
958 int err;
959
960 dev = pci_get_drvdata(pdev);
961 if (!dev)
962 return -ENODEV;
963
Tomas Winkler4f61a7a2011-07-14 20:11:25 +0300964 pci_enable_msi(pdev);
965
966 /* request and enable interrupt */
967 if (pci_dev_msi_enabled(pdev))
968 err = request_threaded_irq(pdev->irq,
969 NULL,
970 mei_interrupt_thread_handler,
Tomas Winkler068c0ae2012-08-07 00:03:54 +0300971 IRQF_ONESHOT, KBUILD_MODNAME, dev);
Tomas Winkler4f61a7a2011-07-14 20:11:25 +0300972 else
973 err = request_threaded_irq(pdev->irq,
Oren Weilab841162011-05-15 13:43:41 +0300974 mei_interrupt_quick_handler,
975 mei_interrupt_thread_handler,
Tomas Winkler068c0ae2012-08-07 00:03:54 +0300976 IRQF_SHARED, KBUILD_MODNAME, dev);
Tomas Winkler4f61a7a2011-07-14 20:11:25 +0300977
Oren Weilab841162011-05-15 13:43:41 +0300978 if (err) {
Tomas Winkler32c826b2012-05-08 23:04:56 +0300979 dev_err(&pdev->dev, "request_threaded_irq failed: irq = %d.\n",
980 pdev->irq);
Oren Weilab841162011-05-15 13:43:41 +0300981 return err;
982 }
983
984 mutex_lock(&dev->device_lock);
Tomas Winklerb210d752012-08-07 00:03:56 +0300985 dev->dev_state = MEI_DEV_POWER_UP;
Oren Weilab841162011-05-15 13:43:41 +0300986 mei_reset(dev, 1);
987 mutex_unlock(&dev->device_lock);
988
Oren Weil6d70e932011-09-07 09:03:14 +0300989 /* Start timer if stopped in suspend */
990 schedule_delayed_work(&dev->timer_work, HZ);
991
Oren Weilab841162011-05-15 13:43:41 +0300992 return err;
993}
994static SIMPLE_DEV_PM_OPS(mei_pm_ops, mei_pci_suspend, mei_pci_resume);
995#define MEI_PM_OPS (&mei_pm_ops)
996#else
Randy Dunlap2d990362011-05-19 08:52:34 -0700997#define MEI_PM_OPS NULL
Oren Weilab841162011-05-15 13:43:41 +0300998#endif /* CONFIG_PM */
999/*
1000 * PCI driver structure
1001 */
1002static struct pci_driver mei_driver = {
Tomas Winkler068c0ae2012-08-07 00:03:54 +03001003 .name = KBUILD_MODNAME,
Oren Weilab841162011-05-15 13:43:41 +03001004 .id_table = mei_pci_tbl,
1005 .probe = mei_probe,
Bill Pemberton9306a8b2012-11-19 13:20:25 -05001006 .remove = mei_remove,
1007 .shutdown = mei_remove,
Oren Weilab841162011-05-15 13:43:41 +03001008 .driver.pm = MEI_PM_OPS,
1009};
1010
Tomas Winkler60781882012-07-19 09:45:32 +03001011module_pci_driver(mei_driver);
Oren Weilab841162011-05-15 13:43:41 +03001012
1013MODULE_AUTHOR("Intel Corporation");
1014MODULE_DESCRIPTION("Intel(R) Management Engine Interface");
1015MODULE_LICENSE("GPL v2");