blob: 94370d26ed450b301865e368f0c46949290782cd [file] [log] [blame]
Oren Weilfb7d8792011-05-15 13:43:42 +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 Weilfb7d8792011-05-15 13:43:42 +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
17
18#include <linux/pci.h>
19#include <linux/kthread.h>
20#include <linux/interrupt.h>
21#include <linux/fs.h>
22#include <linux/jiffies.h>
23
24#include "mei_dev.h"
Tomas Winkler4f3afe12012-05-09 16:38:59 +030025#include <linux/mei.h>
Oren Weilfb7d8792011-05-15 13:43:42 +030026#include "hw.h"
27#include "interface.h"
28
29
30/**
31 * mei_interrupt_quick_handler - The ISR of the MEI device
32 *
33 * @irq: The irq number
34 * @dev_id: pointer to the device structure
35 *
36 * returns irqreturn_t
37 */
38irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id)
39{
40 struct mei_device *dev = (struct mei_device *) dev_id;
41 u32 csr_reg = mei_hcsr_read(dev);
42
43 if ((csr_reg & H_IS) != H_IS)
44 return IRQ_NONE;
45
46 /* clear H_IS bit in H_CSR */
47 mei_reg_write(dev, H_CSR, csr_reg);
48
49 return IRQ_WAKE_THREAD;
50}
51
52/**
53 * _mei_cmpl - processes completed operation.
54 *
55 * @cl: private data of the file object.
56 * @cb_pos: callback block.
57 */
58static void _mei_cmpl(struct mei_cl *cl, struct mei_cl_cb *cb_pos)
59{
60 if (cb_pos->major_file_operations == MEI_WRITE) {
61 mei_free_cb_private(cb_pos);
62 cb_pos = NULL;
63 cl->writing_state = MEI_WRITE_COMPLETE;
64 if (waitqueue_active(&cl->tx_wait))
65 wake_up_interruptible(&cl->tx_wait);
66
67 } else if (cb_pos->major_file_operations == MEI_READ &&
68 MEI_READING == cl->reading_state) {
69 cl->reading_state = MEI_READ_COMPLETE;
70 if (waitqueue_active(&cl->rx_wait))
71 wake_up_interruptible(&cl->rx_wait);
72
73 }
74}
75
76/**
77 * _mei_cmpl_iamthif - processes completed iamthif operation.
78 *
79 * @dev: the device structure.
80 * @cb_pos: callback block.
81 */
82static void _mei_cmpl_iamthif(struct mei_device *dev, struct mei_cl_cb *cb_pos)
83{
84 if (dev->iamthif_canceled != 1) {
85 dev->iamthif_state = MEI_IAMTHIF_READ_COMPLETE;
86 dev->iamthif_stall_timer = 0;
87 memcpy(cb_pos->response_buffer.data,
88 dev->iamthif_msg_buf,
89 dev->iamthif_msg_buf_index);
90 list_add_tail(&cb_pos->cb_list,
91 &dev->amthi_read_complete_list.mei_cb.cb_list);
92 dev_dbg(&dev->pdev->dev, "amthi read completed.\n");
93 dev->iamthif_timer = jiffies;
94 dev_dbg(&dev->pdev->dev, "dev->iamthif_timer = %ld\n",
95 dev->iamthif_timer);
96 } else {
Tomas Winklerc95efb72011-05-25 17:28:21 +030097 mei_run_next_iamthif_cmd(dev);
Oren Weilfb7d8792011-05-15 13:43:42 +030098 }
99
100 dev_dbg(&dev->pdev->dev, "completing amthi call back.\n");
101 wake_up_interruptible(&dev->iamthif_cl.wait);
102}
103
104
105/**
106 * mei_irq_thread_read_amthi_message - bottom half read routine after ISR to
107 * handle the read amthi message data processing.
108 *
109 * @complete_list: An instance of our list structure
110 * @dev: the device structure
111 * @mei_hdr: header of amthi message
112 *
113 * returns 0 on success, <0 on failure.
114 */
115static int mei_irq_thread_read_amthi_message(struct mei_io_list *complete_list,
116 struct mei_device *dev,
117 struct mei_msg_hdr *mei_hdr)
118{
119 struct mei_cl *cl;
120 struct mei_cl_cb *cb;
121 unsigned char *buffer;
122
123 BUG_ON(mei_hdr->me_addr != dev->iamthif_cl.me_client_id);
124 BUG_ON(dev->iamthif_state != MEI_IAMTHIF_READING);
125
Tomas Winkleredf1eed2012-02-09 19:25:54 +0200126 buffer = dev->iamthif_msg_buf + dev->iamthif_msg_buf_index;
Oren Weilfb7d8792011-05-15 13:43:42 +0300127 BUG_ON(dev->iamthif_mtu < dev->iamthif_msg_buf_index + mei_hdr->length);
128
129 mei_read_slots(dev, buffer, mei_hdr->length);
130
131 dev->iamthif_msg_buf_index += mei_hdr->length;
132
133 if (!mei_hdr->msg_complete)
134 return 0;
135
136 dev_dbg(&dev->pdev->dev,
137 "amthi_message_buffer_index =%d\n",
138 mei_hdr->length);
139
140 dev_dbg(&dev->pdev->dev, "completed amthi read.\n ");
141 if (!dev->iamthif_current_cb)
142 return -ENODEV;
143
144 cb = dev->iamthif_current_cb;
145 dev->iamthif_current_cb = NULL;
146
147 cl = (struct mei_cl *)cb->file_private;
148 if (!cl)
149 return -ENODEV;
150
151 dev->iamthif_stall_timer = 0;
152 cb->information = dev->iamthif_msg_buf_index;
153 cb->read_time = jiffies;
154 if (dev->iamthif_ioctl && cl == &dev->iamthif_cl) {
155 /* found the iamthif cb */
156 dev_dbg(&dev->pdev->dev, "complete the amthi read cb.\n ");
157 dev_dbg(&dev->pdev->dev, "add the amthi read cb to complete.\n ");
158 list_add_tail(&cb->cb_list,
159 &complete_list->mei_cb.cb_list);
160 }
161 return 0;
162}
163
164/**
165 * _mei_irq_thread_state_ok - checks if mei header matches file private data
166 *
167 * @cl: private data of the file object
168 * @mei_hdr: header of mei client message
169 *
170 * returns !=0 if matches, 0 if no match.
171 */
172static int _mei_irq_thread_state_ok(struct mei_cl *cl,
173 struct mei_msg_hdr *mei_hdr)
174{
175 return (cl->host_client_id == mei_hdr->host_addr &&
176 cl->me_client_id == mei_hdr->me_addr &&
177 cl->state == MEI_FILE_CONNECTED &&
178 MEI_READ_COMPLETE != cl->reading_state);
179}
180
181/**
182 * mei_irq_thread_read_client_message - bottom half read routine after ISR to
183 * handle the read mei client message data processing.
184 *
185 * @complete_list: An instance of our list structure
186 * @dev: the device structure
187 * @mei_hdr: header of mei client message
188 *
189 * returns 0 on success, <0 on failure.
190 */
191static int mei_irq_thread_read_client_message(struct mei_io_list *complete_list,
192 struct mei_device *dev,
193 struct mei_msg_hdr *mei_hdr)
194{
195 struct mei_cl *cl;
196 struct mei_cl_cb *cb_pos = NULL, *cb_next = NULL;
Tomas Winkler479bc592011-06-16 00:46:03 +0300197 unsigned char *buffer = NULL;
Oren Weilfb7d8792011-05-15 13:43:42 +0300198
199 dev_dbg(&dev->pdev->dev, "start client msg\n");
Tomas Winklerc8372092011-11-27 21:43:33 +0200200 if (list_empty(&dev->read_list.mei_cb.cb_list))
Oren Weilfb7d8792011-05-15 13:43:42 +0300201 goto quit;
202
203 list_for_each_entry_safe(cb_pos, cb_next,
204 &dev->read_list.mei_cb.cb_list, cb_list) {
205 cl = (struct mei_cl *)cb_pos->file_private;
206 if (cl && _mei_irq_thread_state_ok(cl, mei_hdr)) {
207 cl->reading_state = MEI_READING;
Tomas Winkleredf1eed2012-02-09 19:25:54 +0200208 buffer = cb_pos->response_buffer.data + cb_pos->information;
Oren Weilfb7d8792011-05-15 13:43:42 +0300209
210 if (cb_pos->response_buffer.size <
211 mei_hdr->length + cb_pos->information) {
212 dev_dbg(&dev->pdev->dev, "message overflow.\n");
213 list_del(&cb_pos->cb_list);
214 return -ENOMEM;
215 }
216 if (buffer)
217 mei_read_slots(dev, buffer, mei_hdr->length);
218
219 cb_pos->information += mei_hdr->length;
220 if (mei_hdr->msg_complete) {
221 cl->status = 0;
222 list_del(&cb_pos->cb_list);
223 dev_dbg(&dev->pdev->dev,
224 "completed read host client = %d,"
225 "ME client = %d, "
226 "data length = %lu\n",
227 cl->host_client_id,
228 cl->me_client_id,
229 cb_pos->information);
230
231 *(cb_pos->response_buffer.data +
232 cb_pos->information) = '\0';
233 dev_dbg(&dev->pdev->dev, "cb_pos->res_buffer - %s\n",
234 cb_pos->response_buffer.data);
235 list_add_tail(&cb_pos->cb_list,
236 &complete_list->mei_cb.cb_list);
237 }
238
239 break;
240 }
241
242 }
243
244quit:
245 dev_dbg(&dev->pdev->dev, "message read\n");
246 if (!buffer) {
Tomas Winkleredf1eed2012-02-09 19:25:54 +0200247 mei_read_slots(dev, dev->rd_msg_buf, mei_hdr->length);
Oren Weilfb7d8792011-05-15 13:43:42 +0300248 dev_dbg(&dev->pdev->dev, "discarding message, header =%08x.\n",
249 *(u32 *) dev->rd_msg_buf);
250 }
251
252 return 0;
253}
254
255/**
256 * _mei_irq_thread_iamthif_read - prepares to read iamthif data.
257 *
258 * @dev: the device structure.
259 * @slots: free slots.
260 *
261 * returns 0, OK; otherwise, error.
262 */
263static int _mei_irq_thread_iamthif_read(struct mei_device *dev, s32 *slots)
264{
265
Tomas Winkler1ccb7b62012-03-14 14:39:42 +0200266 if (((*slots) * sizeof(u32)) < (sizeof(struct mei_msg_hdr)
Oren Weilfb7d8792011-05-15 13:43:42 +0300267 + sizeof(struct hbm_flow_control))) {
Oren Weilfb7d8792011-05-15 13:43:42 +0300268 return -EMSGSIZE;
269 }
Tomas Winkler7bdf72d2012-07-04 19:24:52 +0300270 *slots -= mei_data2slots(sizeof(struct hbm_flow_control));
Tomas Winkler1ccb7b62012-03-14 14:39:42 +0200271 if (mei_send_flow_control(dev, &dev->iamthif_cl)) {
272 dev_dbg(&dev->pdev->dev, "iamthif flow control failed\n");
273 return -EIO;
274 }
275
276 dev_dbg(&dev->pdev->dev, "iamthif flow control success\n");
277 dev->iamthif_state = MEI_IAMTHIF_READING;
278 dev->iamthif_flow_control_pending = false;
279 dev->iamthif_msg_buf_index = 0;
280 dev->iamthif_msg_buf_size = 0;
281 dev->iamthif_stall_timer = IAMTHIF_STALL_TIMER;
Tomas Winkler726917f2012-06-25 23:46:28 +0300282 dev->mei_host_buffer_is_empty = mei_hbuf_is_empty(dev);
Tomas Winkler1ccb7b62012-03-14 14:39:42 +0200283 return 0;
Oren Weilfb7d8792011-05-15 13:43:42 +0300284}
285
286/**
287 * _mei_irq_thread_close - processes close related operation.
288 *
289 * @dev: the device structure.
290 * @slots: free slots.
291 * @cb_pos: callback block.
292 * @cl: private data of the file object.
293 * @cmpl_list: complete list.
294 *
295 * returns 0, OK; otherwise, error.
296 */
297static int _mei_irq_thread_close(struct mei_device *dev, s32 *slots,
298 struct mei_cl_cb *cb_pos,
299 struct mei_cl *cl,
300 struct mei_io_list *cmpl_list)
301{
Tomas Winklerb45f3cc2012-07-04 19:24:53 +0300302 if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) +
303 sizeof(struct hbm_client_disconnect_request)))
Oren Weilfb7d8792011-05-15 13:43:42 +0300304 return -EBADMSG;
Tomas Winklerb45f3cc2012-07-04 19:24:53 +0300305
306 *slots -= mei_data2slots(sizeof(struct hbm_client_disconnect_request));
307
308 if (mei_disconnect(dev, cl)) {
309 cl->status = 0;
310 cb_pos->information = 0;
311 list_move_tail(&cb_pos->cb_list,
312 &cmpl_list->mei_cb.cb_list);
313 return -EMSGSIZE;
314 } else {
315 cl->state = MEI_FILE_DISCONNECTING;
316 cl->status = 0;
317 cb_pos->information = 0;
318 list_move_tail(&cb_pos->cb_list,
319 &dev->ctrl_rd_list.mei_cb.cb_list);
320 cl->timer_count = MEI_CONNECT_TIMEOUT;
Oren Weilfb7d8792011-05-15 13:43:42 +0300321 }
322
323 return 0;
324}
325
326/**
327 * is_treat_specially_client - checks if the message belongs
328 * to the file private data.
329 *
330 * @cl: private data of the file object
331 * @rs: connect response bus message
332 *
333 */
334static bool is_treat_specially_client(struct mei_cl *cl,
335 struct hbm_client_connect_response *rs)
336{
337
338 if (cl->host_client_id == rs->host_addr &&
339 cl->me_client_id == rs->me_addr) {
340 if (!rs->status) {
341 cl->state = MEI_FILE_CONNECTED;
342 cl->status = 0;
343
344 } else {
345 cl->state = MEI_FILE_DISCONNECTED;
346 cl->status = -ENODEV;
347 }
348 cl->timer_count = 0;
349
350 return true;
351 }
352 return false;
353}
354
355/**
356 * mei_client_connect_response - connects to response irq routine
357 *
358 * @dev: the device structure
359 * @rs: connect response bus message
360 */
361static void mei_client_connect_response(struct mei_device *dev,
362 struct hbm_client_connect_response *rs)
363{
364
365 struct mei_cl *cl;
366 struct mei_cl_cb *cb_pos = NULL, *cb_next = NULL;
367
368 dev_dbg(&dev->pdev->dev,
369 "connect_response:\n"
370 "ME Client = %d\n"
371 "Host Client = %d\n"
372 "Status = %d\n",
373 rs->me_addr,
374 rs->host_addr,
375 rs->status);
376
377 /* if WD or iamthif client treat specially */
378
379 if (is_treat_specially_client(&(dev->wd_cl), rs)) {
Oren Weilfb7d8792011-05-15 13:43:42 +0300380 dev_dbg(&dev->pdev->dev, "successfully connected to WD client.\n");
Tomas Winkler70cd5332011-12-22 18:50:50 +0200381 mei_watchdog_register(dev);
Oren Weil9ce178e2011-09-07 09:03:09 +0300382
Tomas Winkler70cd5332011-12-22 18:50:50 +0200383 /* next step in the state maching */
Tomas Winklerc95efb72011-05-25 17:28:21 +0300384 mei_host_init_iamthif(dev);
Oren Weilfb7d8792011-05-15 13:43:42 +0300385 return;
386 }
387
388 if (is_treat_specially_client(&(dev->iamthif_cl), rs)) {
389 dev->iamthif_state = MEI_IAMTHIF_IDLE;
390 return;
391 }
Tomas Winklerb7cd2d92011-11-27 21:43:34 +0200392 list_for_each_entry_safe(cb_pos, cb_next,
393 &dev->ctrl_rd_list.mei_cb.cb_list, cb_list) {
394
395 cl = (struct mei_cl *)cb_pos->file_private;
396 if (!cl) {
397 list_del(&cb_pos->cb_list);
398 return;
399 }
400 if (MEI_IOCTL == cb_pos->major_file_operations) {
401 if (is_treat_specially_client(cl, rs)) {
Oren Weilfb7d8792011-05-15 13:43:42 +0300402 list_del(&cb_pos->cb_list);
Tomas Winklerb7cd2d92011-11-27 21:43:34 +0200403 cl->status = 0;
404 cl->timer_count = 0;
405 break;
Oren Weilfb7d8792011-05-15 13:43:42 +0300406 }
407 }
408 }
409}
410
411/**
412 * mei_client_disconnect_response - disconnects from response irq routine
413 *
414 * @dev: the device structure
415 * @rs: disconnect response bus message
416 */
417static void mei_client_disconnect_response(struct mei_device *dev,
418 struct hbm_client_connect_response *rs)
419{
420 struct mei_cl *cl;
421 struct mei_cl_cb *cb_pos = NULL, *cb_next = NULL;
422
423 dev_dbg(&dev->pdev->dev,
424 "disconnect_response:\n"
425 "ME Client = %d\n"
426 "Host Client = %d\n"
427 "Status = %d\n",
428 rs->me_addr,
429 rs->host_addr,
430 rs->status);
431
Tomas Winklerb7cd2d92011-11-27 21:43:34 +0200432 list_for_each_entry_safe(cb_pos, cb_next,
433 &dev->ctrl_rd_list.mei_cb.cb_list, cb_list) {
434 cl = (struct mei_cl *)cb_pos->file_private;
Oren Weilfb7d8792011-05-15 13:43:42 +0300435
Tomas Winklerb7cd2d92011-11-27 21:43:34 +0200436 if (!cl) {
437 list_del(&cb_pos->cb_list);
438 return;
439 }
Oren Weilfb7d8792011-05-15 13:43:42 +0300440
Tomas Winklerb7cd2d92011-11-27 21:43:34 +0200441 dev_dbg(&dev->pdev->dev, "list_for_each_entry_safe in ctrl_rd_list.\n");
442 if (cl->host_client_id == rs->host_addr &&
443 cl->me_client_id == rs->me_addr) {
Oren Weilfb7d8792011-05-15 13:43:42 +0300444
Tomas Winklerb7cd2d92011-11-27 21:43:34 +0200445 list_del(&cb_pos->cb_list);
446 if (!rs->status)
447 cl->state = MEI_FILE_DISCONNECTED;
Oren Weilfb7d8792011-05-15 13:43:42 +0300448
Tomas Winklerb7cd2d92011-11-27 21:43:34 +0200449 cl->status = 0;
450 cl->timer_count = 0;
451 break;
Oren Weilfb7d8792011-05-15 13:43:42 +0300452 }
453 }
454}
455
456/**
457 * same_flow_addr - tells if they have the same address.
458 *
459 * @file: private data of the file object.
460 * @flow: flow control.
461 *
462 * returns !=0, same; 0,not.
463 */
464static int same_flow_addr(struct mei_cl *cl, struct hbm_flow_control *flow)
465{
466 return (cl->host_client_id == flow->host_addr &&
467 cl->me_client_id == flow->me_addr);
468}
469
470/**
471 * add_single_flow_creds - adds single buffer credentials.
472 *
473 * @file: private data ot the file object.
474 * @flow: flow control.
475 */
476static void add_single_flow_creds(struct mei_device *dev,
477 struct hbm_flow_control *flow)
478{
479 struct mei_me_client *client;
480 int i;
481
Tomas Winklercf9673d2011-06-06 10:44:33 +0300482 for (i = 0; i < dev->me_clients_num; i++) {
Oren Weilfb7d8792011-05-15 13:43:42 +0300483 client = &dev->me_clients[i];
484 if (client && flow->me_addr == client->client_id) {
485 if (client->props.single_recv_buf) {
486 client->mei_flow_ctrl_creds++;
487 dev_dbg(&dev->pdev->dev, "recv flow ctrl msg ME %d (single).\n",
488 flow->me_addr);
489 dev_dbg(&dev->pdev->dev, "flow control credentials =%d.\n",
490 client->mei_flow_ctrl_creds);
491 } else {
492 BUG(); /* error in flow control */
493 }
494 }
495 }
496}
497
498/**
499 * mei_client_flow_control_response - flow control response irq routine
500 *
501 * @dev: the device structure
502 * @flow_control: flow control response bus message
503 */
504static void mei_client_flow_control_response(struct mei_device *dev,
505 struct hbm_flow_control *flow_control)
506{
507 struct mei_cl *cl_pos = NULL;
508 struct mei_cl *cl_next = NULL;
509
510 if (!flow_control->host_addr) {
511 /* single receive buffer */
512 add_single_flow_creds(dev, flow_control);
513 } else {
514 /* normal connection */
515 list_for_each_entry_safe(cl_pos, cl_next,
516 &dev->file_list, link) {
517 dev_dbg(&dev->pdev->dev, "list_for_each_entry_safe in file_list\n");
518
519 dev_dbg(&dev->pdev->dev, "cl of host client %d ME client %d.\n",
520 cl_pos->host_client_id,
521 cl_pos->me_client_id);
522 dev_dbg(&dev->pdev->dev, "flow ctrl msg for host %d ME %d.\n",
523 flow_control->host_addr,
524 flow_control->me_addr);
525 if (same_flow_addr(cl_pos, flow_control)) {
526 dev_dbg(&dev->pdev->dev, "recv ctrl msg for host %d ME %d.\n",
527 flow_control->host_addr,
528 flow_control->me_addr);
529 cl_pos->mei_flow_ctrl_creds++;
530 dev_dbg(&dev->pdev->dev, "flow control credentials = %d.\n",
531 cl_pos->mei_flow_ctrl_creds);
532 break;
533 }
534 }
535 }
536}
537
538/**
539 * same_disconn_addr - tells if they have the same address
540 *
541 * @file: private data of the file object.
542 * @disconn: disconnection request.
543 *
544 * returns !=0, same; 0,not.
545 */
546static int same_disconn_addr(struct mei_cl *cl,
547 struct hbm_client_disconnect_request *disconn)
548{
549 return (cl->host_client_id == disconn->host_addr &&
550 cl->me_client_id == disconn->me_addr);
551}
552
553/**
554 * mei_client_disconnect_request - disconnects from request irq routine
555 *
556 * @dev: the device structure.
557 * @disconnect_req: disconnect request bus message.
558 */
559static void mei_client_disconnect_request(struct mei_device *dev,
560 struct hbm_client_disconnect_request *disconnect_req)
561{
562 struct mei_msg_hdr *mei_hdr;
563 struct hbm_client_connect_response *disconnect_res;
564 struct mei_cl *cl_pos = NULL;
565 struct mei_cl *cl_next = NULL;
566
567 list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) {
568 if (same_disconn_addr(cl_pos, disconnect_req)) {
569 dev_dbg(&dev->pdev->dev, "disconnect request host client %d ME client %d.\n",
570 disconnect_req->host_addr,
571 disconnect_req->me_addr);
572 cl_pos->state = MEI_FILE_DISCONNECTED;
573 cl_pos->timer_count = 0;
Tomas Winklerd242a0a2012-07-04 19:24:50 +0300574 if (cl_pos == &dev->wd_cl)
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300575 dev->wd_pending = false;
Tomas Winklerd242a0a2012-07-04 19:24:50 +0300576 else if (cl_pos == &dev->iamthif_cl)
Oren Weilfb7d8792011-05-15 13:43:42 +0300577 dev->iamthif_timer = 0;
578
579 /* prepare disconnect response */
580 mei_hdr =
581 (struct mei_msg_hdr *) &dev->ext_msg_buf[0];
582 mei_hdr->host_addr = 0;
583 mei_hdr->me_addr = 0;
584 mei_hdr->length =
585 sizeof(struct hbm_client_connect_response);
586 mei_hdr->msg_complete = 1;
587 mei_hdr->reserved = 0;
588
589 disconnect_res =
590 (struct hbm_client_connect_response *)
591 &dev->ext_msg_buf[1];
592 disconnect_res->host_addr = cl_pos->host_client_id;
593 disconnect_res->me_addr = cl_pos->me_client_id;
Tomas Winkler1ca7e782012-02-26 23:18:57 +0200594 disconnect_res->hbm_cmd = CLIENT_DISCONNECT_RES_CMD;
Oren Weilfb7d8792011-05-15 13:43:42 +0300595 disconnect_res->status = 0;
596 dev->extra_write_index = 2;
597 break;
598 }
599 }
600}
601
602
603/**
604 * mei_irq_thread_read_bus_message - bottom half read routine after ISR to
605 * handle the read bus message cmd processing.
606 *
607 * @dev: the device structure
608 * @mei_hdr: header of bus message
609 */
610static void mei_irq_thread_read_bus_message(struct mei_device *dev,
611 struct mei_msg_hdr *mei_hdr)
612{
613 struct mei_bus_message *mei_msg;
614 struct hbm_host_version_response *version_res;
615 struct hbm_client_connect_response *connect_res;
616 struct hbm_client_connect_response *disconnect_res;
617 struct hbm_flow_control *flow_control;
618 struct hbm_props_response *props_res;
619 struct hbm_host_enum_response *enum_res;
620 struct hbm_client_disconnect_request *disconnect_req;
621 struct hbm_host_stop_request *host_stop_req;
Oren Weilabc51b62011-09-21 16:45:30 +0300622 int res;
Oren Weilfb7d8792011-05-15 13:43:42 +0300623
Oren Weilfb7d8792011-05-15 13:43:42 +0300624
625 /* read the message to our buffer */
Oren Weilfb7d8792011-05-15 13:43:42 +0300626 BUG_ON(mei_hdr->length >= sizeof(dev->rd_msg_buf));
Tomas Winkleredf1eed2012-02-09 19:25:54 +0200627 mei_read_slots(dev, dev->rd_msg_buf, mei_hdr->length);
628 mei_msg = (struct mei_bus_message *)dev->rd_msg_buf;
Oren Weilfb7d8792011-05-15 13:43:42 +0300629
Tomas Winkler1ca7e782012-02-26 23:18:57 +0200630 switch (mei_msg->hbm_cmd) {
Oren Weilfb7d8792011-05-15 13:43:42 +0300631 case HOST_START_RES_CMD:
632 version_res = (struct hbm_host_version_response *) mei_msg;
633 if (version_res->host_version_supported) {
634 dev->version.major_version = HBM_MAJOR_VERSION;
635 dev->version.minor_version = HBM_MINOR_VERSION;
Tomas Winklerb210d752012-08-07 00:03:56 +0300636 if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
Oren Weilfb7d8792011-05-15 13:43:42 +0300637 dev->init_clients_state == MEI_START_MESSAGE) {
638 dev->init_clients_timer = 0;
Tomas Winklerc95efb72011-05-25 17:28:21 +0300639 mei_host_enum_clients_message(dev);
Oren Weilfb7d8792011-05-15 13:43:42 +0300640 } else {
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300641 dev->recvd_msg = false;
Oren Weilfb7d8792011-05-15 13:43:42 +0300642 dev_dbg(&dev->pdev->dev, "IMEI reset due to received host start response bus message.\n");
643 mei_reset(dev, 1);
644 return;
645 }
646 } else {
647 dev->version = version_res->me_max_version;
648 /* send stop message */
Tomas Winkler97d5cb02012-03-06 22:34:32 +0200649 mei_hdr = (struct mei_msg_hdr *)&dev->wr_msg_buf[0];
Oren Weilfb7d8792011-05-15 13:43:42 +0300650 mei_hdr->host_addr = 0;
651 mei_hdr->me_addr = 0;
652 mei_hdr->length = sizeof(struct hbm_host_stop_request);
653 mei_hdr->msg_complete = 1;
654 mei_hdr->reserved = 0;
655
656 host_stop_req = (struct hbm_host_stop_request *)
657 &dev->wr_msg_buf[1];
658
659 memset(host_stop_req,
660 0,
661 sizeof(struct hbm_host_stop_request));
Tomas Winkler1ca7e782012-02-26 23:18:57 +0200662 host_stop_req->hbm_cmd = HOST_STOP_REQ_CMD;
Oren Weilfb7d8792011-05-15 13:43:42 +0300663 host_stop_req->reason = DRIVER_STOP_REQUEST;
664 mei_write_message(dev, mei_hdr,
665 (unsigned char *) (host_stop_req),
666 mei_hdr->length);
667 dev_dbg(&dev->pdev->dev, "version mismatch.\n");
668 return;
669 }
670
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300671 dev->recvd_msg = true;
Oren Weilfb7d8792011-05-15 13:43:42 +0300672 dev_dbg(&dev->pdev->dev, "host start response message received.\n");
673 break;
674
675 case CLIENT_CONNECT_RES_CMD:
676 connect_res =
677 (struct hbm_client_connect_response *) mei_msg;
678 mei_client_connect_response(dev, connect_res);
679 dev_dbg(&dev->pdev->dev, "client connect response message received.\n");
680 wake_up(&dev->wait_recvd_msg);
681 break;
682
683 case CLIENT_DISCONNECT_RES_CMD:
684 disconnect_res =
685 (struct hbm_client_connect_response *) mei_msg;
Tomas Winkler441ab502011-12-13 23:39:34 +0200686 mei_client_disconnect_response(dev, disconnect_res);
Oren Weilfb7d8792011-05-15 13:43:42 +0300687 dev_dbg(&dev->pdev->dev, "client disconnect response message received.\n");
688 wake_up(&dev->wait_recvd_msg);
689 break;
690
691 case MEI_FLOW_CONTROL_CMD:
692 flow_control = (struct hbm_flow_control *) mei_msg;
693 mei_client_flow_control_response(dev, flow_control);
694 dev_dbg(&dev->pdev->dev, "client flow control response message received.\n");
695 break;
696
697 case HOST_CLIENT_PROPERTIES_RES_CMD:
698 props_res = (struct hbm_props_response *)mei_msg;
699 if (props_res->status || !dev->me_clients) {
700 dev_dbg(&dev->pdev->dev, "reset due to received host client properties response bus message wrong status.\n");
701 mei_reset(dev, 1);
702 return;
703 }
Tomas Winkler441ab502011-12-13 23:39:34 +0200704 if (dev->me_clients[dev->me_client_presentation_num]
Oren Weilfb7d8792011-05-15 13:43:42 +0300705 .client_id == props_res->address) {
706
707 dev->me_clients[dev->me_client_presentation_num].props
708 = props_res->client_properties;
709
Tomas Winklerb210d752012-08-07 00:03:56 +0300710 if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
Oren Weilfb7d8792011-05-15 13:43:42 +0300711 dev->init_clients_state ==
712 MEI_CLIENT_PROPERTIES_MESSAGE) {
713 dev->me_client_index++;
714 dev->me_client_presentation_num++;
Oren Weilabc51b62011-09-21 16:45:30 +0300715
Justin P. Mattock5f9092f32012-03-12 07:18:09 -0700716 /** Send Client Properties request **/
Oren Weilabc51b62011-09-21 16:45:30 +0300717 res = mei_host_client_properties(dev);
718 if (res < 0) {
719 dev_dbg(&dev->pdev->dev, "mei_host_client_properties() failed");
720 return;
721 } else if (!res) {
722 /*
723 * No more clients to send to.
724 * Clear Map for indicating now ME clients
725 * with associated host client
726 */
727 bitmap_zero(dev->host_clients_map, MEI_CLIENTS_MAX);
728 dev->open_handle_count = 0;
729
730 /*
731 * Reserving the first three client IDs
732 * Client Id 0 - Reserved for MEI Bus Message communications
733 * Client Id 1 - Reserved for Watchdog
734 * Client ID 2 - Reserved for AMTHI
735 */
736 bitmap_set(dev->host_clients_map, 0, 3);
Tomas Winklerb210d752012-08-07 00:03:56 +0300737 dev->dev_state = MEI_DEV_ENABLED;
Oren Weilabc51b62011-09-21 16:45:30 +0300738
739 /* if wd initialization fails, initialization the AMTHI client,
740 * otherwise the AMTHI client will be initialized after the WD client connect response
741 * will be received
742 */
743 if (mei_wd_host_init(dev))
744 mei_host_init_iamthif(dev);
745 }
746
Oren Weilfb7d8792011-05-15 13:43:42 +0300747 } else {
748 dev_dbg(&dev->pdev->dev, "reset due to received host client properties response bus message");
749 mei_reset(dev, 1);
750 return;
751 }
752 } else {
753 dev_dbg(&dev->pdev->dev, "reset due to received host client properties response bus message for wrong client ID\n");
754 mei_reset(dev, 1);
755 return;
756 }
757 break;
758
759 case HOST_ENUM_RES_CMD:
760 enum_res = (struct hbm_host_enum_response *) mei_msg;
761 memcpy(dev->me_clients_map, enum_res->valid_addresses, 32);
Tomas Winklerb210d752012-08-07 00:03:56 +0300762 if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
Oren Weilfb7d8792011-05-15 13:43:42 +0300763 dev->init_clients_state == MEI_ENUM_CLIENTS_MESSAGE) {
764 dev->init_clients_timer = 0;
765 dev->me_client_presentation_num = 0;
766 dev->me_client_index = 0;
Tomas Winklerc95efb72011-05-25 17:28:21 +0300767 mei_allocate_me_clients_storage(dev);
Oren Weilfb7d8792011-05-15 13:43:42 +0300768 dev->init_clients_state =
769 MEI_CLIENT_PROPERTIES_MESSAGE;
Tomas Winklerc95efb72011-05-25 17:28:21 +0300770 mei_host_client_properties(dev);
Oren Weilfb7d8792011-05-15 13:43:42 +0300771 } else {
772 dev_dbg(&dev->pdev->dev, "reset due to received host enumeration clients response bus message.\n");
773 mei_reset(dev, 1);
774 return;
775 }
776 break;
777
778 case HOST_STOP_RES_CMD:
Tomas Winklerb210d752012-08-07 00:03:56 +0300779 dev->dev_state = MEI_DEV_DISABLED;
Oren Weilfb7d8792011-05-15 13:43:42 +0300780 dev_dbg(&dev->pdev->dev, "resetting because of FW stop response.\n");
781 mei_reset(dev, 1);
782 break;
783
784 case CLIENT_DISCONNECT_REQ_CMD:
785 /* search for client */
786 disconnect_req =
787 (struct hbm_client_disconnect_request *) mei_msg;
788 mei_client_disconnect_request(dev, disconnect_req);
789 break;
790
791 case ME_STOP_REQ_CMD:
792 /* prepare stop request */
793 mei_hdr = (struct mei_msg_hdr *) &dev->ext_msg_buf[0];
794 mei_hdr->host_addr = 0;
795 mei_hdr->me_addr = 0;
796 mei_hdr->length = sizeof(struct hbm_host_stop_request);
797 mei_hdr->msg_complete = 1;
798 mei_hdr->reserved = 0;
799 host_stop_req =
800 (struct hbm_host_stop_request *) &dev->ext_msg_buf[1];
801 memset(host_stop_req, 0, sizeof(struct hbm_host_stop_request));
Tomas Winkler1ca7e782012-02-26 23:18:57 +0200802 host_stop_req->hbm_cmd = HOST_STOP_REQ_CMD;
Oren Weilfb7d8792011-05-15 13:43:42 +0300803 host_stop_req->reason = DRIVER_STOP_REQUEST;
804 host_stop_req->reserved[0] = 0;
805 host_stop_req->reserved[1] = 0;
806 dev->extra_write_index = 2;
807 break;
808
809 default:
810 BUG();
811 break;
812
813 }
814}
815
816
817/**
818 * _mei_hb_read - processes read related operation.
819 *
820 * @dev: the device structure.
821 * @slots: free slots.
822 * @cb_pos: callback block.
823 * @cl: private data of the file object.
824 * @cmpl_list: complete list.
825 *
826 * returns 0, OK; otherwise, error.
827 */
828static int _mei_irq_thread_read(struct mei_device *dev, s32 *slots,
829 struct mei_cl_cb *cb_pos,
830 struct mei_cl *cl,
831 struct mei_io_list *cmpl_list)
832{
Tomas Winkler1e69d642012-05-29 16:39:12 +0300833 if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) +
Oren Weilfb7d8792011-05-15 13:43:42 +0300834 sizeof(struct hbm_flow_control))) {
Oren Weilfb7d8792011-05-15 13:43:42 +0300835 /* return the cancel routine */
836 list_del(&cb_pos->cb_list);
837 return -EBADMSG;
838 }
839
Tomas Winkler7bdf72d2012-07-04 19:24:52 +0300840 *slots -= mei_data2slots(sizeof(struct hbm_flow_control));
841
Tomas Winkler1ccb7b62012-03-14 14:39:42 +0200842 if (mei_send_flow_control(dev, cl)) {
843 cl->status = -ENODEV;
844 cb_pos->information = 0;
845 list_move_tail(&cb_pos->cb_list, &cmpl_list->mei_cb.cb_list);
846 return -ENODEV;
847 }
848 list_move_tail(&cb_pos->cb_list, &dev->read_list.mei_cb.cb_list);
849
Oren Weilfb7d8792011-05-15 13:43:42 +0300850 return 0;
851}
852
853
854/**
855 * _mei_irq_thread_ioctl - processes ioctl related operation.
856 *
857 * @dev: the device structure.
858 * @slots: free slots.
859 * @cb_pos: callback block.
860 * @cl: private data of the file object.
861 * @cmpl_list: complete list.
862 *
863 * returns 0, OK; otherwise, error.
864 */
865static int _mei_irq_thread_ioctl(struct mei_device *dev, s32 *slots,
866 struct mei_cl_cb *cb_pos,
867 struct mei_cl *cl,
868 struct mei_io_list *cmpl_list)
869{
Tomas Winklerb45f3cc2012-07-04 19:24:53 +0300870 if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) +
Oren Weilfb7d8792011-05-15 13:43:42 +0300871 sizeof(struct hbm_client_connect_request))) {
Oren Weilfb7d8792011-05-15 13:43:42 +0300872 /* return the cancel routine */
873 list_del(&cb_pos->cb_list);
874 return -EBADMSG;
875 }
876
Tomas Winklerb45f3cc2012-07-04 19:24:53 +0300877 cl->state = MEI_FILE_CONNECTING;
878 *slots -= mei_data2slots(sizeof(struct hbm_client_connect_request));
879 if (mei_connect(dev, cl)) {
880 cl->status = -ENODEV;
881 cb_pos->information = 0;
882 list_del(&cb_pos->cb_list);
883 return -ENODEV;
884 } else {
885 list_move_tail(&cb_pos->cb_list,
886 &dev->ctrl_rd_list.mei_cb.cb_list);
887 cl->timer_count = MEI_CONNECT_TIMEOUT;
888 }
Oren Weilfb7d8792011-05-15 13:43:42 +0300889 return 0;
890}
891
892/**
893 * _mei_irq_thread_cmpl - processes completed and no-iamthif operation.
894 *
895 * @dev: the device structure.
896 * @slots: free slots.
897 * @cb_pos: callback block.
898 * @cl: private data of the file object.
899 * @cmpl_list: complete list.
900 *
901 * returns 0, OK; otherwise, error.
902 */
903static int _mei_irq_thread_cmpl(struct mei_device *dev, s32 *slots,
904 struct mei_cl_cb *cb_pos,
905 struct mei_cl *cl,
906 struct mei_io_list *cmpl_list)
907{
908 struct mei_msg_hdr *mei_hdr;
909
910 if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) +
911 (cb_pos->request_buffer.size -
912 cb_pos->information))) {
913 mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0];
914 mei_hdr->host_addr = cl->host_client_id;
915 mei_hdr->me_addr = cl->me_client_id;
916 mei_hdr->length = cb_pos->request_buffer.size -
917 cb_pos->information;
918 mei_hdr->msg_complete = 1;
919 mei_hdr->reserved = 0;
920 dev_dbg(&dev->pdev->dev, "cb_pos->request_buffer.size =%d"
921 "mei_hdr->msg_complete = %d\n",
922 cb_pos->request_buffer.size,
923 mei_hdr->msg_complete);
924 dev_dbg(&dev->pdev->dev, "cb_pos->information =%lu\n",
925 cb_pos->information);
926 dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n",
927 mei_hdr->length);
Tomas Winkler7bdf72d2012-07-04 19:24:52 +0300928 *slots -= mei_data2slots(mei_hdr->length);
Tomas Winkler1ccb7b62012-03-14 14:39:42 +0200929 if (mei_write_message(dev, mei_hdr,
Oren Weilfb7d8792011-05-15 13:43:42 +0300930 (unsigned char *)
931 (cb_pos->request_buffer.data +
932 cb_pos->information),
933 mei_hdr->length)) {
934 cl->status = -ENODEV;
935 list_move_tail(&cb_pos->cb_list,
936 &cmpl_list->mei_cb.cb_list);
937 return -ENODEV;
938 } else {
939 if (mei_flow_ctrl_reduce(dev, cl))
940 return -ENODEV;
941 cl->status = 0;
942 cb_pos->information += mei_hdr->length;
943 list_move_tail(&cb_pos->cb_list,
944 &dev->write_waiting_list.mei_cb.cb_list);
945 }
Tomas Winkler24aadc82012-06-25 23:46:27 +0300946 } else if (*slots == dev->hbuf_depth) {
Oren Weilfb7d8792011-05-15 13:43:42 +0300947 /* buffer is still empty */
948 mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0];
949 mei_hdr->host_addr = cl->host_client_id;
950 mei_hdr->me_addr = cl->me_client_id;
951 mei_hdr->length =
952 (*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr);
953 mei_hdr->msg_complete = 0;
954 mei_hdr->reserved = 0;
Tomas Winkler7bdf72d2012-07-04 19:24:52 +0300955 *slots -= mei_data2slots(mei_hdr->length);
Tomas Winkler1ccb7b62012-03-14 14:39:42 +0200956 if (mei_write_message(dev, mei_hdr,
Oren Weilfb7d8792011-05-15 13:43:42 +0300957 (unsigned char *)
958 (cb_pos->request_buffer.data +
959 cb_pos->information),
960 mei_hdr->length)) {
961 cl->status = -ENODEV;
962 list_move_tail(&cb_pos->cb_list,
963 &cmpl_list->mei_cb.cb_list);
964 return -ENODEV;
965 } else {
966 cb_pos->information += mei_hdr->length;
967 dev_dbg(&dev->pdev->dev,
968 "cb_pos->request_buffer.size =%d"
969 " mei_hdr->msg_complete = %d\n",
970 cb_pos->request_buffer.size,
971 mei_hdr->msg_complete);
972 dev_dbg(&dev->pdev->dev, "cb_pos->information =%lu\n",
973 cb_pos->information);
974 dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n",
975 mei_hdr->length);
976 }
977 return -EMSGSIZE;
978 } else {
979 return -EBADMSG;
980 }
981
982 return 0;
983}
984
985/**
986 * _mei_irq_thread_cmpl_iamthif - processes completed iamthif operation.
987 *
988 * @dev: the device structure.
989 * @slots: free slots.
990 * @cb_pos: callback block.
991 * @cl: private data of the file object.
992 * @cmpl_list: complete list.
993 *
994 * returns 0, OK; otherwise, error.
995 */
996static int _mei_irq_thread_cmpl_iamthif(struct mei_device *dev, s32 *slots,
997 struct mei_cl_cb *cb_pos,
998 struct mei_cl *cl,
999 struct mei_io_list *cmpl_list)
1000{
1001 struct mei_msg_hdr *mei_hdr;
1002
1003 if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) +
1004 dev->iamthif_msg_buf_size -
1005 dev->iamthif_msg_buf_index)) {
1006 mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0];
1007 mei_hdr->host_addr = cl->host_client_id;
1008 mei_hdr->me_addr = cl->me_client_id;
1009 mei_hdr->length = dev->iamthif_msg_buf_size -
1010 dev->iamthif_msg_buf_index;
1011 mei_hdr->msg_complete = 1;
1012 mei_hdr->reserved = 0;
1013
Tomas Winkler7bdf72d2012-07-04 19:24:52 +03001014 *slots -= mei_data2slots(mei_hdr->length);
Oren Weilfb7d8792011-05-15 13:43:42 +03001015
Tomas Winkler1ccb7b62012-03-14 14:39:42 +02001016 if (mei_write_message(dev, mei_hdr,
Oren Weilfb7d8792011-05-15 13:43:42 +03001017 (dev->iamthif_msg_buf +
1018 dev->iamthif_msg_buf_index),
1019 mei_hdr->length)) {
1020 dev->iamthif_state = MEI_IAMTHIF_IDLE;
1021 cl->status = -ENODEV;
1022 list_del(&cb_pos->cb_list);
1023 return -ENODEV;
1024 } else {
1025 if (mei_flow_ctrl_reduce(dev, cl))
1026 return -ENODEV;
1027 dev->iamthif_msg_buf_index += mei_hdr->length;
1028 cb_pos->information = dev->iamthif_msg_buf_index;
1029 cl->status = 0;
1030 dev->iamthif_state = MEI_IAMTHIF_FLOW_CONTROL;
Tomas Winklereb9af0a2011-05-25 17:28:22 +03001031 dev->iamthif_flow_control_pending = true;
Oren Weilfb7d8792011-05-15 13:43:42 +03001032 /* save iamthif cb sent to amthi client */
1033 dev->iamthif_current_cb = cb_pos;
1034 list_move_tail(&cb_pos->cb_list,
1035 &dev->write_waiting_list.mei_cb.cb_list);
1036
1037 }
Tomas Winkler24aadc82012-06-25 23:46:27 +03001038 } else if (*slots == dev->hbuf_depth) {
1039 /* buffer is still empty */
Oren Weilfb7d8792011-05-15 13:43:42 +03001040 mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0];
1041 mei_hdr->host_addr = cl->host_client_id;
1042 mei_hdr->me_addr = cl->me_client_id;
1043 mei_hdr->length =
1044 (*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr);
1045 mei_hdr->msg_complete = 0;
1046 mei_hdr->reserved = 0;
1047
Tomas Winkler7bdf72d2012-07-04 19:24:52 +03001048 *slots -= mei_data2slots(mei_hdr->length);
Oren Weilfb7d8792011-05-15 13:43:42 +03001049
Tomas Winkler1ccb7b62012-03-14 14:39:42 +02001050 if (mei_write_message(dev, mei_hdr,
Oren Weilfb7d8792011-05-15 13:43:42 +03001051 (dev->iamthif_msg_buf +
1052 dev->iamthif_msg_buf_index),
1053 mei_hdr->length)) {
1054 cl->status = -ENODEV;
1055 list_del(&cb_pos->cb_list);
1056 } else {
1057 dev->iamthif_msg_buf_index += mei_hdr->length;
1058 }
1059 return -EMSGSIZE;
1060 } else {
1061 return -EBADMSG;
1062 }
1063
1064 return 0;
1065}
1066
1067/**
1068 * mei_irq_thread_read_handler - bottom half read routine after ISR to
1069 * handle the read processing.
1070 *
1071 * @cmpl_list: An instance of our list structure
1072 * @dev: the device structure
1073 * @slots: slots to read.
1074 *
1075 * returns 0 on success, <0 on failure.
1076 */
1077static int mei_irq_thread_read_handler(struct mei_io_list *cmpl_list,
1078 struct mei_device *dev,
1079 s32 *slots)
1080{
1081 struct mei_msg_hdr *mei_hdr;
1082 struct mei_cl *cl_pos = NULL;
1083 struct mei_cl *cl_next = NULL;
1084 int ret = 0;
1085
1086 if (!dev->rd_msg_hdr) {
1087 dev->rd_msg_hdr = mei_mecbrw_read(dev);
1088 dev_dbg(&dev->pdev->dev, "slots =%08x.\n", *slots);
1089 (*slots)--;
1090 dev_dbg(&dev->pdev->dev, "slots =%08x.\n", *slots);
1091 }
1092 mei_hdr = (struct mei_msg_hdr *) &dev->rd_msg_hdr;
1093 dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n", mei_hdr->length);
1094
1095 if (mei_hdr->reserved || !dev->rd_msg_hdr) {
1096 dev_dbg(&dev->pdev->dev, "corrupted message header.\n");
1097 ret = -EBADMSG;
1098 goto end;
1099 }
1100
1101 if (mei_hdr->host_addr || mei_hdr->me_addr) {
1102 list_for_each_entry_safe(cl_pos, cl_next,
1103 &dev->file_list, link) {
1104 dev_dbg(&dev->pdev->dev,
1105 "list_for_each_entry_safe read host"
1106 " client = %d, ME client = %d\n",
1107 cl_pos->host_client_id,
1108 cl_pos->me_client_id);
1109 if (cl_pos->host_client_id == mei_hdr->host_addr &&
1110 cl_pos->me_client_id == mei_hdr->me_addr)
1111 break;
1112 }
1113
1114 if (&cl_pos->link == &dev->file_list) {
1115 dev_dbg(&dev->pdev->dev, "corrupted message header\n");
1116 ret = -EBADMSG;
1117 goto end;
1118 }
1119 }
1120 if (((*slots) * sizeof(u32)) < mei_hdr->length) {
1121 dev_dbg(&dev->pdev->dev,
1122 "we can't read the message slots =%08x.\n",
1123 *slots);
1124 /* we can't read the message */
1125 ret = -ERANGE;
1126 goto end;
1127 }
1128
1129 /* decide where to read the message too */
1130 if (!mei_hdr->host_addr) {
1131 dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_bus_message.\n");
1132 mei_irq_thread_read_bus_message(dev, mei_hdr);
1133 dev_dbg(&dev->pdev->dev, "end mei_irq_thread_read_bus_message.\n");
1134 } else if (mei_hdr->host_addr == dev->iamthif_cl.host_client_id &&
1135 (MEI_FILE_CONNECTED == dev->iamthif_cl.state) &&
1136 (dev->iamthif_state == MEI_IAMTHIF_READING)) {
1137 dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_iamthif_message.\n");
1138 dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n",
1139 mei_hdr->length);
1140 ret = mei_irq_thread_read_amthi_message(cmpl_list,
1141 dev, mei_hdr);
1142 if (ret)
1143 goto end;
1144
1145 } else {
1146 dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_client_message.\n");
1147 ret = mei_irq_thread_read_client_message(cmpl_list,
1148 dev, mei_hdr);
1149 if (ret)
1150 goto end;
1151
1152 }
1153
1154 /* reset the number of slots and header */
1155 *slots = mei_count_full_read_slots(dev);
1156 dev->rd_msg_hdr = 0;
1157
1158 if (*slots == -EOVERFLOW) {
1159 /* overflow - reset */
1160 dev_dbg(&dev->pdev->dev, "resetting due to slots overflow.\n");
1161 /* set the event since message has been read */
1162 ret = -ERANGE;
1163 goto end;
1164 }
1165end:
1166 return ret;
1167}
1168
1169
1170/**
1171 * mei_irq_thread_write_handler - bottom half write routine after
1172 * ISR to handle the write processing.
1173 *
1174 * @cmpl_list: An instance of our list structure
1175 * @dev: the device structure
1176 * @slots: slots to write.
1177 *
1178 * returns 0 on success, <0 on failure.
1179 */
1180static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
1181 struct mei_device *dev,
1182 s32 *slots)
1183{
1184
1185 struct mei_cl *cl;
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001186 struct mei_cl_cb *pos = NULL, *next = NULL;
Oren Weilfb7d8792011-05-15 13:43:42 +03001187 struct mei_io_list *list;
1188 int ret;
1189
Tomas Winkler726917f2012-06-25 23:46:28 +03001190 if (!mei_hbuf_is_empty(dev)) {
Oren Weilfb7d8792011-05-15 13:43:42 +03001191 dev_dbg(&dev->pdev->dev, "host buffer is not empty.\n");
1192 return 0;
1193 }
Tomas Winkler726917f2012-06-25 23:46:28 +03001194 *slots = mei_hbuf_empty_slots(dev);
Tomas Winkler7d5e0e52012-06-19 09:13:36 +03001195 if (*slots <= 0)
1196 return -EMSGSIZE;
1197
Oren Weilfb7d8792011-05-15 13:43:42 +03001198 /* complete all waiting for write CB */
1199 dev_dbg(&dev->pdev->dev, "complete all waiting for write cb.\n");
1200
1201 list = &dev->write_waiting_list;
Tomas Winkler483136e2012-07-04 19:24:54 +03001202 list_for_each_entry_safe(pos, next, &list->mei_cb.cb_list, cb_list) {
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001203 cl = (struct mei_cl *)pos->file_private;
1204 if (cl == NULL)
1205 continue;
Oren Weilfb7d8792011-05-15 13:43:42 +03001206
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001207 cl->status = 0;
1208 list_del(&pos->cb_list);
1209 if (MEI_WRITING == cl->writing_state &&
1210 (pos->major_file_operations == MEI_WRITE) &&
1211 (cl != &dev->iamthif_cl)) {
Tomas Winkler483136e2012-07-04 19:24:54 +03001212 dev_dbg(&dev->pdev->dev, "MEI WRITE COMPLETE\n");
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001213 cl->writing_state = MEI_WRITE_COMPLETE;
1214 list_add_tail(&pos->cb_list,
Tomas Winkler483136e2012-07-04 19:24:54 +03001215 &cmpl_list->mei_cb.cb_list);
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001216 }
1217 if (cl == &dev->iamthif_cl) {
1218 dev_dbg(&dev->pdev->dev, "check iamthif flow control.\n");
1219 if (dev->iamthif_flow_control_pending) {
Tomas Winkler483136e2012-07-04 19:24:54 +03001220 ret = _mei_irq_thread_iamthif_read(dev, slots);
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001221 if (ret)
1222 return ret;
1223 }
Oren Weilfb7d8792011-05-15 13:43:42 +03001224 }
1225 }
1226
1227 if (dev->stop && !dev->wd_pending) {
Tomas Winklereb9af0a2011-05-25 17:28:22 +03001228 dev->wd_stopped = true;
Oren Weilfb7d8792011-05-15 13:43:42 +03001229 wake_up_interruptible(&dev->wait_stop_wd);
1230 return 0;
1231 }
1232
1233 if (dev->extra_write_index) {
1234 dev_dbg(&dev->pdev->dev, "extra_write_index =%d.\n",
1235 dev->extra_write_index);
1236 mei_write_message(dev,
1237 (struct mei_msg_hdr *) &dev->ext_msg_buf[0],
1238 (unsigned char *) &dev->ext_msg_buf[1],
1239 (dev->extra_write_index - 1) * sizeof(u32));
1240 *slots -= dev->extra_write_index;
1241 dev->extra_write_index = 0;
1242 }
Tomas Winklerb210d752012-08-07 00:03:56 +03001243 if (dev->dev_state == MEI_DEV_ENABLED) {
Oren Weilfb7d8792011-05-15 13:43:42 +03001244 if (dev->wd_pending &&
Tomas Winkler483136e2012-07-04 19:24:54 +03001245 mei_flow_ctrl_creds(dev, &dev->wd_cl) > 0) {
Oren Weilfb7d8792011-05-15 13:43:42 +03001246 if (mei_wd_send(dev))
1247 dev_dbg(&dev->pdev->dev, "wd send failed.\n");
Tomas Winkler483136e2012-07-04 19:24:54 +03001248 else if (mei_flow_ctrl_reduce(dev, &dev->wd_cl))
1249 return -ENODEV;
Oren Weilfb7d8792011-05-15 13:43:42 +03001250
Tomas Winklereb9af0a2011-05-25 17:28:22 +03001251 dev->wd_pending = false;
Oren Weilfb7d8792011-05-15 13:43:42 +03001252
Tomas Winklerd242a0a2012-07-04 19:24:50 +03001253 if (dev->wd_timeout)
Tomas Winkler7bdf72d2012-07-04 19:24:52 +03001254 *slots -= mei_data2slots(MEI_START_WD_DATA_SIZE);
Tomas Winklerd242a0a2012-07-04 19:24:50 +03001255 else
Tomas Winkler7bdf72d2012-07-04 19:24:52 +03001256 *slots -= mei_data2slots(MEI_START_WD_DATA_SIZE);
Oren Weilfb7d8792011-05-15 13:43:42 +03001257 }
1258 }
1259 if (dev->stop)
Devin J. Pohlydc91e2f2012-02-27 20:32:53 +02001260 return -ENODEV;
Oren Weilfb7d8792011-05-15 13:43:42 +03001261
1262 /* complete control write list CB */
Tomas Winklerc8372092011-11-27 21:43:33 +02001263 dev_dbg(&dev->pdev->dev, "complete control write list cb.\n");
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001264 list_for_each_entry_safe(pos, next,
Oren Weilfb7d8792011-05-15 13:43:42 +03001265 &dev->ctrl_wr_list.mei_cb.cb_list, cb_list) {
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001266 cl = (struct mei_cl *) pos->file_private;
Tomas Winklerc8372092011-11-27 21:43:33 +02001267 if (!cl) {
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001268 list_del(&pos->cb_list);
Tomas Winklerc8372092011-11-27 21:43:33 +02001269 return -ENODEV;
Oren Weilfb7d8792011-05-15 13:43:42 +03001270 }
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001271 switch (pos->major_file_operations) {
Tomas Winklerc8372092011-11-27 21:43:33 +02001272 case MEI_CLOSE:
1273 /* send disconnect message */
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001274 ret = _mei_irq_thread_close(dev, slots, pos, cl, cmpl_list);
Tomas Winklerc8372092011-11-27 21:43:33 +02001275 if (ret)
1276 return ret;
1277
1278 break;
1279 case MEI_READ:
1280 /* send flow control message */
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001281 ret = _mei_irq_thread_read(dev, slots, pos, cl, cmpl_list);
Tomas Winklerc8372092011-11-27 21:43:33 +02001282 if (ret)
1283 return ret;
1284
1285 break;
1286 case MEI_IOCTL:
1287 /* connect message */
Natalia Ovsyanikove8cd29d2011-12-05 00:16:54 +02001288 if (mei_other_client_is_connecting(dev, cl))
Tomas Winklerc8372092011-11-27 21:43:33 +02001289 continue;
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001290 ret = _mei_irq_thread_ioctl(dev, slots, pos, cl, cmpl_list);
Tomas Winklerc8372092011-11-27 21:43:33 +02001291 if (ret)
1292 return ret;
1293
1294 break;
1295
1296 default:
1297 BUG();
1298 }
1299
Oren Weilfb7d8792011-05-15 13:43:42 +03001300 }
1301 /* complete write list CB */
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001302 dev_dbg(&dev->pdev->dev, "complete write list cb.\n");
1303 list_for_each_entry_safe(pos, next,
Tomas Winkler483136e2012-07-04 19:24:54 +03001304 &dev->write_list.mei_cb.cb_list, cb_list) {
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001305 cl = (struct mei_cl *)pos->file_private;
1306 if (cl == NULL)
1307 continue;
Oren Weilfb7d8792011-05-15 13:43:42 +03001308
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001309 if (cl != &dev->iamthif_cl) {
Tomas Winklerd2041152012-06-19 09:13:34 +03001310 if (mei_flow_ctrl_creds(dev, cl) <= 0) {
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001311 dev_dbg(&dev->pdev->dev,
Tomas Winkler483136e2012-07-04 19:24:54 +03001312 "No flow control credentials for client %d, not sending.\n",
1313 cl->host_client_id);
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001314 continue;
Oren Weilfb7d8792011-05-15 13:43:42 +03001315 }
Tomas Winkler483136e2012-07-04 19:24:54 +03001316 ret = _mei_irq_thread_cmpl(dev, slots, pos,
1317 cl, cmpl_list);
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001318 if (ret)
1319 return ret;
1320
1321 } else if (cl == &dev->iamthif_cl) {
1322 /* IAMTHIF IOCTL */
1323 dev_dbg(&dev->pdev->dev, "complete amthi write cb.\n");
Tomas Winklerd2041152012-06-19 09:13:34 +03001324 if (mei_flow_ctrl_creds(dev, cl) <= 0) {
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001325 dev_dbg(&dev->pdev->dev,
Tomas Winkler483136e2012-07-04 19:24:54 +03001326 "No flow control credentials for amthi client %d.\n",
1327 cl->host_client_id);
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001328 continue;
1329 }
Tomas Winkler483136e2012-07-04 19:24:54 +03001330 ret = _mei_irq_thread_cmpl_iamthif(dev, slots, pos,
1331 cl, cmpl_list);
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001332 if (ret)
1333 return ret;
Oren Weilfb7d8792011-05-15 13:43:42 +03001334
1335 }
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001336
Oren Weilfb7d8792011-05-15 13:43:42 +03001337 }
1338 return 0;
1339}
1340
1341
1342
1343/**
1344 * mei_timer - timer function.
1345 *
1346 * @work: pointer to the work_struct structure
1347 *
1348 * NOTE: This function is called by timer interrupt work
1349 */
Oren Weila61c6532011-09-07 09:03:13 +03001350void mei_timer(struct work_struct *work)
Oren Weilfb7d8792011-05-15 13:43:42 +03001351{
1352 unsigned long timeout;
1353 struct mei_cl *cl_pos = NULL;
1354 struct mei_cl *cl_next = NULL;
1355 struct list_head *amthi_complete_list = NULL;
1356 struct mei_cl_cb *cb_pos = NULL;
1357 struct mei_cl_cb *cb_next = NULL;
1358
1359 struct mei_device *dev = container_of(work,
Oren Weila61c6532011-09-07 09:03:13 +03001360 struct mei_device, timer_work.work);
Oren Weilfb7d8792011-05-15 13:43:42 +03001361
1362
1363 mutex_lock(&dev->device_lock);
Tomas Winklerb210d752012-08-07 00:03:56 +03001364 if (dev->dev_state != MEI_DEV_ENABLED) {
1365 if (dev->dev_state == MEI_DEV_INIT_CLIENTS) {
Oren Weilfb7d8792011-05-15 13:43:42 +03001366 if (dev->init_clients_timer) {
1367 if (--dev->init_clients_timer == 0) {
1368 dev_dbg(&dev->pdev->dev, "IMEI reset due to init clients timeout ,init clients state = %d.\n",
1369 dev->init_clients_state);
1370 mei_reset(dev, 1);
1371 }
1372 }
1373 }
1374 goto out;
1375 }
1376 /*** connect/disconnect timeouts ***/
1377 list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) {
1378 if (cl_pos->timer_count) {
1379 if (--cl_pos->timer_count == 0) {
1380 dev_dbg(&dev->pdev->dev, "HECI reset due to connect/disconnect timeout.\n");
1381 mei_reset(dev, 1);
1382 goto out;
1383 }
1384 }
1385 }
1386
Oren Weilfb7d8792011-05-15 13:43:42 +03001387 if (dev->iamthif_stall_timer) {
1388 if (--dev->iamthif_stall_timer == 0) {
Masanari Iida32de21f2012-01-25 23:14:56 +09001389 dev_dbg(&dev->pdev->dev, "resetting because of hang to amthi.\n");
Oren Weilfb7d8792011-05-15 13:43:42 +03001390 mei_reset(dev, 1);
1391 dev->iamthif_msg_buf_size = 0;
1392 dev->iamthif_msg_buf_index = 0;
Tomas Winklereb9af0a2011-05-25 17:28:22 +03001393 dev->iamthif_canceled = false;
1394 dev->iamthif_ioctl = true;
Oren Weilfb7d8792011-05-15 13:43:42 +03001395 dev->iamthif_state = MEI_IAMTHIF_IDLE;
1396 dev->iamthif_timer = 0;
1397
1398 if (dev->iamthif_current_cb)
1399 mei_free_cb_private(dev->iamthif_current_cb);
1400
1401 dev->iamthif_file_object = NULL;
1402 dev->iamthif_current_cb = NULL;
Tomas Winklerc95efb72011-05-25 17:28:21 +03001403 mei_run_next_iamthif_cmd(dev);
Oren Weilfb7d8792011-05-15 13:43:42 +03001404 }
1405 }
1406
1407 if (dev->iamthif_timer) {
1408
1409 timeout = dev->iamthif_timer +
1410 msecs_to_jiffies(IAMTHIF_READ_TIMER);
1411
1412 dev_dbg(&dev->pdev->dev, "dev->iamthif_timer = %ld\n",
1413 dev->iamthif_timer);
1414 dev_dbg(&dev->pdev->dev, "timeout = %ld\n", timeout);
1415 dev_dbg(&dev->pdev->dev, "jiffies = %ld\n", jiffies);
1416 if (time_after(jiffies, timeout)) {
1417 /*
1418 * User didn't read the AMTHI data on time (15sec)
1419 * freeing AMTHI for other requests
1420 */
1421
1422 dev_dbg(&dev->pdev->dev, "freeing AMTHI for other requests\n");
1423
1424 amthi_complete_list = &dev->amthi_read_complete_list.
1425 mei_cb.cb_list;
1426
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001427 list_for_each_entry_safe(cb_pos, cb_next, amthi_complete_list, cb_list) {
Oren Weilfb7d8792011-05-15 13:43:42 +03001428
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001429 cl_pos = cb_pos->file_object->private_data;
Oren Weilfb7d8792011-05-15 13:43:42 +03001430
Tomas Winklerb7cd2d92011-11-27 21:43:34 +02001431 /* Finding the AMTHI entry. */
1432 if (cl_pos == &dev->iamthif_cl)
1433 list_del(&cb_pos->cb_list);
Oren Weilfb7d8792011-05-15 13:43:42 +03001434 }
1435 if (dev->iamthif_current_cb)
1436 mei_free_cb_private(dev->iamthif_current_cb);
1437
1438 dev->iamthif_file_object->private_data = NULL;
1439 dev->iamthif_file_object = NULL;
1440 dev->iamthif_current_cb = NULL;
1441 dev->iamthif_timer = 0;
Tomas Winklerc95efb72011-05-25 17:28:21 +03001442 mei_run_next_iamthif_cmd(dev);
Oren Weilfb7d8792011-05-15 13:43:42 +03001443
1444 }
1445 }
1446out:
Tomas Winkler441ab502011-12-13 23:39:34 +02001447 schedule_delayed_work(&dev->timer_work, 2 * HZ);
1448 mutex_unlock(&dev->device_lock);
Oren Weilfb7d8792011-05-15 13:43:42 +03001449}
1450
1451/**
1452 * mei_interrupt_thread_handler - function called after ISR to handle the interrupt
1453 * processing.
1454 *
1455 * @irq: The irq number
1456 * @dev_id: pointer to the device structure
1457 *
1458 * returns irqreturn_t
1459 *
1460 */
1461irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id)
1462{
1463 struct mei_device *dev = (struct mei_device *) dev_id;
1464 struct mei_io_list complete_list;
1465 struct mei_cl_cb *cb_pos = NULL, *cb_next = NULL;
1466 struct mei_cl *cl;
1467 s32 slots;
1468 int rets;
1469 bool bus_message_received;
1470
1471
1472 dev_dbg(&dev->pdev->dev, "function called after ISR to handle the interrupt processing.\n");
1473 /* initialize our complete list */
1474 mutex_lock(&dev->device_lock);
Tomas Winkler0288c7c2011-06-06 10:44:34 +03001475 mei_io_list_init(&complete_list);
Oren Weilfb7d8792011-05-15 13:43:42 +03001476 dev->host_hw_state = mei_hcsr_read(dev);
Tomas Winkler4f61a7a2011-07-14 20:11:25 +03001477
1478 /* Ack the interrupt here
Justin P. Mattock5f9092f32012-03-12 07:18:09 -07001479 * In case of MSI we don't go through the quick handler */
Tomas Winkler4f61a7a2011-07-14 20:11:25 +03001480 if (pci_dev_msi_enabled(dev->pdev))
1481 mei_reg_write(dev, H_CSR, dev->host_hw_state);
1482
Oren Weilfb7d8792011-05-15 13:43:42 +03001483 dev->me_hw_state = mei_mecsr_read(dev);
1484
1485 /* check if ME wants a reset */
1486 if ((dev->me_hw_state & ME_RDY_HRA) == 0 &&
Tomas Winklerb210d752012-08-07 00:03:56 +03001487 dev->dev_state != MEI_DEV_RESETING &&
1488 dev->dev_state != MEI_DEV_INITIALIZING) {
Oren Weilfb7d8792011-05-15 13:43:42 +03001489 dev_dbg(&dev->pdev->dev, "FW not ready.\n");
1490 mei_reset(dev, 1);
1491 mutex_unlock(&dev->device_lock);
1492 return IRQ_HANDLED;
1493 }
1494
1495 /* check if we need to start the dev */
1496 if ((dev->host_hw_state & H_RDY) == 0) {
1497 if ((dev->me_hw_state & ME_RDY_HRA) == ME_RDY_HRA) {
1498 dev_dbg(&dev->pdev->dev, "we need to start the dev.\n");
1499 dev->host_hw_state |= (H_IE | H_IG | H_RDY);
1500 mei_hcsr_set(dev);
Tomas Winklerb210d752012-08-07 00:03:56 +03001501 dev->dev_state = MEI_DEV_INIT_CLIENTS;
Oren Weilfb7d8792011-05-15 13:43:42 +03001502 dev_dbg(&dev->pdev->dev, "link is established start sending messages.\n");
1503 /* link is established
1504 * start sending messages.
1505 */
Tomas Winklerc95efb72011-05-25 17:28:21 +03001506 mei_host_start_message(dev);
Oren Weilfb7d8792011-05-15 13:43:42 +03001507 mutex_unlock(&dev->device_lock);
1508 return IRQ_HANDLED;
1509 } else {
1510 dev_dbg(&dev->pdev->dev, "FW not ready.\n");
1511 mutex_unlock(&dev->device_lock);
1512 return IRQ_HANDLED;
1513 }
1514 }
Justin P. Mattock5f9092f32012-03-12 07:18:09 -07001515 /* check slots available for reading */
Oren Weilfb7d8792011-05-15 13:43:42 +03001516 slots = mei_count_full_read_slots(dev);
1517 dev_dbg(&dev->pdev->dev, "slots =%08x extra_write_index =%08x.\n",
1518 slots, dev->extra_write_index);
1519 while (slots > 0 && !dev->extra_write_index) {
1520 dev_dbg(&dev->pdev->dev, "slots =%08x extra_write_index =%08x.\n",
1521 slots, dev->extra_write_index);
1522 dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_handler.\n");
1523 rets = mei_irq_thread_read_handler(&complete_list, dev, &slots);
1524 if (rets)
1525 goto end;
1526 }
1527 rets = mei_irq_thread_write_handler(&complete_list, dev, &slots);
1528end:
1529 dev_dbg(&dev->pdev->dev, "end of bottom half function.\n");
1530 dev->host_hw_state = mei_hcsr_read(dev);
Tomas Winkler726917f2012-06-25 23:46:28 +03001531 dev->mei_host_buffer_is_empty = mei_hbuf_is_empty(dev);
Oren Weilfb7d8792011-05-15 13:43:42 +03001532
1533 bus_message_received = false;
1534 if (dev->recvd_msg && waitqueue_active(&dev->wait_recvd_msg)) {
1535 dev_dbg(&dev->pdev->dev, "received waiting bus message\n");
1536 bus_message_received = true;
1537 }
1538 mutex_unlock(&dev->device_lock);
1539 if (bus_message_received) {
1540 dev_dbg(&dev->pdev->dev, "wake up dev->wait_recvd_msg\n");
1541 wake_up_interruptible(&dev->wait_recvd_msg);
1542 bus_message_received = false;
1543 }
Tomas Winklerc8372092011-11-27 21:43:33 +02001544 if (list_empty(&complete_list.mei_cb.cb_list))
Oren Weilfb7d8792011-05-15 13:43:42 +03001545 return IRQ_HANDLED;
1546
1547
1548 list_for_each_entry_safe(cb_pos, cb_next,
1549 &complete_list.mei_cb.cb_list, cb_list) {
1550 cl = (struct mei_cl *)cb_pos->file_private;
1551 list_del(&cb_pos->cb_list);
1552 if (cl) {
1553 if (cl != &dev->iamthif_cl) {
1554 dev_dbg(&dev->pdev->dev, "completing call back.\n");
1555 _mei_cmpl(cl, cb_pos);
1556 cb_pos = NULL;
1557 } else if (cl == &dev->iamthif_cl) {
1558 _mei_cmpl_iamthif(dev, cb_pos);
1559 }
1560 }
1561 }
1562 return IRQ_HANDLED;
1563}