3 * Intel Management Engine Interface (Intel MEI) Linux driver
4 * Copyright (c) 2003-2012, Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 #include <linux/pci.h>
19 #include <linux/kthread.h>
20 #include <linux/interrupt.h>
22 #include <linux/jiffies.h>
27 #include "interface.h"
31 * mei_interrupt_quick_handler - The ISR of the MEI device
33 * @irq: The irq number
34 * @dev_id: pointer to the device structure
38 irqreturn_t
mei_interrupt_quick_handler(int irq
, void *dev_id
)
40 struct mei_device
*dev
= (struct mei_device
*) dev_id
;
41 u32 csr_reg
= mei_hcsr_read(dev
);
43 if ((csr_reg
& H_IS
) != H_IS
)
46 /* clear H_IS bit in H_CSR */
47 mei_reg_write(dev
, H_CSR
, csr_reg
);
49 return IRQ_WAKE_THREAD
;
53 * _mei_cmpl - processes completed operation.
55 * @cl: private data of the file object.
56 * @cb_pos: callback block.
58 static void _mei_cmpl(struct mei_cl
*cl
, struct mei_cl_cb
*cb_pos
)
60 if (cb_pos
->major_file_operations
== MEI_WRITE
) {
61 mei_free_cb_private(cb_pos
);
63 cl
->writing_state
= MEI_WRITE_COMPLETE
;
64 if (waitqueue_active(&cl
->tx_wait
))
65 wake_up_interruptible(&cl
->tx_wait
);
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
);
77 * _mei_cmpl_iamthif - processes completed iamthif operation.
79 * @dev: the device structure.
80 * @cb_pos: callback block.
82 static void _mei_cmpl_iamthif(struct mei_device
*dev
, struct mei_cl_cb
*cb_pos
)
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
,
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",
97 mei_run_next_iamthif_cmd(dev
);
100 dev_dbg(&dev
->pdev
->dev
, "completing amthi call back.\n");
101 wake_up_interruptible(&dev
->iamthif_cl
.wait
);
106 * mei_irq_thread_read_amthi_message - bottom half read routine after ISR to
107 * handle the read amthi message data processing.
109 * @complete_list: An instance of our list structure
110 * @dev: the device structure
111 * @mei_hdr: header of amthi message
113 * returns 0 on success, <0 on failure.
115 static 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
)
120 struct mei_cl_cb
*cb
;
121 unsigned char *buffer
;
123 BUG_ON(mei_hdr
->me_addr
!= dev
->iamthif_cl
.me_client_id
);
124 BUG_ON(dev
->iamthif_state
!= MEI_IAMTHIF_READING
);
126 buffer
= dev
->iamthif_msg_buf
+ dev
->iamthif_msg_buf_index
;
127 BUG_ON(dev
->iamthif_mtu
< dev
->iamthif_msg_buf_index
+ mei_hdr
->length
);
129 mei_read_slots(dev
, buffer
, mei_hdr
->length
);
131 dev
->iamthif_msg_buf_index
+= mei_hdr
->length
;
133 if (!mei_hdr
->msg_complete
)
136 dev_dbg(&dev
->pdev
->dev
,
137 "amthi_message_buffer_index =%d\n",
140 dev_dbg(&dev
->pdev
->dev
, "completed amthi read.\n ");
141 if (!dev
->iamthif_current_cb
)
144 cb
= dev
->iamthif_current_cb
;
145 dev
->iamthif_current_cb
= NULL
;
147 cl
= (struct mei_cl
*)cb
->file_private
;
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
);
165 * _mei_irq_thread_state_ok - checks if mei header matches file private data
167 * @cl: private data of the file object
168 * @mei_hdr: header of mei client message
170 * returns !=0 if matches, 0 if no match.
172 static int _mei_irq_thread_state_ok(struct mei_cl
*cl
,
173 struct mei_msg_hdr
*mei_hdr
)
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
);
182 * mei_irq_thread_read_client_message - bottom half read routine after ISR to
183 * handle the read mei client message data processing.
185 * @complete_list: An instance of our list structure
186 * @dev: the device structure
187 * @mei_hdr: header of mei client message
189 * returns 0 on success, <0 on failure.
191 static 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
)
196 struct mei_cl_cb
*cb_pos
= NULL
, *cb_next
= NULL
;
197 unsigned char *buffer
= NULL
;
199 dev_dbg(&dev
->pdev
->dev
, "start client msg\n");
200 if (list_empty(&dev
->read_list
.mei_cb
.cb_list
))
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
;
208 buffer
= cb_pos
->response_buffer
.data
+ cb_pos
->information
;
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
);
217 mei_read_slots(dev
, buffer
, mei_hdr
->length
);
219 cb_pos
->information
+= mei_hdr
->length
;
220 if (mei_hdr
->msg_complete
) {
222 list_del(&cb_pos
->cb_list
);
223 dev_dbg(&dev
->pdev
->dev
,
224 "completed read host client = %d,"
226 "data length = %lu\n",
229 cb_pos
->information
);
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
);
245 dev_dbg(&dev
->pdev
->dev
, "message read\n");
247 mei_read_slots(dev
, dev
->rd_msg_buf
, mei_hdr
->length
);
248 dev_dbg(&dev
->pdev
->dev
, "discarding message, header =%08x.\n",
249 *(u32
*) dev
->rd_msg_buf
);
256 * _mei_irq_thread_iamthif_read - prepares to read iamthif data.
258 * @dev: the device structure.
259 * @slots: free slots.
261 * returns 0, OK; otherwise, error.
263 static int _mei_irq_thread_iamthif_read(struct mei_device
*dev
, s32
*slots
)
266 if (((*slots
) * sizeof(u32
)) < (sizeof(struct mei_msg_hdr
)
267 + sizeof(struct hbm_flow_control
))) {
270 *slots
-= (sizeof(struct mei_msg_hdr
) +
271 sizeof(struct hbm_flow_control
) + 3) / 4;
272 if (mei_send_flow_control(dev
, &dev
->iamthif_cl
)) {
273 dev_dbg(&dev
->pdev
->dev
, "iamthif flow control failed\n");
277 dev_dbg(&dev
->pdev
->dev
, "iamthif flow control success\n");
278 dev
->iamthif_state
= MEI_IAMTHIF_READING
;
279 dev
->iamthif_flow_control_pending
= false;
280 dev
->iamthif_msg_buf_index
= 0;
281 dev
->iamthif_msg_buf_size
= 0;
282 dev
->iamthif_stall_timer
= IAMTHIF_STALL_TIMER
;
283 dev
->mei_host_buffer_is_empty
= mei_host_buffer_is_empty(dev
);
288 * _mei_irq_thread_close - processes close related operation.
290 * @dev: the device structure.
291 * @slots: free slots.
292 * @cb_pos: callback block.
293 * @cl: private data of the file object.
294 * @cmpl_list: complete list.
296 * returns 0, OK; otherwise, error.
298 static int _mei_irq_thread_close(struct mei_device
*dev
, s32
*slots
,
299 struct mei_cl_cb
*cb_pos
,
301 struct mei_io_list
*cmpl_list
)
303 if ((*slots
* sizeof(u32
)) >= (sizeof(struct mei_msg_hdr
) +
304 sizeof(struct hbm_client_disconnect_request
))) {
305 *slots
-= (sizeof(struct mei_msg_hdr
) +
306 sizeof(struct hbm_client_disconnect_request
) + 3) / 4;
308 if (mei_disconnect(dev
, cl
)) {
310 cb_pos
->information
= 0;
311 list_move_tail(&cb_pos
->cb_list
,
312 &cmpl_list
->mei_cb
.cb_list
);
315 cl
->state
= MEI_FILE_DISCONNECTING
;
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
;
323 /* return the cancel routine */
331 * is_treat_specially_client - checks if the message belongs
332 * to the file private data.
334 * @cl: private data of the file object
335 * @rs: connect response bus message
338 static bool is_treat_specially_client(struct mei_cl
*cl
,
339 struct hbm_client_connect_response
*rs
)
342 if (cl
->host_client_id
== rs
->host_addr
&&
343 cl
->me_client_id
== rs
->me_addr
) {
345 cl
->state
= MEI_FILE_CONNECTED
;
349 cl
->state
= MEI_FILE_DISCONNECTED
;
350 cl
->status
= -ENODEV
;
360 * mei_client_connect_response - connects to response irq routine
362 * @dev: the device structure
363 * @rs: connect response bus message
365 static void mei_client_connect_response(struct mei_device
*dev
,
366 struct hbm_client_connect_response
*rs
)
370 struct mei_cl_cb
*cb_pos
= NULL
, *cb_next
= NULL
;
372 dev_dbg(&dev
->pdev
->dev
,
373 "connect_response:\n"
381 /* if WD or iamthif client treat specially */
383 if (is_treat_specially_client(&(dev
->wd_cl
), rs
)) {
384 dev_dbg(&dev
->pdev
->dev
, "successfully connected to WD client.\n");
385 mei_watchdog_register(dev
);
387 /* next step in the state maching */
388 mei_host_init_iamthif(dev
);
392 if (is_treat_specially_client(&(dev
->iamthif_cl
), rs
)) {
393 dev
->iamthif_state
= MEI_IAMTHIF_IDLE
;
396 list_for_each_entry_safe(cb_pos
, cb_next
,
397 &dev
->ctrl_rd_list
.mei_cb
.cb_list
, cb_list
) {
399 cl
= (struct mei_cl
*)cb_pos
->file_private
;
401 list_del(&cb_pos
->cb_list
);
404 if (MEI_IOCTL
== cb_pos
->major_file_operations
) {
405 if (is_treat_specially_client(cl
, rs
)) {
406 list_del(&cb_pos
->cb_list
);
416 * mei_client_disconnect_response - disconnects from response irq routine
418 * @dev: the device structure
419 * @rs: disconnect response bus message
421 static void mei_client_disconnect_response(struct mei_device
*dev
,
422 struct hbm_client_connect_response
*rs
)
425 struct mei_cl_cb
*cb_pos
= NULL
, *cb_next
= NULL
;
427 dev_dbg(&dev
->pdev
->dev
,
428 "disconnect_response:\n"
436 list_for_each_entry_safe(cb_pos
, cb_next
,
437 &dev
->ctrl_rd_list
.mei_cb
.cb_list
, cb_list
) {
438 cl
= (struct mei_cl
*)cb_pos
->file_private
;
441 list_del(&cb_pos
->cb_list
);
445 dev_dbg(&dev
->pdev
->dev
, "list_for_each_entry_safe in ctrl_rd_list.\n");
446 if (cl
->host_client_id
== rs
->host_addr
&&
447 cl
->me_client_id
== rs
->me_addr
) {
449 list_del(&cb_pos
->cb_list
);
451 cl
->state
= MEI_FILE_DISCONNECTED
;
461 * same_flow_addr - tells if they have the same address.
463 * @file: private data of the file object.
464 * @flow: flow control.
466 * returns !=0, same; 0,not.
468 static int same_flow_addr(struct mei_cl
*cl
, struct hbm_flow_control
*flow
)
470 return (cl
->host_client_id
== flow
->host_addr
&&
471 cl
->me_client_id
== flow
->me_addr
);
475 * add_single_flow_creds - adds single buffer credentials.
477 * @file: private data ot the file object.
478 * @flow: flow control.
480 static void add_single_flow_creds(struct mei_device
*dev
,
481 struct hbm_flow_control
*flow
)
483 struct mei_me_client
*client
;
486 for (i
= 0; i
< dev
->me_clients_num
; i
++) {
487 client
= &dev
->me_clients
[i
];
488 if (client
&& flow
->me_addr
== client
->client_id
) {
489 if (client
->props
.single_recv_buf
) {
490 client
->mei_flow_ctrl_creds
++;
491 dev_dbg(&dev
->pdev
->dev
, "recv flow ctrl msg ME %d (single).\n",
493 dev_dbg(&dev
->pdev
->dev
, "flow control credentials =%d.\n",
494 client
->mei_flow_ctrl_creds
);
496 BUG(); /* error in flow control */
503 * mei_client_flow_control_response - flow control response irq routine
505 * @dev: the device structure
506 * @flow_control: flow control response bus message
508 static void mei_client_flow_control_response(struct mei_device
*dev
,
509 struct hbm_flow_control
*flow_control
)
511 struct mei_cl
*cl_pos
= NULL
;
512 struct mei_cl
*cl_next
= NULL
;
514 if (!flow_control
->host_addr
) {
515 /* single receive buffer */
516 add_single_flow_creds(dev
, flow_control
);
518 /* normal connection */
519 list_for_each_entry_safe(cl_pos
, cl_next
,
520 &dev
->file_list
, link
) {
521 dev_dbg(&dev
->pdev
->dev
, "list_for_each_entry_safe in file_list\n");
523 dev_dbg(&dev
->pdev
->dev
, "cl of host client %d ME client %d.\n",
524 cl_pos
->host_client_id
,
525 cl_pos
->me_client_id
);
526 dev_dbg(&dev
->pdev
->dev
, "flow ctrl msg for host %d ME %d.\n",
527 flow_control
->host_addr
,
528 flow_control
->me_addr
);
529 if (same_flow_addr(cl_pos
, flow_control
)) {
530 dev_dbg(&dev
->pdev
->dev
, "recv ctrl msg for host %d ME %d.\n",
531 flow_control
->host_addr
,
532 flow_control
->me_addr
);
533 cl_pos
->mei_flow_ctrl_creds
++;
534 dev_dbg(&dev
->pdev
->dev
, "flow control credentials = %d.\n",
535 cl_pos
->mei_flow_ctrl_creds
);
543 * same_disconn_addr - tells if they have the same address
545 * @file: private data of the file object.
546 * @disconn: disconnection request.
548 * returns !=0, same; 0,not.
550 static int same_disconn_addr(struct mei_cl
*cl
,
551 struct hbm_client_disconnect_request
*disconn
)
553 return (cl
->host_client_id
== disconn
->host_addr
&&
554 cl
->me_client_id
== disconn
->me_addr
);
558 * mei_client_disconnect_request - disconnects from request irq routine
560 * @dev: the device structure.
561 * @disconnect_req: disconnect request bus message.
563 static void mei_client_disconnect_request(struct mei_device
*dev
,
564 struct hbm_client_disconnect_request
*disconnect_req
)
566 struct mei_msg_hdr
*mei_hdr
;
567 struct hbm_client_connect_response
*disconnect_res
;
568 struct mei_cl
*cl_pos
= NULL
;
569 struct mei_cl
*cl_next
= NULL
;
571 list_for_each_entry_safe(cl_pos
, cl_next
, &dev
->file_list
, link
) {
572 if (same_disconn_addr(cl_pos
, disconnect_req
)) {
573 dev_dbg(&dev
->pdev
->dev
, "disconnect request host client %d ME client %d.\n",
574 disconnect_req
->host_addr
,
575 disconnect_req
->me_addr
);
576 cl_pos
->state
= MEI_FILE_DISCONNECTED
;
577 cl_pos
->timer_count
= 0;
578 if (cl_pos
== &dev
->wd_cl
) {
579 dev
->wd_due_counter
= 0;
580 dev
->wd_pending
= false;
581 } else if (cl_pos
== &dev
->iamthif_cl
)
582 dev
->iamthif_timer
= 0;
584 /* prepare disconnect response */
586 (struct mei_msg_hdr
*) &dev
->ext_msg_buf
[0];
587 mei_hdr
->host_addr
= 0;
588 mei_hdr
->me_addr
= 0;
590 sizeof(struct hbm_client_connect_response
);
591 mei_hdr
->msg_complete
= 1;
592 mei_hdr
->reserved
= 0;
595 (struct hbm_client_connect_response
*)
596 &dev
->ext_msg_buf
[1];
597 disconnect_res
->host_addr
= cl_pos
->host_client_id
;
598 disconnect_res
->me_addr
= cl_pos
->me_client_id
;
599 disconnect_res
->hbm_cmd
= CLIENT_DISCONNECT_RES_CMD
;
600 disconnect_res
->status
= 0;
601 dev
->extra_write_index
= 2;
609 * mei_irq_thread_read_bus_message - bottom half read routine after ISR to
610 * handle the read bus message cmd processing.
612 * @dev: the device structure
613 * @mei_hdr: header of bus message
615 static void mei_irq_thread_read_bus_message(struct mei_device
*dev
,
616 struct mei_msg_hdr
*mei_hdr
)
618 struct mei_bus_message
*mei_msg
;
619 struct hbm_host_version_response
*version_res
;
620 struct hbm_client_connect_response
*connect_res
;
621 struct hbm_client_connect_response
*disconnect_res
;
622 struct hbm_flow_control
*flow_control
;
623 struct hbm_props_response
*props_res
;
624 struct hbm_host_enum_response
*enum_res
;
625 struct hbm_client_disconnect_request
*disconnect_req
;
626 struct hbm_host_stop_request
*host_stop_req
;
630 /* read the message to our buffer */
631 BUG_ON(mei_hdr
->length
>= sizeof(dev
->rd_msg_buf
));
632 mei_read_slots(dev
, dev
->rd_msg_buf
, mei_hdr
->length
);
633 mei_msg
= (struct mei_bus_message
*)dev
->rd_msg_buf
;
635 switch (mei_msg
->hbm_cmd
) {
636 case HOST_START_RES_CMD
:
637 version_res
= (struct hbm_host_version_response
*) mei_msg
;
638 if (version_res
->host_version_supported
) {
639 dev
->version
.major_version
= HBM_MAJOR_VERSION
;
640 dev
->version
.minor_version
= HBM_MINOR_VERSION
;
641 if (dev
->mei_state
== MEI_INIT_CLIENTS
&&
642 dev
->init_clients_state
== MEI_START_MESSAGE
) {
643 dev
->init_clients_timer
= 0;
644 mei_host_enum_clients_message(dev
);
646 dev
->recvd_msg
= false;
647 dev_dbg(&dev
->pdev
->dev
, "IMEI reset due to received host start response bus message.\n");
652 dev
->version
= version_res
->me_max_version
;
653 /* send stop message */
654 mei_hdr
= (struct mei_msg_hdr
*)&dev
->wr_msg_buf
[0];
655 mei_hdr
->host_addr
= 0;
656 mei_hdr
->me_addr
= 0;
657 mei_hdr
->length
= sizeof(struct hbm_host_stop_request
);
658 mei_hdr
->msg_complete
= 1;
659 mei_hdr
->reserved
= 0;
661 host_stop_req
= (struct hbm_host_stop_request
*)
664 memset(host_stop_req
,
666 sizeof(struct hbm_host_stop_request
));
667 host_stop_req
->hbm_cmd
= HOST_STOP_REQ_CMD
;
668 host_stop_req
->reason
= DRIVER_STOP_REQUEST
;
669 mei_write_message(dev
, mei_hdr
,
670 (unsigned char *) (host_stop_req
),
672 dev_dbg(&dev
->pdev
->dev
, "version mismatch.\n");
676 dev
->recvd_msg
= true;
677 dev_dbg(&dev
->pdev
->dev
, "host start response message received.\n");
680 case CLIENT_CONNECT_RES_CMD
:
682 (struct hbm_client_connect_response
*) mei_msg
;
683 mei_client_connect_response(dev
, connect_res
);
684 dev_dbg(&dev
->pdev
->dev
, "client connect response message received.\n");
685 wake_up(&dev
->wait_recvd_msg
);
688 case CLIENT_DISCONNECT_RES_CMD
:
690 (struct hbm_client_connect_response
*) mei_msg
;
691 mei_client_disconnect_response(dev
, disconnect_res
);
692 dev_dbg(&dev
->pdev
->dev
, "client disconnect response message received.\n");
693 wake_up(&dev
->wait_recvd_msg
);
696 case MEI_FLOW_CONTROL_CMD
:
697 flow_control
= (struct hbm_flow_control
*) mei_msg
;
698 mei_client_flow_control_response(dev
, flow_control
);
699 dev_dbg(&dev
->pdev
->dev
, "client flow control response message received.\n");
702 case HOST_CLIENT_PROPERTIES_RES_CMD
:
703 props_res
= (struct hbm_props_response
*)mei_msg
;
704 if (props_res
->status
|| !dev
->me_clients
) {
705 dev_dbg(&dev
->pdev
->dev
, "reset due to received host client properties response bus message wrong status.\n");
709 if (dev
->me_clients
[dev
->me_client_presentation_num
]
710 .client_id
== props_res
->address
) {
712 dev
->me_clients
[dev
->me_client_presentation_num
].props
713 = props_res
->client_properties
;
715 if (dev
->mei_state
== MEI_INIT_CLIENTS
&&
716 dev
->init_clients_state
==
717 MEI_CLIENT_PROPERTIES_MESSAGE
) {
718 dev
->me_client_index
++;
719 dev
->me_client_presentation_num
++;
721 /** Send Client Properties request **/
722 res
= mei_host_client_properties(dev
);
724 dev_dbg(&dev
->pdev
->dev
, "mei_host_client_properties() failed");
728 * No more clients to send to.
729 * Clear Map for indicating now ME clients
730 * with associated host client
732 bitmap_zero(dev
->host_clients_map
, MEI_CLIENTS_MAX
);
733 dev
->open_handle_count
= 0;
736 * Reserving the first three client IDs
737 * Client Id 0 - Reserved for MEI Bus Message communications
738 * Client Id 1 - Reserved for Watchdog
739 * Client ID 2 - Reserved for AMTHI
741 bitmap_set(dev
->host_clients_map
, 0, 3);
742 dev
->mei_state
= MEI_ENABLED
;
744 /* if wd initialization fails, initialization the AMTHI client,
745 * otherwise the AMTHI client will be initialized after the WD client connect response
748 if (mei_wd_host_init(dev
))
749 mei_host_init_iamthif(dev
);
753 dev_dbg(&dev
->pdev
->dev
, "reset due to received host client properties response bus message");
758 dev_dbg(&dev
->pdev
->dev
, "reset due to received host client properties response bus message for wrong client ID\n");
764 case HOST_ENUM_RES_CMD
:
765 enum_res
= (struct hbm_host_enum_response
*) mei_msg
;
766 memcpy(dev
->me_clients_map
, enum_res
->valid_addresses
, 32);
767 if (dev
->mei_state
== MEI_INIT_CLIENTS
&&
768 dev
->init_clients_state
== MEI_ENUM_CLIENTS_MESSAGE
) {
769 dev
->init_clients_timer
= 0;
770 dev
->me_client_presentation_num
= 0;
771 dev
->me_client_index
= 0;
772 mei_allocate_me_clients_storage(dev
);
773 dev
->init_clients_state
=
774 MEI_CLIENT_PROPERTIES_MESSAGE
;
775 mei_host_client_properties(dev
);
777 dev_dbg(&dev
->pdev
->dev
, "reset due to received host enumeration clients response bus message.\n");
783 case HOST_STOP_RES_CMD
:
784 dev
->mei_state
= MEI_DISABLED
;
785 dev_dbg(&dev
->pdev
->dev
, "resetting because of FW stop response.\n");
789 case CLIENT_DISCONNECT_REQ_CMD
:
790 /* search for client */
792 (struct hbm_client_disconnect_request
*) mei_msg
;
793 mei_client_disconnect_request(dev
, disconnect_req
);
796 case ME_STOP_REQ_CMD
:
797 /* prepare stop request */
798 mei_hdr
= (struct mei_msg_hdr
*) &dev
->ext_msg_buf
[0];
799 mei_hdr
->host_addr
= 0;
800 mei_hdr
->me_addr
= 0;
801 mei_hdr
->length
= sizeof(struct hbm_host_stop_request
);
802 mei_hdr
->msg_complete
= 1;
803 mei_hdr
->reserved
= 0;
805 (struct hbm_host_stop_request
*) &dev
->ext_msg_buf
[1];
806 memset(host_stop_req
, 0, sizeof(struct hbm_host_stop_request
));
807 host_stop_req
->hbm_cmd
= HOST_STOP_REQ_CMD
;
808 host_stop_req
->reason
= DRIVER_STOP_REQUEST
;
809 host_stop_req
->reserved
[0] = 0;
810 host_stop_req
->reserved
[1] = 0;
811 dev
->extra_write_index
= 2;
823 * _mei_hb_read - processes read related operation.
825 * @dev: the device structure.
826 * @slots: free slots.
827 * @cb_pos: callback block.
828 * @cl: private data of the file object.
829 * @cmpl_list: complete list.
831 * returns 0, OK; otherwise, error.
833 static int _mei_irq_thread_read(struct mei_device
*dev
, s32
*slots
,
834 struct mei_cl_cb
*cb_pos
,
836 struct mei_io_list
*cmpl_list
)
838 if ((*slots
* sizeof(u32
)) >= (sizeof(struct mei_msg_hdr
) +
839 sizeof(struct hbm_flow_control
))) {
840 /* return the cancel routine */
841 list_del(&cb_pos
->cb_list
);
845 *slots
-= (sizeof(struct mei_msg_hdr
) +
846 sizeof(struct hbm_flow_control
) + 3) / 4;
847 if (mei_send_flow_control(dev
, cl
)) {
848 cl
->status
= -ENODEV
;
849 cb_pos
->information
= 0;
850 list_move_tail(&cb_pos
->cb_list
, &cmpl_list
->mei_cb
.cb_list
);
853 list_move_tail(&cb_pos
->cb_list
, &dev
->read_list
.mei_cb
.cb_list
);
860 * _mei_irq_thread_ioctl - processes ioctl related operation.
862 * @dev: the device structure.
863 * @slots: free slots.
864 * @cb_pos: callback block.
865 * @cl: private data of the file object.
866 * @cmpl_list: complete list.
868 * returns 0, OK; otherwise, error.
870 static int _mei_irq_thread_ioctl(struct mei_device
*dev
, s32
*slots
,
871 struct mei_cl_cb
*cb_pos
,
873 struct mei_io_list
*cmpl_list
)
875 if ((*slots
* sizeof(u32
)) >= (sizeof(struct mei_msg_hdr
) +
876 sizeof(struct hbm_client_connect_request
))) {
877 cl
->state
= MEI_FILE_CONNECTING
;
878 *slots
-= (sizeof(struct mei_msg_hdr
) +
879 sizeof(struct hbm_client_connect_request
) + 3) / 4;
880 if (mei_connect(dev
, cl
)) {
881 cl
->status
= -ENODEV
;
882 cb_pos
->information
= 0;
883 list_del(&cb_pos
->cb_list
);
886 list_move_tail(&cb_pos
->cb_list
,
887 &dev
->ctrl_rd_list
.mei_cb
.cb_list
);
888 cl
->timer_count
= MEI_CONNECT_TIMEOUT
;
891 /* return the cancel routine */
892 list_del(&cb_pos
->cb_list
);
900 * _mei_irq_thread_cmpl - processes completed and no-iamthif operation.
902 * @dev: the device structure.
903 * @slots: free slots.
904 * @cb_pos: callback block.
905 * @cl: private data of the file object.
906 * @cmpl_list: complete list.
908 * returns 0, OK; otherwise, error.
910 static int _mei_irq_thread_cmpl(struct mei_device
*dev
, s32
*slots
,
911 struct mei_cl_cb
*cb_pos
,
913 struct mei_io_list
*cmpl_list
)
915 struct mei_msg_hdr
*mei_hdr
;
917 if ((*slots
* sizeof(u32
)) >= (sizeof(struct mei_msg_hdr
) +
918 (cb_pos
->request_buffer
.size
-
919 cb_pos
->information
))) {
920 mei_hdr
= (struct mei_msg_hdr
*) &dev
->wr_msg_buf
[0];
921 mei_hdr
->host_addr
= cl
->host_client_id
;
922 mei_hdr
->me_addr
= cl
->me_client_id
;
923 mei_hdr
->length
= cb_pos
->request_buffer
.size
-
925 mei_hdr
->msg_complete
= 1;
926 mei_hdr
->reserved
= 0;
927 dev_dbg(&dev
->pdev
->dev
, "cb_pos->request_buffer.size =%d"
928 "mei_hdr->msg_complete = %d\n",
929 cb_pos
->request_buffer
.size
,
930 mei_hdr
->msg_complete
);
931 dev_dbg(&dev
->pdev
->dev
, "cb_pos->information =%lu\n",
932 cb_pos
->information
);
933 dev_dbg(&dev
->pdev
->dev
, "mei_hdr->length =%d\n",
935 *slots
-= (sizeof(struct mei_msg_hdr
) +
936 mei_hdr
->length
+ 3) / 4;
937 if (mei_write_message(dev
, mei_hdr
,
939 (cb_pos
->request_buffer
.data
+
940 cb_pos
->information
),
942 cl
->status
= -ENODEV
;
943 list_move_tail(&cb_pos
->cb_list
,
944 &cmpl_list
->mei_cb
.cb_list
);
947 if (mei_flow_ctrl_reduce(dev
, cl
))
950 cb_pos
->information
+= mei_hdr
->length
;
951 list_move_tail(&cb_pos
->cb_list
,
952 &dev
->write_waiting_list
.mei_cb
.cb_list
);
954 } else if (*slots
== ((dev
->host_hw_state
& H_CBD
) >> 24)) {
955 /* buffer is still empty */
956 mei_hdr
= (struct mei_msg_hdr
*) &dev
->wr_msg_buf
[0];
957 mei_hdr
->host_addr
= cl
->host_client_id
;
958 mei_hdr
->me_addr
= cl
->me_client_id
;
960 (*slots
* sizeof(u32
)) - sizeof(struct mei_msg_hdr
);
961 mei_hdr
->msg_complete
= 0;
962 mei_hdr
->reserved
= 0;
964 (*slots
) -= (sizeof(struct mei_msg_hdr
) +
965 mei_hdr
->length
+ 3) / 4;
966 if (mei_write_message(dev
, mei_hdr
,
968 (cb_pos
->request_buffer
.data
+
969 cb_pos
->information
),
971 cl
->status
= -ENODEV
;
972 list_move_tail(&cb_pos
->cb_list
,
973 &cmpl_list
->mei_cb
.cb_list
);
976 cb_pos
->information
+= mei_hdr
->length
;
977 dev_dbg(&dev
->pdev
->dev
,
978 "cb_pos->request_buffer.size =%d"
979 " mei_hdr->msg_complete = %d\n",
980 cb_pos
->request_buffer
.size
,
981 mei_hdr
->msg_complete
);
982 dev_dbg(&dev
->pdev
->dev
, "cb_pos->information =%lu\n",
983 cb_pos
->information
);
984 dev_dbg(&dev
->pdev
->dev
, "mei_hdr->length =%d\n",
996 * _mei_irq_thread_cmpl_iamthif - processes completed iamthif operation.
998 * @dev: the device structure.
999 * @slots: free slots.
1000 * @cb_pos: callback block.
1001 * @cl: private data of the file object.
1002 * @cmpl_list: complete list.
1004 * returns 0, OK; otherwise, error.
1006 static int _mei_irq_thread_cmpl_iamthif(struct mei_device
*dev
, s32
*slots
,
1007 struct mei_cl_cb
*cb_pos
,
1009 struct mei_io_list
*cmpl_list
)
1011 struct mei_msg_hdr
*mei_hdr
;
1013 if ((*slots
* sizeof(u32
)) >= (sizeof(struct mei_msg_hdr
) +
1014 dev
->iamthif_msg_buf_size
-
1015 dev
->iamthif_msg_buf_index
)) {
1016 mei_hdr
= (struct mei_msg_hdr
*) &dev
->wr_msg_buf
[0];
1017 mei_hdr
->host_addr
= cl
->host_client_id
;
1018 mei_hdr
->me_addr
= cl
->me_client_id
;
1019 mei_hdr
->length
= dev
->iamthif_msg_buf_size
-
1020 dev
->iamthif_msg_buf_index
;
1021 mei_hdr
->msg_complete
= 1;
1022 mei_hdr
->reserved
= 0;
1024 *slots
-= (sizeof(struct mei_msg_hdr
) +
1025 mei_hdr
->length
+ 3) / 4;
1027 if (mei_write_message(dev
, mei_hdr
,
1028 (dev
->iamthif_msg_buf
+
1029 dev
->iamthif_msg_buf_index
),
1031 dev
->iamthif_state
= MEI_IAMTHIF_IDLE
;
1032 cl
->status
= -ENODEV
;
1033 list_del(&cb_pos
->cb_list
);
1036 if (mei_flow_ctrl_reduce(dev
, cl
))
1038 dev
->iamthif_msg_buf_index
+= mei_hdr
->length
;
1039 cb_pos
->information
= dev
->iamthif_msg_buf_index
;
1041 dev
->iamthif_state
= MEI_IAMTHIF_FLOW_CONTROL
;
1042 dev
->iamthif_flow_control_pending
= true;
1043 /* save iamthif cb sent to amthi client */
1044 dev
->iamthif_current_cb
= cb_pos
;
1045 list_move_tail(&cb_pos
->cb_list
,
1046 &dev
->write_waiting_list
.mei_cb
.cb_list
);
1049 } else if (*slots
== ((dev
->host_hw_state
& H_CBD
) >> 24)) {
1050 /* buffer is still empty */
1051 mei_hdr
= (struct mei_msg_hdr
*) &dev
->wr_msg_buf
[0];
1052 mei_hdr
->host_addr
= cl
->host_client_id
;
1053 mei_hdr
->me_addr
= cl
->me_client_id
;
1055 (*slots
* sizeof(u32
)) - sizeof(struct mei_msg_hdr
);
1056 mei_hdr
->msg_complete
= 0;
1057 mei_hdr
->reserved
= 0;
1059 *slots
-= (sizeof(struct mei_msg_hdr
) +
1060 mei_hdr
->length
+ 3) / 4;
1062 if (mei_write_message(dev
, mei_hdr
,
1063 (dev
->iamthif_msg_buf
+
1064 dev
->iamthif_msg_buf_index
),
1066 cl
->status
= -ENODEV
;
1067 list_del(&cb_pos
->cb_list
);
1069 dev
->iamthif_msg_buf_index
+= mei_hdr
->length
;
1080 * mei_irq_thread_read_handler - bottom half read routine after ISR to
1081 * handle the read processing.
1083 * @cmpl_list: An instance of our list structure
1084 * @dev: the device structure
1085 * @slots: slots to read.
1087 * returns 0 on success, <0 on failure.
1089 static int mei_irq_thread_read_handler(struct mei_io_list
*cmpl_list
,
1090 struct mei_device
*dev
,
1093 struct mei_msg_hdr
*mei_hdr
;
1094 struct mei_cl
*cl_pos
= NULL
;
1095 struct mei_cl
*cl_next
= NULL
;
1098 if (!dev
->rd_msg_hdr
) {
1099 dev
->rd_msg_hdr
= mei_mecbrw_read(dev
);
1100 dev_dbg(&dev
->pdev
->dev
, "slots =%08x.\n", *slots
);
1102 dev_dbg(&dev
->pdev
->dev
, "slots =%08x.\n", *slots
);
1104 mei_hdr
= (struct mei_msg_hdr
*) &dev
->rd_msg_hdr
;
1105 dev_dbg(&dev
->pdev
->dev
, "mei_hdr->length =%d\n", mei_hdr
->length
);
1107 if (mei_hdr
->reserved
|| !dev
->rd_msg_hdr
) {
1108 dev_dbg(&dev
->pdev
->dev
, "corrupted message header.\n");
1113 if (mei_hdr
->host_addr
|| mei_hdr
->me_addr
) {
1114 list_for_each_entry_safe(cl_pos
, cl_next
,
1115 &dev
->file_list
, link
) {
1116 dev_dbg(&dev
->pdev
->dev
,
1117 "list_for_each_entry_safe read host"
1118 " client = %d, ME client = %d\n",
1119 cl_pos
->host_client_id
,
1120 cl_pos
->me_client_id
);
1121 if (cl_pos
->host_client_id
== mei_hdr
->host_addr
&&
1122 cl_pos
->me_client_id
== mei_hdr
->me_addr
)
1126 if (&cl_pos
->link
== &dev
->file_list
) {
1127 dev_dbg(&dev
->pdev
->dev
, "corrupted message header\n");
1132 if (((*slots
) * sizeof(u32
)) < mei_hdr
->length
) {
1133 dev_dbg(&dev
->pdev
->dev
,
1134 "we can't read the message slots =%08x.\n",
1136 /* we can't read the message */
1141 /* decide where to read the message too */
1142 if (!mei_hdr
->host_addr
) {
1143 dev_dbg(&dev
->pdev
->dev
, "call mei_irq_thread_read_bus_message.\n");
1144 mei_irq_thread_read_bus_message(dev
, mei_hdr
);
1145 dev_dbg(&dev
->pdev
->dev
, "end mei_irq_thread_read_bus_message.\n");
1146 } else if (mei_hdr
->host_addr
== dev
->iamthif_cl
.host_client_id
&&
1147 (MEI_FILE_CONNECTED
== dev
->iamthif_cl
.state
) &&
1148 (dev
->iamthif_state
== MEI_IAMTHIF_READING
)) {
1149 dev_dbg(&dev
->pdev
->dev
, "call mei_irq_thread_read_iamthif_message.\n");
1150 dev_dbg(&dev
->pdev
->dev
, "mei_hdr->length =%d\n",
1152 ret
= mei_irq_thread_read_amthi_message(cmpl_list
,
1158 dev_dbg(&dev
->pdev
->dev
, "call mei_irq_thread_read_client_message.\n");
1159 ret
= mei_irq_thread_read_client_message(cmpl_list
,
1166 /* reset the number of slots and header */
1167 *slots
= mei_count_full_read_slots(dev
);
1168 dev
->rd_msg_hdr
= 0;
1170 if (*slots
== -EOVERFLOW
) {
1171 /* overflow - reset */
1172 dev_dbg(&dev
->pdev
->dev
, "resetting due to slots overflow.\n");
1173 /* set the event since message has been read */
1183 * mei_irq_thread_write_handler - bottom half write routine after
1184 * ISR to handle the write processing.
1186 * @cmpl_list: An instance of our list structure
1187 * @dev: the device structure
1188 * @slots: slots to write.
1190 * returns 0 on success, <0 on failure.
1192 static int mei_irq_thread_write_handler(struct mei_io_list
*cmpl_list
,
1193 struct mei_device
*dev
,
1198 struct mei_cl_cb
*pos
= NULL
, *next
= NULL
;
1199 struct mei_io_list
*list
;
1202 if (!mei_host_buffer_is_empty(dev
)) {
1203 dev_dbg(&dev
->pdev
->dev
, "host buffer is not empty.\n");
1206 *slots
= mei_count_empty_write_slots(dev
);
1207 /* complete all waiting for write CB */
1208 dev_dbg(&dev
->pdev
->dev
, "complete all waiting for write cb.\n");
1210 list
= &dev
->write_waiting_list
;
1211 list_for_each_entry_safe(pos
, next
,
1212 &list
->mei_cb
.cb_list
, cb_list
) {
1213 cl
= (struct mei_cl
*)pos
->file_private
;
1218 list_del(&pos
->cb_list
);
1219 if (MEI_WRITING
== cl
->writing_state
&&
1220 (pos
->major_file_operations
== MEI_WRITE
) &&
1221 (cl
!= &dev
->iamthif_cl
)) {
1222 dev_dbg(&dev
->pdev
->dev
,
1223 "MEI WRITE COMPLETE\n");
1224 cl
->writing_state
= MEI_WRITE_COMPLETE
;
1225 list_add_tail(&pos
->cb_list
,
1226 &cmpl_list
->mei_cb
.cb_list
);
1228 if (cl
== &dev
->iamthif_cl
) {
1229 dev_dbg(&dev
->pdev
->dev
, "check iamthif flow control.\n");
1230 if (dev
->iamthif_flow_control_pending
) {
1231 ret
= _mei_irq_thread_iamthif_read(
1239 if (dev
->stop
&& !dev
->wd_pending
) {
1240 dev
->wd_stopped
= true;
1241 wake_up_interruptible(&dev
->wait_stop_wd
);
1245 if (dev
->extra_write_index
) {
1246 dev_dbg(&dev
->pdev
->dev
, "extra_write_index =%d.\n",
1247 dev
->extra_write_index
);
1248 mei_write_message(dev
,
1249 (struct mei_msg_hdr
*) &dev
->ext_msg_buf
[0],
1250 (unsigned char *) &dev
->ext_msg_buf
[1],
1251 (dev
->extra_write_index
- 1) * sizeof(u32
));
1252 *slots
-= dev
->extra_write_index
;
1253 dev
->extra_write_index
= 0;
1255 if (dev
->mei_state
== MEI_ENABLED
) {
1256 if (dev
->wd_pending
&&
1257 mei_flow_ctrl_creds(dev
, &dev
->wd_cl
) > 0) {
1258 if (mei_wd_send(dev
))
1259 dev_dbg(&dev
->pdev
->dev
, "wd send failed.\n");
1261 if (mei_flow_ctrl_reduce(dev
, &dev
->wd_cl
))
1264 dev
->wd_pending
= false;
1266 if (dev
->wd_timeout
) {
1267 *slots
-= (sizeof(struct mei_msg_hdr
) +
1268 MEI_START_WD_DATA_SIZE
+ 3) / 4;
1269 dev
->wd_due_counter
= 2;
1271 *slots
-= (sizeof(struct mei_msg_hdr
) +
1272 MEI_WD_PARAMS_SIZE
+ 3) / 4;
1273 dev
->wd_due_counter
= 0;
1281 /* complete control write list CB */
1282 dev_dbg(&dev
->pdev
->dev
, "complete control write list cb.\n");
1283 list_for_each_entry_safe(pos
, next
,
1284 &dev
->ctrl_wr_list
.mei_cb
.cb_list
, cb_list
) {
1285 cl
= (struct mei_cl
*) pos
->file_private
;
1287 list_del(&pos
->cb_list
);
1290 switch (pos
->major_file_operations
) {
1292 /* send disconnect message */
1293 ret
= _mei_irq_thread_close(dev
, slots
, pos
, cl
, cmpl_list
);
1299 /* send flow control message */
1300 ret
= _mei_irq_thread_read(dev
, slots
, pos
, cl
, cmpl_list
);
1306 /* connect message */
1307 if (mei_other_client_is_connecting(dev
, cl
))
1309 ret
= _mei_irq_thread_ioctl(dev
, slots
, pos
, cl
, cmpl_list
);
1320 /* complete write list CB */
1321 dev_dbg(&dev
->pdev
->dev
, "complete write list cb.\n");
1322 list_for_each_entry_safe(pos
, next
,
1323 &dev
->write_list
.mei_cb
.cb_list
, cb_list
) {
1324 cl
= (struct mei_cl
*)pos
->file_private
;
1328 if (cl
!= &dev
->iamthif_cl
) {
1329 if (!mei_flow_ctrl_creds(dev
, cl
)) {
1330 dev_dbg(&dev
->pdev
->dev
,
1332 " credentials for client"
1333 " %d, not sending.\n",
1334 cl
->host_client_id
);
1337 ret
= _mei_irq_thread_cmpl(dev
, slots
,
1343 } else if (cl
== &dev
->iamthif_cl
) {
1345 dev_dbg(&dev
->pdev
->dev
, "complete amthi write cb.\n");
1346 if (!mei_flow_ctrl_creds(dev
, cl
)) {
1347 dev_dbg(&dev
->pdev
->dev
,
1349 " credentials for amthi"
1351 cl
->host_client_id
);
1354 ret
= _mei_irq_thread_cmpl_iamthif(dev
,
1371 * mei_timer - timer function.
1373 * @work: pointer to the work_struct structure
1375 * NOTE: This function is called by timer interrupt work
1377 void mei_timer(struct work_struct
*work
)
1379 unsigned long timeout
;
1380 struct mei_cl
*cl_pos
= NULL
;
1381 struct mei_cl
*cl_next
= NULL
;
1382 struct list_head
*amthi_complete_list
= NULL
;
1383 struct mei_cl_cb
*cb_pos
= NULL
;
1384 struct mei_cl_cb
*cb_next
= NULL
;
1386 struct mei_device
*dev
= container_of(work
,
1387 struct mei_device
, timer_work
.work
);
1390 mutex_lock(&dev
->device_lock
);
1391 if (dev
->mei_state
!= MEI_ENABLED
) {
1392 if (dev
->mei_state
== MEI_INIT_CLIENTS
) {
1393 if (dev
->init_clients_timer
) {
1394 if (--dev
->init_clients_timer
== 0) {
1395 dev_dbg(&dev
->pdev
->dev
, "IMEI reset due to init clients timeout ,init clients state = %d.\n",
1396 dev
->init_clients_state
);
1403 /*** connect/disconnect timeouts ***/
1404 list_for_each_entry_safe(cl_pos
, cl_next
, &dev
->file_list
, link
) {
1405 if (cl_pos
->timer_count
) {
1406 if (--cl_pos
->timer_count
== 0) {
1407 dev_dbg(&dev
->pdev
->dev
, "HECI reset due to connect/disconnect timeout.\n");
1414 if (dev
->iamthif_stall_timer
) {
1415 if (--dev
->iamthif_stall_timer
== 0) {
1416 dev_dbg(&dev
->pdev
->dev
, "resetting because of hang to amthi.\n");
1418 dev
->iamthif_msg_buf_size
= 0;
1419 dev
->iamthif_msg_buf_index
= 0;
1420 dev
->iamthif_canceled
= false;
1421 dev
->iamthif_ioctl
= true;
1422 dev
->iamthif_state
= MEI_IAMTHIF_IDLE
;
1423 dev
->iamthif_timer
= 0;
1425 if (dev
->iamthif_current_cb
)
1426 mei_free_cb_private(dev
->iamthif_current_cb
);
1428 dev
->iamthif_file_object
= NULL
;
1429 dev
->iamthif_current_cb
= NULL
;
1430 mei_run_next_iamthif_cmd(dev
);
1434 if (dev
->iamthif_timer
) {
1436 timeout
= dev
->iamthif_timer
+
1437 msecs_to_jiffies(IAMTHIF_READ_TIMER
);
1439 dev_dbg(&dev
->pdev
->dev
, "dev->iamthif_timer = %ld\n",
1440 dev
->iamthif_timer
);
1441 dev_dbg(&dev
->pdev
->dev
, "timeout = %ld\n", timeout
);
1442 dev_dbg(&dev
->pdev
->dev
, "jiffies = %ld\n", jiffies
);
1443 if (time_after(jiffies
, timeout
)) {
1445 * User didn't read the AMTHI data on time (15sec)
1446 * freeing AMTHI for other requests
1449 dev_dbg(&dev
->pdev
->dev
, "freeing AMTHI for other requests\n");
1451 amthi_complete_list
= &dev
->amthi_read_complete_list
.
1454 list_for_each_entry_safe(cb_pos
, cb_next
, amthi_complete_list
, cb_list
) {
1456 cl_pos
= cb_pos
->file_object
->private_data
;
1458 /* Finding the AMTHI entry. */
1459 if (cl_pos
== &dev
->iamthif_cl
)
1460 list_del(&cb_pos
->cb_list
);
1462 if (dev
->iamthif_current_cb
)
1463 mei_free_cb_private(dev
->iamthif_current_cb
);
1465 dev
->iamthif_file_object
->private_data
= NULL
;
1466 dev
->iamthif_file_object
= NULL
;
1467 dev
->iamthif_current_cb
= NULL
;
1468 dev
->iamthif_timer
= 0;
1469 mei_run_next_iamthif_cmd(dev
);
1474 schedule_delayed_work(&dev
->timer_work
, 2 * HZ
);
1475 mutex_unlock(&dev
->device_lock
);
1479 * mei_interrupt_thread_handler - function called after ISR to handle the interrupt
1482 * @irq: The irq number
1483 * @dev_id: pointer to the device structure
1485 * returns irqreturn_t
1488 irqreturn_t
mei_interrupt_thread_handler(int irq
, void *dev_id
)
1490 struct mei_device
*dev
= (struct mei_device
*) dev_id
;
1491 struct mei_io_list complete_list
;
1492 struct mei_cl_cb
*cb_pos
= NULL
, *cb_next
= NULL
;
1496 bool bus_message_received
;
1499 dev_dbg(&dev
->pdev
->dev
, "function called after ISR to handle the interrupt processing.\n");
1500 /* initialize our complete list */
1501 mutex_lock(&dev
->device_lock
);
1502 mei_io_list_init(&complete_list
);
1503 dev
->host_hw_state
= mei_hcsr_read(dev
);
1505 /* Ack the interrupt here
1506 * In case of MSI we don't go through the quick handler */
1507 if (pci_dev_msi_enabled(dev
->pdev
))
1508 mei_reg_write(dev
, H_CSR
, dev
->host_hw_state
);
1510 dev
->me_hw_state
= mei_mecsr_read(dev
);
1512 /* check if ME wants a reset */
1513 if ((dev
->me_hw_state
& ME_RDY_HRA
) == 0 &&
1514 dev
->mei_state
!= MEI_RESETING
&&
1515 dev
->mei_state
!= MEI_INITIALIZING
) {
1516 dev_dbg(&dev
->pdev
->dev
, "FW not ready.\n");
1518 mutex_unlock(&dev
->device_lock
);
1522 /* check if we need to start the dev */
1523 if ((dev
->host_hw_state
& H_RDY
) == 0) {
1524 if ((dev
->me_hw_state
& ME_RDY_HRA
) == ME_RDY_HRA
) {
1525 dev_dbg(&dev
->pdev
->dev
, "we need to start the dev.\n");
1526 dev
->host_hw_state
|= (H_IE
| H_IG
| H_RDY
);
1528 dev
->mei_state
= MEI_INIT_CLIENTS
;
1529 dev_dbg(&dev
->pdev
->dev
, "link is established start sending messages.\n");
1530 /* link is established
1531 * start sending messages.
1533 mei_host_start_message(dev
);
1534 mutex_unlock(&dev
->device_lock
);
1537 dev_dbg(&dev
->pdev
->dev
, "FW not ready.\n");
1538 mutex_unlock(&dev
->device_lock
);
1542 /* check slots available for reading */
1543 slots
= mei_count_full_read_slots(dev
);
1544 dev_dbg(&dev
->pdev
->dev
, "slots =%08x extra_write_index =%08x.\n",
1545 slots
, dev
->extra_write_index
);
1546 while (slots
> 0 && !dev
->extra_write_index
) {
1547 dev_dbg(&dev
->pdev
->dev
, "slots =%08x extra_write_index =%08x.\n",
1548 slots
, dev
->extra_write_index
);
1549 dev_dbg(&dev
->pdev
->dev
, "call mei_irq_thread_read_handler.\n");
1550 rets
= mei_irq_thread_read_handler(&complete_list
, dev
, &slots
);
1554 rets
= mei_irq_thread_write_handler(&complete_list
, dev
, &slots
);
1556 dev_dbg(&dev
->pdev
->dev
, "end of bottom half function.\n");
1557 dev
->host_hw_state
= mei_hcsr_read(dev
);
1558 dev
->mei_host_buffer_is_empty
= mei_host_buffer_is_empty(dev
);
1560 bus_message_received
= false;
1561 if (dev
->recvd_msg
&& waitqueue_active(&dev
->wait_recvd_msg
)) {
1562 dev_dbg(&dev
->pdev
->dev
, "received waiting bus message\n");
1563 bus_message_received
= true;
1565 mutex_unlock(&dev
->device_lock
);
1566 if (bus_message_received
) {
1567 dev_dbg(&dev
->pdev
->dev
, "wake up dev->wait_recvd_msg\n");
1568 wake_up_interruptible(&dev
->wait_recvd_msg
);
1569 bus_message_received
= false;
1571 if (list_empty(&complete_list
.mei_cb
.cb_list
))
1575 list_for_each_entry_safe(cb_pos
, cb_next
,
1576 &complete_list
.mei_cb
.cb_list
, cb_list
) {
1577 cl
= (struct mei_cl
*)cb_pos
->file_private
;
1578 list_del(&cb_pos
->cb_list
);
1580 if (cl
!= &dev
->iamthif_cl
) {
1581 dev_dbg(&dev
->pdev
->dev
, "completing call back.\n");
1582 _mei_cmpl(cl
, cb_pos
);
1584 } else if (cl
== &dev
->iamthif_cl
) {
1585 _mei_cmpl_iamthif(dev
, cb_pos
);