blob: 5c557dd129d6bd9b6876ad5889a21a5523639395 [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
40#include "mei_dev.h"
Tomas Winkler4f3afe12012-05-09 16:38:59 +030041#include <linux/mei.h>
Oren Weilab841162011-05-15 13:43:41 +030042#include "interface.h"
Oren Weilab841162011-05-15 13:43:41 +030043
Oren Weilab841162011-05-15 13:43:41 +030044/* The device pointer */
45/* Currently this driver works as long as there is only a single AMT device. */
Oren Weil4a3cafd2011-09-07 09:03:10 +030046struct pci_dev *mei_device;
Oren Weilab841162011-05-15 13:43:41 +030047
Oren Weilab841162011-05-15 13:43:41 +030048/* mei_pci_tbl - PCI Device ID Table */
49static DEFINE_PCI_DEVICE_TABLE(mei_pci_tbl) = {
50 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82946GZ)},
51 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82G35)},
52 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82Q965)},
53 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82G965)},
54 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82GM965)},
55 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82GME965)},
56 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_82Q35)},
57 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_82G33)},
58 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_82Q33)},
59 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_82X38)},
60 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_3200)},
61 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_6)},
62 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_7)},
63 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_8)},
64 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_9)},
65 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_10)},
66 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9M_1)},
67 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9M_2)},
68 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9M_3)},
69 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9M_4)},
70 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH10_1)},
71 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH10_2)},
72 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH10_3)},
73 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH10_4)},
74 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_IBXPK_1)},
75 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_IBXPK_2)},
76 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_CPT_1)},
77 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_PBG_1)},
78 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_PPT_1)},
79 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_PPT_2)},
80 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_PPT_3)},
81
82 /* required last entry */
83 {0, }
84};
85
86MODULE_DEVICE_TABLE(pci, mei_pci_tbl);
87
88static DEFINE_MUTEX(mei_mutex);
89
Oren Weilab841162011-05-15 13:43:41 +030090
91/**
92 * mei_clear_list - removes all callbacks associated with file
93 * from mei_cb_list
94 *
95 * @dev: device structure.
96 * @file: file structure
97 * @mei_cb_list: callbacks list
98 *
99 * mei_clear_list is called to clear resources associated with file
100 * when application calls close function or Ctrl-C was pressed
101 *
102 * returns true if callback removed from the list, false otherwise
103 */
104static bool mei_clear_list(struct mei_device *dev,
105 struct file *file, struct list_head *mei_cb_list)
106{
107 struct mei_cl_cb *cb_pos = NULL;
108 struct mei_cl_cb *cb_next = NULL;
109 struct file *file_temp;
110 bool removed = false;
111
112 /* list all list member */
113 list_for_each_entry_safe(cb_pos, cb_next, mei_cb_list, cb_list) {
114 file_temp = (struct file *)cb_pos->file_object;
115 /* check if list member associated with a file */
116 if (file_temp == file) {
117 /* remove member from the list */
118 list_del(&cb_pos->cb_list);
119 /* check if cb equal to current iamthif cb */
120 if (dev->iamthif_current_cb == cb_pos) {
121 dev->iamthif_current_cb = NULL;
122 /* send flow control to iamthif client */
123 mei_send_flow_control(dev, &dev->iamthif_cl);
124 }
125 /* free all allocated buffers */
126 mei_free_cb_private(cb_pos);
127 cb_pos = NULL;
128 removed = true;
129 }
130 }
131 return removed;
132}
133
134/**
135 * mei_clear_lists - removes all callbacks associated with file
136 *
137 * @dev: device structure
138 * @file: file structure
139 *
140 * mei_clear_lists is called to clear resources associated with file
141 * when application calls close function or Ctrl-C was pressed
142 *
143 * returns true if callback removed from the list, false otherwise
144 */
145static bool mei_clear_lists(struct mei_device *dev, struct file *file)
146{
147 bool removed = false;
148
149 /* remove callbacks associated with a file */
150 mei_clear_list(dev, file, &dev->amthi_cmd_list.mei_cb.cb_list);
151 if (mei_clear_list(dev, file,
152 &dev->amthi_read_complete_list.mei_cb.cb_list))
153 removed = true;
154
155 mei_clear_list(dev, file, &dev->ctrl_rd_list.mei_cb.cb_list);
156
157 if (mei_clear_list(dev, file, &dev->ctrl_wr_list.mei_cb.cb_list))
158 removed = true;
159
160 if (mei_clear_list(dev, file, &dev->write_waiting_list.mei_cb.cb_list))
161 removed = true;
162
163 if (mei_clear_list(dev, file, &dev->write_list.mei_cb.cb_list))
164 removed = true;
165
166 /* check if iamthif_current_cb not NULL */
167 if (dev->iamthif_current_cb && !removed) {
168 /* check file and iamthif current cb association */
169 if (dev->iamthif_current_cb->file_object == file) {
170 /* remove cb */
171 mei_free_cb_private(dev->iamthif_current_cb);
172 dev->iamthif_current_cb = NULL;
173 removed = true;
174 }
175 }
176 return removed;
177}
178/**
179 * find_read_list_entry - find read list entry
180 *
181 * @dev: device structure
182 * @file: pointer to file structure
183 *
184 * returns cb on success, NULL on error
185 */
186static struct mei_cl_cb *find_read_list_entry(
187 struct mei_device *dev,
188 struct mei_cl *cl)
189{
Tomas Winklerb7cd2d92011-11-27 21:43:34 +0200190 struct mei_cl_cb *pos = NULL;
191 struct mei_cl_cb *next = NULL;
Oren Weilab841162011-05-15 13:43:41 +0300192
Tomas Winklerb7cd2d92011-11-27 21:43:34 +0200193 dev_dbg(&dev->pdev->dev, "remove read_list CB\n");
194 list_for_each_entry_safe(pos, next,
195 &dev->read_list.mei_cb.cb_list, cb_list) {
196 struct mei_cl *cl_temp;
197 cl_temp = (struct mei_cl *)pos->file_private;
Oren Weilab841162011-05-15 13:43:41 +0300198
Tomas Winklerb7cd2d92011-11-27 21:43:34 +0200199 if (mei_cl_cmp_id(cl, cl_temp))
200 return pos;
Oren Weilab841162011-05-15 13:43:41 +0300201 }
202 return NULL;
203}
204
205/**
206 * mei_open - the open function
207 *
208 * @inode: pointer to inode structure
209 * @file: pointer to file structure
210 *
211 * returns 0 on success, <0 on error
212 */
213static int mei_open(struct inode *inode, struct file *file)
214{
215 struct mei_cl *cl;
Oren Weilab841162011-05-15 13:43:41 +0300216 struct mei_device *dev;
Tomas Winkler6f37aca2011-11-13 09:41:15 +0200217 unsigned long cl_id;
218 int err;
Oren Weilab841162011-05-15 13:43:41 +0300219
220 err = -ENODEV;
221 if (!mei_device)
222 goto out;
223
224 dev = pci_get_drvdata(mei_device);
Oren Weil5b881e32011-11-13 09:41:14 +0200225 if (!dev)
Oren Weilab841162011-05-15 13:43:41 +0300226 goto out;
227
228 mutex_lock(&dev->device_lock);
229 err = -ENOMEM;
Tomas Winklerc95efb72011-05-25 17:28:21 +0300230 cl = mei_cl_allocate(dev);
Oren Weilab841162011-05-15 13:43:41 +0300231 if (!cl)
Alexey Khoroshilov303dfbf2011-08-31 00:41:14 +0400232 goto out_unlock;
Oren Weilab841162011-05-15 13:43:41 +0300233
234 err = -ENODEV;
Tomas Winklerb210d752012-08-07 00:03:56 +0300235 if (dev->dev_state != MEI_DEV_ENABLED) {
236 dev_dbg(&dev->pdev->dev, "dev_state != MEI_ENABLED dev_state = %s\n",
237 mei_dev_state_str(dev->dev_state));
Oren Weilab841162011-05-15 13:43:41 +0300238 goto out_unlock;
239 }
240 err = -EMFILE;
241 if (dev->open_handle_count >= MEI_MAX_OPEN_HANDLE_COUNT)
242 goto out_unlock;
243
Tomas Winkler6f37aca2011-11-13 09:41:15 +0200244 cl_id = find_first_zero_bit(dev->host_clients_map, MEI_CLIENTS_MAX);
245 if (cl_id >= MEI_CLIENTS_MAX)
Oren Weilab841162011-05-15 13:43:41 +0300246 goto out_unlock;
247
Tomas Winkler6f37aca2011-11-13 09:41:15 +0200248 cl->host_client_id = cl_id;
249
Oren Weilab841162011-05-15 13:43:41 +0300250 dev_dbg(&dev->pdev->dev, "client_id = %d\n", cl->host_client_id);
251
252 dev->open_handle_count++;
Tomas Winkler6f37aca2011-11-13 09:41:15 +0200253
Oren Weilab841162011-05-15 13:43:41 +0300254 list_add_tail(&cl->link, &dev->file_list);
255
256 set_bit(cl->host_client_id, dev->host_clients_map);
257 cl->state = MEI_FILE_INITIALIZING;
258 cl->sm_state = 0;
259
260 file->private_data = cl;
261 mutex_unlock(&dev->device_lock);
262
Oren Weil5b881e32011-11-13 09:41:14 +0200263 return nonseekable_open(inode, file);
Oren Weilab841162011-05-15 13:43:41 +0300264
265out_unlock:
266 mutex_unlock(&dev->device_lock);
267 kfree(cl);
268out:
269 return err;
270}
271
272/**
273 * mei_release - the release function
274 *
275 * @inode: pointer to inode structure
276 * @file: pointer to file structure
277 *
278 * returns 0 on success, <0 on error
279 */
280static int mei_release(struct inode *inode, struct file *file)
281{
282 struct mei_cl *cl = file->private_data;
283 struct mei_cl_cb *cb;
284 struct mei_device *dev;
285 int rets = 0;
286
287 if (WARN_ON(!cl || !cl->dev))
288 return -ENODEV;
289
290 dev = cl->dev;
291
292 mutex_lock(&dev->device_lock);
293 if (cl != &dev->iamthif_cl) {
294 if (cl->state == MEI_FILE_CONNECTED) {
295 cl->state = MEI_FILE_DISCONNECTING;
296 dev_dbg(&dev->pdev->dev,
297 "disconnecting client host client = %d, "
298 "ME client = %d\n",
299 cl->host_client_id,
300 cl->me_client_id);
301 rets = mei_disconnect_host_client(dev, cl);
302 }
Tomas Winkler0288c7c2011-06-06 10:44:34 +0300303 mei_cl_flush_queues(cl);
Oren Weilab841162011-05-15 13:43:41 +0300304 dev_dbg(&dev->pdev->dev, "remove client host client = %d, ME client = %d\n",
305 cl->host_client_id,
306 cl->me_client_id);
307
308 if (dev->open_handle_count > 0) {
Tomas Winkler441ab502011-12-13 23:39:34 +0200309 clear_bit(cl->host_client_id, dev->host_clients_map);
Oren Weilab841162011-05-15 13:43:41 +0300310 dev->open_handle_count--;
311 }
312 mei_remove_client_from_file_list(dev, cl->host_client_id);
313
314 /* free read cb */
315 cb = NULL;
316 if (cl->read_cb) {
317 cb = find_read_list_entry(dev, cl);
318 /* Remove entry from read list */
319 if (cb)
320 list_del(&cb->cb_list);
321
322 cb = cl->read_cb;
323 cl->read_cb = NULL;
324 }
325
326 file->private_data = NULL;
327
328 if (cb) {
329 mei_free_cb_private(cb);
330 cb = NULL;
331 }
332
333 kfree(cl);
334 } else {
335 if (dev->open_handle_count > 0)
336 dev->open_handle_count--;
337
338 if (dev->iamthif_file_object == file &&
339 dev->iamthif_state != MEI_IAMTHIF_IDLE) {
340
341 dev_dbg(&dev->pdev->dev, "amthi canceled iamthif state %d\n",
342 dev->iamthif_state);
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300343 dev->iamthif_canceled = true;
Oren Weilab841162011-05-15 13:43:41 +0300344 if (dev->iamthif_state == MEI_IAMTHIF_READ_COMPLETE) {
345 dev_dbg(&dev->pdev->dev, "run next amthi iamthif cb\n");
Tomas Winklerc95efb72011-05-25 17:28:21 +0300346 mei_run_next_iamthif_cmd(dev);
Oren Weilab841162011-05-15 13:43:41 +0300347 }
348 }
349
350 if (mei_clear_lists(dev, file))
351 dev->iamthif_state = MEI_IAMTHIF_IDLE;
352
353 }
354 mutex_unlock(&dev->device_lock);
355 return rets;
356}
357
358
359/**
360 * mei_read - the read function.
361 *
362 * @file: pointer to file structure
363 * @ubuf: pointer to user buffer
364 * @length: buffer length
365 * @offset: data offset in buffer
366 *
367 * returns >=0 data length on success , <0 on error
368 */
369static ssize_t mei_read(struct file *file, char __user *ubuf,
Tomas Winkler441ab502011-12-13 23:39:34 +0200370 size_t length, loff_t *offset)
Oren Weilab841162011-05-15 13:43:41 +0300371{
372 struct mei_cl *cl = file->private_data;
373 struct mei_cl_cb *cb_pos = NULL;
374 struct mei_cl_cb *cb = NULL;
375 struct mei_device *dev;
376 int i;
377 int rets;
378 int err;
379
380
381 if (WARN_ON(!cl || !cl->dev))
382 return -ENODEV;
383
384 dev = cl->dev;
385
386 mutex_lock(&dev->device_lock);
Tomas Winklerb210d752012-08-07 00:03:56 +0300387 if (dev->dev_state != MEI_DEV_ENABLED) {
Oren Weilab841162011-05-15 13:43:41 +0300388 rets = -ENODEV;
389 goto out;
390 }
391
392 if ((cl->sm_state & MEI_WD_STATE_INDEPENDENCE_MSG_SENT) == 0) {
393 /* Do not allow to read watchdog client */
Tomas Winkler07b509b2012-07-23 14:05:39 +0300394 i = mei_me_cl_by_uuid(dev, &mei_wd_guid);
Oren Weilab841162011-05-15 13:43:41 +0300395 if (i >= 0) {
396 struct mei_me_client *me_client = &dev->me_clients[i];
Oren Weilab841162011-05-15 13:43:41 +0300397 if (cl->me_client_id == me_client->client_id) {
398 rets = -EBADF;
399 goto out;
400 }
401 }
402 } else {
403 cl->sm_state &= ~MEI_WD_STATE_INDEPENDENCE_MSG_SENT;
404 }
405
406 if (cl == &dev->iamthif_cl) {
407 rets = amthi_read(dev, file, ubuf, length, offset);
408 goto out;
409 }
410
411 if (cl->read_cb && cl->read_cb->information > *offset) {
412 cb = cl->read_cb;
413 goto copy_buffer;
414 } else if (cl->read_cb && cl->read_cb->information > 0 &&
415 cl->read_cb->information <= *offset) {
416 cb = cl->read_cb;
417 rets = 0;
418 goto free;
419 } else if ((!cl->read_cb || !cl->read_cb->information) &&
420 *offset > 0) {
Justin P. Mattock5f9092f32012-03-12 07:18:09 -0700421 /*Offset needs to be cleaned for contiguous reads*/
Oren Weilab841162011-05-15 13:43:41 +0300422 *offset = 0;
423 rets = 0;
424 goto out;
425 }
426
427 err = mei_start_read(dev, cl);
428 if (err && err != -EBUSY) {
429 dev_dbg(&dev->pdev->dev,
430 "mei start read failure with status = %d\n", err);
431 rets = err;
432 goto out;
433 }
434
435 if (MEI_READ_COMPLETE != cl->reading_state &&
436 !waitqueue_active(&cl->rx_wait)) {
437 if (file->f_flags & O_NONBLOCK) {
438 rets = -EAGAIN;
439 goto out;
440 }
441
442 mutex_unlock(&dev->device_lock);
443
444 if (wait_event_interruptible(cl->rx_wait,
445 (MEI_READ_COMPLETE == cl->reading_state ||
446 MEI_FILE_INITIALIZING == cl->state ||
447 MEI_FILE_DISCONNECTED == cl->state ||
448 MEI_FILE_DISCONNECTING == cl->state))) {
449 if (signal_pending(current))
450 return -EINTR;
451 return -ERESTARTSYS;
452 }
453
454 mutex_lock(&dev->device_lock);
455 if (MEI_FILE_INITIALIZING == cl->state ||
456 MEI_FILE_DISCONNECTED == cl->state ||
457 MEI_FILE_DISCONNECTING == cl->state) {
458 rets = -EBUSY;
459 goto out;
460 }
461 }
462
463 cb = cl->read_cb;
464
465 if (!cb) {
466 rets = -ENODEV;
467 goto out;
468 }
469 if (cl->reading_state != MEI_READ_COMPLETE) {
470 rets = 0;
471 goto out;
472 }
473 /* now copy the data to user space */
474copy_buffer:
475 dev_dbg(&dev->pdev->dev, "cb->response_buffer size - %d\n",
476 cb->response_buffer.size);
477 dev_dbg(&dev->pdev->dev, "cb->information - %lu\n",
478 cb->information);
479 if (length == 0 || ubuf == NULL || *offset > cb->information) {
480 rets = -EMSGSIZE;
481 goto free;
482 }
483
Justin P. Mattock5f9092f32012-03-12 07:18:09 -0700484 /* length is being truncated to PAGE_SIZE, however, */
Oren Weilab841162011-05-15 13:43:41 +0300485 /* information size may be longer */
486 length = min_t(size_t, length, (cb->information - *offset));
487
Tomas Winkler441ab502011-12-13 23:39:34 +0200488 if (copy_to_user(ubuf, cb->response_buffer.data + *offset, length)) {
Oren Weilab841162011-05-15 13:43:41 +0300489 rets = -EFAULT;
490 goto free;
491 }
492
493 rets = length;
494 *offset += length;
495 if ((unsigned long)*offset < cb->information)
496 goto out;
497
498free:
499 cb_pos = find_read_list_entry(dev, cl);
500 /* Remove entry from read list */
501 if (cb_pos)
502 list_del(&cb_pos->cb_list);
503 mei_free_cb_private(cb);
504 cl->reading_state = MEI_IDLE;
505 cl->read_cb = NULL;
506 cl->read_pending = 0;
507out:
508 dev_dbg(&dev->pdev->dev, "end mei read rets= %d\n", rets);
509 mutex_unlock(&dev->device_lock);
510 return rets;
511}
512
513/**
514 * mei_write - the write function.
515 *
516 * @file: pointer to file structure
517 * @ubuf: pointer to user buffer
518 * @length: buffer length
519 * @offset: data offset in buffer
520 *
521 * returns >=0 data length on success , <0 on error
522 */
523static ssize_t mei_write(struct file *file, const char __user *ubuf,
Tomas Winkler441ab502011-12-13 23:39:34 +0200524 size_t length, loff_t *offset)
Oren Weilab841162011-05-15 13:43:41 +0300525{
526 struct mei_cl *cl = file->private_data;
527 struct mei_cl_cb *write_cb = NULL;
528 struct mei_msg_hdr mei_hdr;
529 struct mei_device *dev;
530 unsigned long timeout = 0;
531 int rets;
532 int i;
533
534 if (WARN_ON(!cl || !cl->dev))
535 return -ENODEV;
536
537 dev = cl->dev;
538
539 mutex_lock(&dev->device_lock);
540
Tomas Winklerb210d752012-08-07 00:03:56 +0300541 if (dev->dev_state != MEI_DEV_ENABLED) {
Oren Weilab841162011-05-15 13:43:41 +0300542 mutex_unlock(&dev->device_lock);
543 return -ENODEV;
544 }
545
546 if (cl == &dev->iamthif_cl) {
547 write_cb = find_amthi_read_list_entry(dev, file);
548
549 if (write_cb) {
550 timeout = write_cb->read_time +
551 msecs_to_jiffies(IAMTHIF_READ_TIMER);
552
553 if (time_after(jiffies, timeout) ||
554 cl->reading_state == MEI_READ_COMPLETE) {
555 *offset = 0;
556 list_del(&write_cb->cb_list);
557 mei_free_cb_private(write_cb);
558 write_cb = NULL;
559 }
560 }
561 }
562
563 /* free entry used in read */
564 if (cl->reading_state == MEI_READ_COMPLETE) {
565 *offset = 0;
566 write_cb = find_read_list_entry(dev, cl);
567 if (write_cb) {
568 list_del(&write_cb->cb_list);
569 mei_free_cb_private(write_cb);
570 write_cb = NULL;
571 cl->reading_state = MEI_IDLE;
572 cl->read_cb = NULL;
573 cl->read_pending = 0;
574 }
Tomas Winkler441ab502011-12-13 23:39:34 +0200575 } else if (cl->reading_state == MEI_IDLE && !cl->read_pending)
Oren Weilab841162011-05-15 13:43:41 +0300576 *offset = 0;
577
578
579 write_cb = kzalloc(sizeof(struct mei_cl_cb), GFP_KERNEL);
580 if (!write_cb) {
581 mutex_unlock(&dev->device_lock);
582 return -ENOMEM;
583 }
584
585 write_cb->file_object = file;
586 write_cb->file_private = cl;
587 write_cb->request_buffer.data = kmalloc(length, GFP_KERNEL);
588 rets = -ENOMEM;
589 if (!write_cb->request_buffer.data)
590 goto unlock_dev;
591
592 dev_dbg(&dev->pdev->dev, "length =%d\n", (int) length);
593
594 rets = -EFAULT;
595 if (copy_from_user(write_cb->request_buffer.data, ubuf, length))
596 goto unlock_dev;
597
598 cl->sm_state = 0;
599 if (length == 4 &&
600 ((memcmp(mei_wd_state_independence_msg[0],
601 write_cb->request_buffer.data, 4) == 0) ||
602 (memcmp(mei_wd_state_independence_msg[1],
603 write_cb->request_buffer.data, 4) == 0) ||
604 (memcmp(mei_wd_state_independence_msg[2],
605 write_cb->request_buffer.data, 4) == 0)))
606 cl->sm_state |= MEI_WD_STATE_INDEPENDENCE_MSG_SENT;
607
608 INIT_LIST_HEAD(&write_cb->cb_list);
609 if (cl == &dev->iamthif_cl) {
610 write_cb->response_buffer.data =
611 kmalloc(dev->iamthif_mtu, GFP_KERNEL);
612 if (!write_cb->response_buffer.data) {
613 rets = -ENOMEM;
614 goto unlock_dev;
615 }
Tomas Winklerb210d752012-08-07 00:03:56 +0300616 if (dev->dev_state != MEI_DEV_ENABLED) {
Oren Weilab841162011-05-15 13:43:41 +0300617 rets = -ENODEV;
618 goto unlock_dev;
619 }
Tomas Winkler07b509b2012-07-23 14:05:39 +0300620 i = mei_me_cl_by_id(dev, dev->iamthif_cl.me_client_id);
621 if (i < 0) {
Oren Weilab841162011-05-15 13:43:41 +0300622 rets = -ENODEV;
623 goto unlock_dev;
624 }
Tomas Winkler07b509b2012-07-23 14:05:39 +0300625 if (length > dev->me_clients[i].props.max_msg_length ||
Oren Weilab841162011-05-15 13:43:41 +0300626 length <= 0) {
627 rets = -EMSGSIZE;
628 goto unlock_dev;
629 }
630
631 write_cb->response_buffer.size = dev->iamthif_mtu;
632 write_cb->major_file_operations = MEI_IOCTL;
633 write_cb->information = 0;
634 write_cb->request_buffer.size = length;
635 if (dev->iamthif_cl.state != MEI_FILE_CONNECTED) {
636 rets = -ENODEV;
637 goto unlock_dev;
638 }
639
640 if (!list_empty(&dev->amthi_cmd_list.mei_cb.cb_list) ||
641 dev->iamthif_state != MEI_IAMTHIF_IDLE) {
642 dev_dbg(&dev->pdev->dev, "amthi_state = %d\n",
643 (int) dev->iamthif_state);
644 dev_dbg(&dev->pdev->dev, "add amthi cb to amthi cmd waiting list\n");
645 list_add_tail(&write_cb->cb_list,
646 &dev->amthi_cmd_list.mei_cb.cb_list);
647 rets = length;
648 } else {
649 dev_dbg(&dev->pdev->dev, "call amthi write\n");
650 rets = amthi_write(dev, write_cb);
651
652 if (rets) {
653 dev_dbg(&dev->pdev->dev, "amthi write failed with status = %d\n",
654 rets);
655 goto unlock_dev;
656 }
657 rets = length;
658 }
659 mutex_unlock(&dev->device_lock);
660 return rets;
661 }
662
663 write_cb->major_file_operations = MEI_WRITE;
664 /* make sure information is zero before we start */
665
666 write_cb->information = 0;
667 write_cb->request_buffer.size = length;
668
669 dev_dbg(&dev->pdev->dev, "host client = %d, ME client = %d\n",
670 cl->host_client_id, cl->me_client_id);
671 if (cl->state != MEI_FILE_CONNECTED) {
672 rets = -ENODEV;
673 dev_dbg(&dev->pdev->dev, "host client = %d, is not connected to ME client = %d",
674 cl->host_client_id,
675 cl->me_client_id);
676 goto unlock_dev;
677 }
Tomas Winkler07b509b2012-07-23 14:05:39 +0300678 i = mei_me_cl_by_id(dev, cl->me_client_id);
679 if (i < 0) {
Oren Weilab841162011-05-15 13:43:41 +0300680 rets = -ENODEV;
681 goto unlock_dev;
682 }
683 if (length > dev->me_clients[i].props.max_msg_length || length <= 0) {
684 rets = -EINVAL;
685 goto unlock_dev;
686 }
687 write_cb->file_private = cl;
688
689 rets = mei_flow_ctrl_creds(dev, cl);
690 if (rets < 0)
691 goto unlock_dev;
692
693 if (rets && dev->mei_host_buffer_is_empty) {
694 rets = 0;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300695 dev->mei_host_buffer_is_empty = false;
Tomas Winkler24aadc82012-06-25 23:46:27 +0300696 if (length > mei_hbuf_max_data(dev)) {
697 mei_hdr.length = mei_hbuf_max_data(dev);
Oren Weilab841162011-05-15 13:43:41 +0300698 mei_hdr.msg_complete = 0;
699 } else {
700 mei_hdr.length = length;
701 mei_hdr.msg_complete = 1;
702 }
703 mei_hdr.host_addr = cl->host_client_id;
704 mei_hdr.me_addr = cl->me_client_id;
705 mei_hdr.reserved = 0;
706 dev_dbg(&dev->pdev->dev, "call mei_write_message header=%08x.\n",
707 *((u32 *) &mei_hdr));
Tomas Winkler1ccb7b62012-03-14 14:39:42 +0200708 if (mei_write_message(dev, &mei_hdr,
Oren Weilab841162011-05-15 13:43:41 +0300709 (unsigned char *) (write_cb->request_buffer.data),
710 mei_hdr.length)) {
711 rets = -ENODEV;
712 goto unlock_dev;
713 }
714 cl->writing_state = MEI_WRITING;
715 write_cb->information = mei_hdr.length;
716 if (mei_hdr.msg_complete) {
717 if (mei_flow_ctrl_reduce(dev, cl)) {
718 rets = -ENODEV;
719 goto unlock_dev;
720 }
721 list_add_tail(&write_cb->cb_list,
722 &dev->write_waiting_list.mei_cb.cb_list);
723 } else {
724 list_add_tail(&write_cb->cb_list,
725 &dev->write_list.mei_cb.cb_list);
726 }
727
728 } else {
729
730 write_cb->information = 0;
731 cl->writing_state = MEI_WRITING;
732 list_add_tail(&write_cb->cb_list,
733 &dev->write_list.mei_cb.cb_list);
734 }
735 mutex_unlock(&dev->device_lock);
736 return length;
737
738unlock_dev:
739 mutex_unlock(&dev->device_lock);
740 mei_free_cb_private(write_cb);
741 return rets;
742}
743
744
745/**
746 * mei_ioctl - the IOCTL function
747 *
748 * @file: pointer to file structure
749 * @cmd: ioctl command
750 * @data: pointer to mei message structure
751 *
752 * returns 0 on success , <0 on error
753 */
754static long mei_ioctl(struct file *file, unsigned int cmd, unsigned long data)
755{
756 struct mei_device *dev;
757 struct mei_cl *cl = file->private_data;
758 struct mei_connect_client_data *connect_data = NULL;
759 int rets;
760
761 if (cmd != IOCTL_MEI_CONNECT_CLIENT)
762 return -EINVAL;
763
764 if (WARN_ON(!cl || !cl->dev))
765 return -ENODEV;
766
767 dev = cl->dev;
768
769 dev_dbg(&dev->pdev->dev, "IOCTL cmd = 0x%x", cmd);
770
771 mutex_lock(&dev->device_lock);
Tomas Winklerb210d752012-08-07 00:03:56 +0300772 if (dev->dev_state != MEI_DEV_ENABLED) {
Oren Weilab841162011-05-15 13:43:41 +0300773 rets = -ENODEV;
774 goto out;
775 }
776
777 dev_dbg(&dev->pdev->dev, ": IOCTL_MEI_CONNECT_CLIENT.\n");
778
779 connect_data = kzalloc(sizeof(struct mei_connect_client_data),
780 GFP_KERNEL);
781 if (!connect_data) {
782 rets = -ENOMEM;
783 goto out;
784 }
785 dev_dbg(&dev->pdev->dev, "copy connect data from user\n");
786 if (copy_from_user(connect_data, (char __user *)data,
787 sizeof(struct mei_connect_client_data))) {
788 dev_dbg(&dev->pdev->dev, "failed to copy data from userland\n");
789 rets = -EFAULT;
790 goto out;
791 }
792 rets = mei_ioctl_connect_client(file, connect_data);
793
794 /* if all is ok, copying the data back to user. */
795 if (rets)
796 goto out;
797
798 dev_dbg(&dev->pdev->dev, "copy connect data to user\n");
799 if (copy_to_user((char __user *)data, connect_data,
800 sizeof(struct mei_connect_client_data))) {
801 dev_dbg(&dev->pdev->dev, "failed to copy data to userland\n");
802 rets = -EFAULT;
803 goto out;
804 }
805
806out:
807 kfree(connect_data);
808 mutex_unlock(&dev->device_lock);
809 return rets;
810}
811
812/**
813 * mei_compat_ioctl - the compat IOCTL function
814 *
815 * @file: pointer to file structure
816 * @cmd: ioctl command
817 * @data: pointer to mei message structure
818 *
819 * returns 0 on success , <0 on error
820 */
821#ifdef CONFIG_COMPAT
822static long mei_compat_ioctl(struct file *file,
Tomas Winkler441ab502011-12-13 23:39:34 +0200823 unsigned int cmd, unsigned long data)
Oren Weilab841162011-05-15 13:43:41 +0300824{
825 return mei_ioctl(file, cmd, (unsigned long)compat_ptr(data));
826}
827#endif
828
829
830/**
831 * mei_poll - the poll function
832 *
833 * @file: pointer to file structure
834 * @wait: pointer to poll_table structure
835 *
836 * returns poll mask
837 */
838static unsigned int mei_poll(struct file *file, poll_table *wait)
839{
840 struct mei_cl *cl = file->private_data;
841 struct mei_device *dev;
842 unsigned int mask = 0;
843
844 if (WARN_ON(!cl || !cl->dev))
845 return mask;
846
847 dev = cl->dev;
848
849 mutex_lock(&dev->device_lock);
850
Tomas Winklerb210d752012-08-07 00:03:56 +0300851 if (dev->dev_state != MEI_DEV_ENABLED)
Oren Weilab841162011-05-15 13:43:41 +0300852 goto out;
853
854
855 if (cl == &dev->iamthif_cl) {
856 mutex_unlock(&dev->device_lock);
857 poll_wait(file, &dev->iamthif_cl.wait, wait);
858 mutex_lock(&dev->device_lock);
859 if (dev->iamthif_state == MEI_IAMTHIF_READ_COMPLETE &&
860 dev->iamthif_file_object == file) {
861 mask |= (POLLIN | POLLRDNORM);
862 dev_dbg(&dev->pdev->dev, "run next amthi cb\n");
Tomas Winklerc95efb72011-05-25 17:28:21 +0300863 mei_run_next_iamthif_cmd(dev);
Oren Weilab841162011-05-15 13:43:41 +0300864 }
865 goto out;
866 }
867
868 mutex_unlock(&dev->device_lock);
869 poll_wait(file, &cl->tx_wait, wait);
870 mutex_lock(&dev->device_lock);
871 if (MEI_WRITE_COMPLETE == cl->writing_state)
872 mask |= (POLLIN | POLLRDNORM);
873
874out:
875 mutex_unlock(&dev->device_lock);
876 return mask;
877}
878
Oren Weil5b881e32011-11-13 09:41:14 +0200879/*
880 * file operations structure will be used for mei char device.
881 */
882static const struct file_operations mei_fops = {
883 .owner = THIS_MODULE,
884 .read = mei_read,
885 .unlocked_ioctl = mei_ioctl,
886#ifdef CONFIG_COMPAT
887 .compat_ioctl = mei_compat_ioctl,
888#endif
889 .open = mei_open,
890 .release = mei_release,
891 .write = mei_write,
892 .poll = mei_poll,
893 .llseek = no_llseek
894};
895
896
897/*
898 * Misc Device Struct
899 */
900static struct miscdevice mei_misc_device = {
Tomas Winklerc38ea242012-04-02 20:32:39 +0300901 .name = "mei",
Oren Weil5b881e32011-11-13 09:41:14 +0200902 .fops = &mei_fops,
903 .minor = MISC_DYNAMIC_MINOR,
904};
905
906/**
Tomas Winkler9a123f12012-08-06 15:23:55 +0300907 * mei_quirk_probe - probe for devices that doesn't valid ME interface
908 * @pdev: PCI device structure
909 * @ent: entry into pci_device_table
910 *
911 * returns true if ME Interface is valid, false otherwise
912 */
913static bool __devinit mei_quirk_probe(struct pci_dev *pdev,
914 const struct pci_device_id *ent)
915{
916 u32 reg;
917 if (ent->device == MEI_DEV_ID_PBG_1) {
918 pci_read_config_dword(pdev, 0x48, &reg);
919 /* make sure that bit 9 is up and bit 10 is down */
920 if ((reg & 0x600) == 0x200) {
921 dev_info(&pdev->dev, "Device doesn't have valid ME Interface\n");
922 return false;
923 }
924 }
925 return true;
926}
927/**
Oren Weil5b881e32011-11-13 09:41:14 +0200928 * mei_probe - Device Initialization Routine
929 *
930 * @pdev: PCI device structure
931 * @ent: entry in kcs_pci_tbl
932 *
933 * returns 0 on success, <0 on failure.
934 */
935static int __devinit mei_probe(struct pci_dev *pdev,
936 const struct pci_device_id *ent)
937{
938 struct mei_device *dev;
939 int err;
940
941 mutex_lock(&mei_mutex);
Tomas Winkler9a123f12012-08-06 15:23:55 +0300942
943 if (!mei_quirk_probe(pdev, ent)) {
944 err = -ENODEV;
945 goto end;
946 }
947
Oren Weil5b881e32011-11-13 09:41:14 +0200948 if (mei_device) {
949 err = -EEXIST;
950 goto end;
951 }
952 /* enable pci dev */
953 err = pci_enable_device(pdev);
954 if (err) {
Tomas Winkler32c826b2012-05-08 23:04:56 +0300955 dev_err(&pdev->dev, "failed to enable pci device.\n");
Oren Weil5b881e32011-11-13 09:41:14 +0200956 goto end;
957 }
958 /* set PCI host mastering */
959 pci_set_master(pdev);
960 /* pci request regions for mei driver */
Tomas Winkler068c0ae2012-08-07 00:03:54 +0300961 err = pci_request_regions(pdev, KBUILD_MODNAME);
Oren Weil5b881e32011-11-13 09:41:14 +0200962 if (err) {
Tomas Winkler32c826b2012-05-08 23:04:56 +0300963 dev_err(&pdev->dev, "failed to get pci regions.\n");
Oren Weil5b881e32011-11-13 09:41:14 +0200964 goto disable_device;
965 }
966 /* allocates and initializes the mei dev structure */
967 dev = mei_device_init(pdev);
968 if (!dev) {
969 err = -ENOMEM;
970 goto release_regions;
971 }
972 /* mapping IO device memory */
973 dev->mem_addr = pci_iomap(pdev, 0, 0);
974 if (!dev->mem_addr) {
Tomas Winkler32c826b2012-05-08 23:04:56 +0300975 dev_err(&pdev->dev, "mapping I/O device memory failure.\n");
Oren Weil5b881e32011-11-13 09:41:14 +0200976 err = -ENOMEM;
977 goto free_device;
978 }
979 pci_enable_msi(pdev);
980
981 /* request and enable interrupt */
982 if (pci_dev_msi_enabled(pdev))
983 err = request_threaded_irq(pdev->irq,
984 NULL,
985 mei_interrupt_thread_handler,
Tomas Winkler068c0ae2012-08-07 00:03:54 +0300986 IRQF_ONESHOT, KBUILD_MODNAME, dev);
Oren Weil5b881e32011-11-13 09:41:14 +0200987 else
988 err = request_threaded_irq(pdev->irq,
989 mei_interrupt_quick_handler,
990 mei_interrupt_thread_handler,
Tomas Winkler068c0ae2012-08-07 00:03:54 +0300991 IRQF_SHARED, KBUILD_MODNAME, dev);
Oren Weil5b881e32011-11-13 09:41:14 +0200992
993 if (err) {
Tomas Winkler32c826b2012-05-08 23:04:56 +0300994 dev_err(&pdev->dev, "request_threaded_irq failure. irq = %d\n",
Oren Weil5b881e32011-11-13 09:41:14 +0200995 pdev->irq);
Samuel Ortiz169dc382012-06-11 12:18:30 +0300996 goto disable_msi;
Oren Weil5b881e32011-11-13 09:41:14 +0200997 }
998 INIT_DELAYED_WORK(&dev->timer_work, mei_timer);
999 if (mei_hw_init(dev)) {
Tomas Winkler32c826b2012-05-08 23:04:56 +03001000 dev_err(&pdev->dev, "init hw failure.\n");
Oren Weil5b881e32011-11-13 09:41:14 +02001001 err = -ENODEV;
1002 goto release_irq;
1003 }
1004
1005 err = misc_register(&mei_misc_device);
1006 if (err)
1007 goto release_irq;
1008
1009 mei_device = pdev;
1010 pci_set_drvdata(pdev, dev);
1011
1012
1013 schedule_delayed_work(&dev->timer_work, HZ);
1014
1015 mutex_unlock(&mei_mutex);
1016
Tomas Winkler2f3d2b42012-03-19 22:38:13 +02001017 pr_debug("initialization successful.\n");
Oren Weil5b881e32011-11-13 09:41:14 +02001018
1019 return 0;
1020
1021release_irq:
1022 /* disable interrupts */
1023 dev->host_hw_state = mei_hcsr_read(dev);
1024 mei_disable_interrupts(dev);
1025 flush_scheduled_work();
1026 free_irq(pdev->irq, dev);
Samuel Ortiz169dc382012-06-11 12:18:30 +03001027disable_msi:
Oren Weil5b881e32011-11-13 09:41:14 +02001028 pci_disable_msi(pdev);
Oren Weil5b881e32011-11-13 09:41:14 +02001029 pci_iounmap(pdev, dev->mem_addr);
1030free_device:
1031 kfree(dev);
1032release_regions:
1033 pci_release_regions(pdev);
1034disable_device:
1035 pci_disable_device(pdev);
1036end:
1037 mutex_unlock(&mei_mutex);
Tomas Winkler32c826b2012-05-08 23:04:56 +03001038 dev_err(&pdev->dev, "initialization failed.\n");
Oren Weil5b881e32011-11-13 09:41:14 +02001039 return err;
1040}
1041
1042/**
1043 * mei_remove - Device Removal Routine
1044 *
1045 * @pdev: PCI device structure
1046 *
1047 * mei_remove is called by the PCI subsystem to alert the driver
1048 * that it should release a PCI device.
1049 */
1050static void __devexit mei_remove(struct pci_dev *pdev)
1051{
1052 struct mei_device *dev;
1053
1054 if (mei_device != pdev)
1055 return;
1056
1057 dev = pci_get_drvdata(pdev);
1058 if (!dev)
1059 return;
1060
1061 mutex_lock(&dev->device_lock);
1062
1063 mei_wd_stop(dev, false);
1064
1065 mei_device = NULL;
1066
1067 if (dev->iamthif_cl.state == MEI_FILE_CONNECTED) {
1068 dev->iamthif_cl.state = MEI_FILE_DISCONNECTING;
1069 mei_disconnect_host_client(dev, &dev->iamthif_cl);
1070 }
1071 if (dev->wd_cl.state == MEI_FILE_CONNECTED) {
1072 dev->wd_cl.state = MEI_FILE_DISCONNECTING;
1073 mei_disconnect_host_client(dev, &dev->wd_cl);
1074 }
1075
1076 /* Unregistering watchdog device */
Tomas Winkler70cd5332011-12-22 18:50:50 +02001077 mei_watchdog_unregister(dev);
Oren Weil5b881e32011-11-13 09:41:14 +02001078
1079 /* remove entry if already in list */
1080 dev_dbg(&pdev->dev, "list del iamthif and wd file list.\n");
1081 mei_remove_client_from_file_list(dev, dev->wd_cl.host_client_id);
1082 mei_remove_client_from_file_list(dev, dev->iamthif_cl.host_client_id);
1083
1084 dev->iamthif_current_cb = NULL;
1085 dev->me_clients_num = 0;
1086
1087 mutex_unlock(&dev->device_lock);
1088
1089 flush_scheduled_work();
1090
1091 /* disable interrupts */
1092 mei_disable_interrupts(dev);
1093
1094 free_irq(pdev->irq, dev);
1095 pci_disable_msi(pdev);
1096 pci_set_drvdata(pdev, NULL);
1097
1098 if (dev->mem_addr)
1099 pci_iounmap(pdev, dev->mem_addr);
1100
1101 kfree(dev);
1102
1103 pci_release_regions(pdev);
1104 pci_disable_device(pdev);
Tomas Winklera44cab42012-05-29 16:39:11 +03001105
1106 misc_deregister(&mei_misc_device);
Oren Weil5b881e32011-11-13 09:41:14 +02001107}
Oren Weilab841162011-05-15 13:43:41 +03001108#ifdef CONFIG_PM
1109static int mei_pci_suspend(struct device *device)
1110{
1111 struct pci_dev *pdev = to_pci_dev(device);
1112 struct mei_device *dev = pci_get_drvdata(pdev);
1113 int err;
1114
1115 if (!dev)
1116 return -ENODEV;
1117 mutex_lock(&dev->device_lock);
1118 /* Stop watchdog if exists */
1119 err = mei_wd_stop(dev, true);
1120 /* Set new mei state */
Tomas Winklerb210d752012-08-07 00:03:56 +03001121 if (dev->dev_state == MEI_DEV_ENABLED ||
1122 dev->dev_state == MEI_DEV_RECOVERING_FROM_RESET) {
1123 dev->dev_state = MEI_DEV_POWER_DOWN;
Oren Weilab841162011-05-15 13:43:41 +03001124 mei_reset(dev, 0);
1125 }
1126 mutex_unlock(&dev->device_lock);
1127
1128 free_irq(pdev->irq, dev);
Tomas Winkler4f61a7a2011-07-14 20:11:25 +03001129 pci_disable_msi(pdev);
Oren Weilab841162011-05-15 13:43:41 +03001130
1131 return err;
1132}
1133
1134static int mei_pci_resume(struct device *device)
1135{
1136 struct pci_dev *pdev = to_pci_dev(device);
1137 struct mei_device *dev;
1138 int err;
1139
1140 dev = pci_get_drvdata(pdev);
1141 if (!dev)
1142 return -ENODEV;
1143
Tomas Winkler4f61a7a2011-07-14 20:11:25 +03001144 pci_enable_msi(pdev);
1145
1146 /* request and enable interrupt */
1147 if (pci_dev_msi_enabled(pdev))
1148 err = request_threaded_irq(pdev->irq,
1149 NULL,
1150 mei_interrupt_thread_handler,
Tomas Winkler068c0ae2012-08-07 00:03:54 +03001151 IRQF_ONESHOT, KBUILD_MODNAME, dev);
Tomas Winkler4f61a7a2011-07-14 20:11:25 +03001152 else
1153 err = request_threaded_irq(pdev->irq,
Oren Weilab841162011-05-15 13:43:41 +03001154 mei_interrupt_quick_handler,
1155 mei_interrupt_thread_handler,
Tomas Winkler068c0ae2012-08-07 00:03:54 +03001156 IRQF_SHARED, KBUILD_MODNAME, dev);
Tomas Winkler4f61a7a2011-07-14 20:11:25 +03001157
Oren Weilab841162011-05-15 13:43:41 +03001158 if (err) {
Tomas Winkler32c826b2012-05-08 23:04:56 +03001159 dev_err(&pdev->dev, "request_threaded_irq failed: irq = %d.\n",
1160 pdev->irq);
Oren Weilab841162011-05-15 13:43:41 +03001161 return err;
1162 }
1163
1164 mutex_lock(&dev->device_lock);
Tomas Winklerb210d752012-08-07 00:03:56 +03001165 dev->dev_state = MEI_DEV_POWER_UP;
Oren Weilab841162011-05-15 13:43:41 +03001166 mei_reset(dev, 1);
1167 mutex_unlock(&dev->device_lock);
1168
Oren Weil6d70e932011-09-07 09:03:14 +03001169 /* Start timer if stopped in suspend */
1170 schedule_delayed_work(&dev->timer_work, HZ);
1171
Oren Weilab841162011-05-15 13:43:41 +03001172 return err;
1173}
1174static SIMPLE_DEV_PM_OPS(mei_pm_ops, mei_pci_suspend, mei_pci_resume);
1175#define MEI_PM_OPS (&mei_pm_ops)
1176#else
Randy Dunlap2d990362011-05-19 08:52:34 -07001177#define MEI_PM_OPS NULL
Oren Weilab841162011-05-15 13:43:41 +03001178#endif /* CONFIG_PM */
1179/*
1180 * PCI driver structure
1181 */
1182static struct pci_driver mei_driver = {
Tomas Winkler068c0ae2012-08-07 00:03:54 +03001183 .name = KBUILD_MODNAME,
Oren Weilab841162011-05-15 13:43:41 +03001184 .id_table = mei_pci_tbl,
1185 .probe = mei_probe,
1186 .remove = __devexit_p(mei_remove),
1187 .shutdown = __devexit_p(mei_remove),
1188 .driver.pm = MEI_PM_OPS,
1189};
1190
Tomas Winkler60781882012-07-19 09:45:32 +03001191module_pci_driver(mei_driver);
Oren Weilab841162011-05-15 13:43:41 +03001192
1193MODULE_AUTHOR("Intel Corporation");
1194MODULE_DESCRIPTION("Intel(R) Management Engine Interface");
1195MODULE_LICENSE("GPL v2");