Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Intel Management Engine Interface (Intel MEI) Linux driver |
Tomas Winkler | 733ba91c | 2012-02-09 19:25:53 +0200 | [diff] [blame] | 4 | * Copyright (c) 2003-2012, Intel Corporation. |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 5 | * |
| 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 Winkler | 4f3afe1 | 2012-05-09 16:38:59 +0300 | [diff] [blame] | 25 | #include <linux/mei.h> |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 26 | #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 | */ |
| 38 | irqreturn_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 | */ |
| 58 | static void _mei_cmpl(struct mei_cl *cl, struct mei_cl_cb *cb_pos) |
| 59 | { |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 60 | if (cb_pos->fop_type == MEI_FOP_WRITE) { |
Tomas Winkler | 601a1ef | 2012-10-09 16:50:20 +0200 | [diff] [blame] | 61 | mei_io_cb_free(cb_pos); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 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 | |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 67 | } else if (cb_pos->fop_type == MEI_FOP_READ && |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 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 | /** |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 77 | * _mei_irq_thread_state_ok - checks if mei header matches file private data |
| 78 | * |
| 79 | * @cl: private data of the file object |
| 80 | * @mei_hdr: header of mei client message |
| 81 | * |
| 82 | * returns !=0 if matches, 0 if no match. |
| 83 | */ |
| 84 | static int _mei_irq_thread_state_ok(struct mei_cl *cl, |
| 85 | struct mei_msg_hdr *mei_hdr) |
| 86 | { |
| 87 | return (cl->host_client_id == mei_hdr->host_addr && |
| 88 | cl->me_client_id == mei_hdr->me_addr && |
| 89 | cl->state == MEI_FILE_CONNECTED && |
| 90 | MEI_READ_COMPLETE != cl->reading_state); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * mei_irq_thread_read_client_message - bottom half read routine after ISR to |
| 95 | * handle the read mei client message data processing. |
| 96 | * |
| 97 | * @complete_list: An instance of our list structure |
| 98 | * @dev: the device structure |
| 99 | * @mei_hdr: header of mei client message |
| 100 | * |
| 101 | * returns 0 on success, <0 on failure. |
| 102 | */ |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 103 | static int mei_irq_thread_read_client_message(struct mei_cl_cb *complete_list, |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 104 | struct mei_device *dev, |
| 105 | struct mei_msg_hdr *mei_hdr) |
| 106 | { |
| 107 | struct mei_cl *cl; |
| 108 | struct mei_cl_cb *cb_pos = NULL, *cb_next = NULL; |
Tomas Winkler | 479bc59 | 2011-06-16 00:46:03 +0300 | [diff] [blame] | 109 | unsigned char *buffer = NULL; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 110 | |
| 111 | dev_dbg(&dev->pdev->dev, "start client msg\n"); |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 112 | if (list_empty(&dev->read_list.list)) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 113 | goto quit; |
| 114 | |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 115 | list_for_each_entry_safe(cb_pos, cb_next, &dev->read_list.list, list) { |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 116 | cl = cb_pos->cl; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 117 | if (cl && _mei_irq_thread_state_ok(cl, mei_hdr)) { |
| 118 | cl->reading_state = MEI_READING; |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 119 | buffer = cb_pos->response_buffer.data + cb_pos->buf_idx; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 120 | |
| 121 | if (cb_pos->response_buffer.size < |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 122 | mei_hdr->length + cb_pos->buf_idx) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 123 | dev_dbg(&dev->pdev->dev, "message overflow.\n"); |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 124 | list_del(&cb_pos->list); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 125 | return -ENOMEM; |
| 126 | } |
| 127 | if (buffer) |
| 128 | mei_read_slots(dev, buffer, mei_hdr->length); |
| 129 | |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 130 | cb_pos->buf_idx += mei_hdr->length; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 131 | if (mei_hdr->msg_complete) { |
| 132 | cl->status = 0; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 133 | list_del(&cb_pos->list); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 134 | dev_dbg(&dev->pdev->dev, |
Tomas Winkler | a4136b4 | 2012-09-11 00:43:22 +0300 | [diff] [blame] | 135 | "completed read H cl = %d, ME cl = %d, length = %lu\n", |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 136 | cl->host_client_id, |
| 137 | cl->me_client_id, |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 138 | cb_pos->buf_idx); |
| 139 | |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 140 | list_add_tail(&cb_pos->list, |
| 141 | &complete_list->list); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | break; |
| 145 | } |
| 146 | |
| 147 | } |
| 148 | |
| 149 | quit: |
| 150 | dev_dbg(&dev->pdev->dev, "message read\n"); |
| 151 | if (!buffer) { |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 152 | mei_read_slots(dev, dev->rd_msg_buf, mei_hdr->length); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 153 | dev_dbg(&dev->pdev->dev, "discarding message, header =%08x.\n", |
| 154 | *(u32 *) dev->rd_msg_buf); |
| 155 | } |
| 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | /** |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 161 | * _mei_irq_thread_close - processes close related operation. |
| 162 | * |
| 163 | * @dev: the device structure. |
| 164 | * @slots: free slots. |
| 165 | * @cb_pos: callback block. |
| 166 | * @cl: private data of the file object. |
| 167 | * @cmpl_list: complete list. |
| 168 | * |
| 169 | * returns 0, OK; otherwise, error. |
| 170 | */ |
| 171 | static int _mei_irq_thread_close(struct mei_device *dev, s32 *slots, |
| 172 | struct mei_cl_cb *cb_pos, |
| 173 | struct mei_cl *cl, |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 174 | struct mei_cl_cb *cmpl_list) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 175 | { |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 176 | if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) + |
Tomas Winkler | aeba4a0 | 2012-11-11 17:38:04 +0200 | [diff] [blame] | 177 | sizeof(struct hbm_client_connect_request))) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 178 | return -EBADMSG; |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 179 | |
Tomas Winkler | aeba4a0 | 2012-11-11 17:38:04 +0200 | [diff] [blame] | 180 | *slots -= mei_data2slots(sizeof(struct hbm_client_connect_request)); |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 181 | |
| 182 | if (mei_disconnect(dev, cl)) { |
| 183 | cl->status = 0; |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 184 | cb_pos->buf_idx = 0; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 185 | list_move_tail(&cb_pos->list, &cmpl_list->list); |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 186 | return -EMSGSIZE; |
| 187 | } else { |
| 188 | cl->state = MEI_FILE_DISCONNECTING; |
| 189 | cl->status = 0; |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 190 | cb_pos->buf_idx = 0; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 191 | list_move_tail(&cb_pos->list, &dev->ctrl_rd_list.list); |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 192 | cl->timer_count = MEI_CONNECT_TIMEOUT; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * is_treat_specially_client - checks if the message belongs |
| 200 | * to the file private data. |
| 201 | * |
| 202 | * @cl: private data of the file object |
| 203 | * @rs: connect response bus message |
| 204 | * |
| 205 | */ |
| 206 | static bool is_treat_specially_client(struct mei_cl *cl, |
| 207 | struct hbm_client_connect_response *rs) |
| 208 | { |
| 209 | |
| 210 | if (cl->host_client_id == rs->host_addr && |
| 211 | cl->me_client_id == rs->me_addr) { |
| 212 | if (!rs->status) { |
| 213 | cl->state = MEI_FILE_CONNECTED; |
| 214 | cl->status = 0; |
| 215 | |
| 216 | } else { |
| 217 | cl->state = MEI_FILE_DISCONNECTED; |
| 218 | cl->status = -ENODEV; |
| 219 | } |
| 220 | cl->timer_count = 0; |
| 221 | |
| 222 | return true; |
| 223 | } |
| 224 | return false; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * mei_client_connect_response - connects to response irq routine |
| 229 | * |
| 230 | * @dev: the device structure |
| 231 | * @rs: connect response bus message |
| 232 | */ |
| 233 | static void mei_client_connect_response(struct mei_device *dev, |
| 234 | struct hbm_client_connect_response *rs) |
| 235 | { |
| 236 | |
| 237 | struct mei_cl *cl; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 238 | struct mei_cl_cb *pos = NULL, *next = NULL; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 239 | |
| 240 | dev_dbg(&dev->pdev->dev, |
| 241 | "connect_response:\n" |
| 242 | "ME Client = %d\n" |
| 243 | "Host Client = %d\n" |
| 244 | "Status = %d\n", |
| 245 | rs->me_addr, |
| 246 | rs->host_addr, |
| 247 | rs->status); |
| 248 | |
| 249 | /* if WD or iamthif client treat specially */ |
| 250 | |
| 251 | if (is_treat_specially_client(&(dev->wd_cl), rs)) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 252 | dev_dbg(&dev->pdev->dev, "successfully connected to WD client.\n"); |
Tomas Winkler | 70cd533 | 2011-12-22 18:50:50 +0200 | [diff] [blame] | 253 | mei_watchdog_register(dev); |
Oren Weil | 9ce178e | 2011-09-07 09:03:09 +0300 | [diff] [blame] | 254 | |
Tomas Winkler | 70cd533 | 2011-12-22 18:50:50 +0200 | [diff] [blame] | 255 | /* next step in the state maching */ |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 256 | mei_amthif_host_init(dev); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 257 | return; |
| 258 | } |
| 259 | |
| 260 | if (is_treat_specially_client(&(dev->iamthif_cl), rs)) { |
| 261 | dev->iamthif_state = MEI_IAMTHIF_IDLE; |
| 262 | return; |
| 263 | } |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 264 | list_for_each_entry_safe(pos, next, &dev->ctrl_rd_list.list, list) { |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 265 | |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 266 | cl = pos->cl; |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 267 | if (!cl) { |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 268 | list_del(&pos->list); |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 269 | return; |
| 270 | } |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 271 | if (pos->fop_type == MEI_FOP_IOCTL) { |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 272 | if (is_treat_specially_client(cl, rs)) { |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 273 | list_del(&pos->list); |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 274 | cl->status = 0; |
| 275 | cl->timer_count = 0; |
| 276 | break; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * mei_client_disconnect_response - disconnects from response irq routine |
| 284 | * |
| 285 | * @dev: the device structure |
| 286 | * @rs: disconnect response bus message |
| 287 | */ |
| 288 | static void mei_client_disconnect_response(struct mei_device *dev, |
| 289 | struct hbm_client_connect_response *rs) |
| 290 | { |
| 291 | struct mei_cl *cl; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 292 | struct mei_cl_cb *pos = NULL, *next = NULL; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 293 | |
| 294 | dev_dbg(&dev->pdev->dev, |
| 295 | "disconnect_response:\n" |
| 296 | "ME Client = %d\n" |
| 297 | "Host Client = %d\n" |
| 298 | "Status = %d\n", |
| 299 | rs->me_addr, |
| 300 | rs->host_addr, |
| 301 | rs->status); |
| 302 | |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 303 | list_for_each_entry_safe(pos, next, &dev->ctrl_rd_list.list, list) { |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 304 | cl = pos->cl; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 305 | |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 306 | if (!cl) { |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 307 | list_del(&pos->list); |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 308 | return; |
| 309 | } |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 310 | |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 311 | dev_dbg(&dev->pdev->dev, "list_for_each_entry_safe in ctrl_rd_list.\n"); |
| 312 | if (cl->host_client_id == rs->host_addr && |
| 313 | cl->me_client_id == rs->me_addr) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 314 | |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 315 | list_del(&pos->list); |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 316 | if (!rs->status) |
| 317 | cl->state = MEI_FILE_DISCONNECTED; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 318 | |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 319 | cl->status = 0; |
| 320 | cl->timer_count = 0; |
| 321 | break; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * same_flow_addr - tells if they have the same address. |
| 328 | * |
| 329 | * @file: private data of the file object. |
| 330 | * @flow: flow control. |
| 331 | * |
| 332 | * returns !=0, same; 0,not. |
| 333 | */ |
| 334 | static int same_flow_addr(struct mei_cl *cl, struct hbm_flow_control *flow) |
| 335 | { |
| 336 | return (cl->host_client_id == flow->host_addr && |
| 337 | cl->me_client_id == flow->me_addr); |
| 338 | } |
| 339 | |
| 340 | /** |
| 341 | * add_single_flow_creds - adds single buffer credentials. |
| 342 | * |
| 343 | * @file: private data ot the file object. |
| 344 | * @flow: flow control. |
| 345 | */ |
| 346 | static void add_single_flow_creds(struct mei_device *dev, |
| 347 | struct hbm_flow_control *flow) |
| 348 | { |
| 349 | struct mei_me_client *client; |
| 350 | int i; |
| 351 | |
Tomas Winkler | cf9673d | 2011-06-06 10:44:33 +0300 | [diff] [blame] | 352 | for (i = 0; i < dev->me_clients_num; i++) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 353 | client = &dev->me_clients[i]; |
| 354 | if (client && flow->me_addr == client->client_id) { |
| 355 | if (client->props.single_recv_buf) { |
| 356 | client->mei_flow_ctrl_creds++; |
| 357 | dev_dbg(&dev->pdev->dev, "recv flow ctrl msg ME %d (single).\n", |
| 358 | flow->me_addr); |
| 359 | dev_dbg(&dev->pdev->dev, "flow control credentials =%d.\n", |
| 360 | client->mei_flow_ctrl_creds); |
| 361 | } else { |
| 362 | BUG(); /* error in flow control */ |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | /** |
| 369 | * mei_client_flow_control_response - flow control response irq routine |
| 370 | * |
| 371 | * @dev: the device structure |
| 372 | * @flow_control: flow control response bus message |
| 373 | */ |
| 374 | static void mei_client_flow_control_response(struct mei_device *dev, |
| 375 | struct hbm_flow_control *flow_control) |
| 376 | { |
| 377 | struct mei_cl *cl_pos = NULL; |
| 378 | struct mei_cl *cl_next = NULL; |
| 379 | |
| 380 | if (!flow_control->host_addr) { |
| 381 | /* single receive buffer */ |
| 382 | add_single_flow_creds(dev, flow_control); |
| 383 | } else { |
| 384 | /* normal connection */ |
| 385 | list_for_each_entry_safe(cl_pos, cl_next, |
| 386 | &dev->file_list, link) { |
| 387 | dev_dbg(&dev->pdev->dev, "list_for_each_entry_safe in file_list\n"); |
| 388 | |
| 389 | dev_dbg(&dev->pdev->dev, "cl of host client %d ME client %d.\n", |
| 390 | cl_pos->host_client_id, |
| 391 | cl_pos->me_client_id); |
| 392 | dev_dbg(&dev->pdev->dev, "flow ctrl msg for host %d ME %d.\n", |
| 393 | flow_control->host_addr, |
| 394 | flow_control->me_addr); |
| 395 | if (same_flow_addr(cl_pos, flow_control)) { |
| 396 | dev_dbg(&dev->pdev->dev, "recv ctrl msg for host %d ME %d.\n", |
| 397 | flow_control->host_addr, |
| 398 | flow_control->me_addr); |
| 399 | cl_pos->mei_flow_ctrl_creds++; |
| 400 | dev_dbg(&dev->pdev->dev, "flow control credentials = %d.\n", |
| 401 | cl_pos->mei_flow_ctrl_creds); |
| 402 | break; |
| 403 | } |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | /** |
| 409 | * same_disconn_addr - tells if they have the same address |
| 410 | * |
| 411 | * @file: private data of the file object. |
| 412 | * @disconn: disconnection request. |
| 413 | * |
| 414 | * returns !=0, same; 0,not. |
| 415 | */ |
| 416 | static int same_disconn_addr(struct mei_cl *cl, |
Tomas Winkler | aeba4a0 | 2012-11-11 17:38:04 +0200 | [diff] [blame] | 417 | struct hbm_client_connect_request *req) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 418 | { |
Tomas Winkler | aeba4a0 | 2012-11-11 17:38:04 +0200 | [diff] [blame] | 419 | return (cl->host_client_id == req->host_addr && |
| 420 | cl->me_client_id == req->me_addr); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /** |
| 424 | * mei_client_disconnect_request - disconnects from request irq routine |
| 425 | * |
| 426 | * @dev: the device structure. |
| 427 | * @disconnect_req: disconnect request bus message. |
| 428 | */ |
| 429 | static void mei_client_disconnect_request(struct mei_device *dev, |
Tomas Winkler | aeba4a0 | 2012-11-11 17:38:04 +0200 | [diff] [blame] | 430 | struct hbm_client_connect_request *disconnect_req) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 431 | { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 432 | struct hbm_client_connect_response *disconnect_res; |
Tomas Winkler | 5bd6471 | 2012-11-18 15:13:14 +0200 | [diff] [blame] | 433 | struct mei_cl *pos, *next; |
| 434 | const size_t len = sizeof(struct hbm_client_connect_response); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 435 | |
Tomas Winkler | 5bd6471 | 2012-11-18 15:13:14 +0200 | [diff] [blame] | 436 | list_for_each_entry_safe(pos, next, &dev->file_list, link) { |
| 437 | if (same_disconn_addr(pos, disconnect_req)) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 438 | dev_dbg(&dev->pdev->dev, "disconnect request host client %d ME client %d.\n", |
| 439 | disconnect_req->host_addr, |
| 440 | disconnect_req->me_addr); |
Tomas Winkler | 5bd6471 | 2012-11-18 15:13:14 +0200 | [diff] [blame] | 441 | pos->state = MEI_FILE_DISCONNECTED; |
| 442 | pos->timer_count = 0; |
| 443 | if (pos == &dev->wd_cl) |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 444 | dev->wd_pending = false; |
Tomas Winkler | 5bd6471 | 2012-11-18 15:13:14 +0200 | [diff] [blame] | 445 | else if (pos == &dev->iamthif_cl) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 446 | dev->iamthif_timer = 0; |
| 447 | |
| 448 | /* prepare disconnect response */ |
Tomas Winkler | 5fb54fb | 2012-11-18 15:13:15 +0200 | [diff] [blame^] | 449 | (void)mei_hbm_hdr((u32 *)&dev->wr_ext_msg.hdr, len); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 450 | disconnect_res = |
| 451 | (struct hbm_client_connect_response *) |
Tomas Winkler | 5fb54fb | 2012-11-18 15:13:15 +0200 | [diff] [blame^] | 452 | &dev->wr_ext_msg.data; |
Tomas Winkler | 1ca7e78 | 2012-02-26 23:18:57 +0200 | [diff] [blame] | 453 | disconnect_res->hbm_cmd = CLIENT_DISCONNECT_RES_CMD; |
Tomas Winkler | 5bd6471 | 2012-11-18 15:13:14 +0200 | [diff] [blame] | 454 | disconnect_res->host_addr = pos->host_client_id; |
| 455 | disconnect_res->me_addr = pos->me_client_id; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 456 | disconnect_res->status = 0; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 457 | break; |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 462 | /** |
| 463 | * mei_irq_thread_read_bus_message - bottom half read routine after ISR to |
| 464 | * handle the read bus message cmd processing. |
| 465 | * |
| 466 | * @dev: the device structure |
| 467 | * @mei_hdr: header of bus message |
| 468 | */ |
| 469 | static void mei_irq_thread_read_bus_message(struct mei_device *dev, |
| 470 | struct mei_msg_hdr *mei_hdr) |
| 471 | { |
| 472 | struct mei_bus_message *mei_msg; |
| 473 | struct hbm_host_version_response *version_res; |
| 474 | struct hbm_client_connect_response *connect_res; |
| 475 | struct hbm_client_connect_response *disconnect_res; |
Tomas Winkler | aeba4a0 | 2012-11-11 17:38:04 +0200 | [diff] [blame] | 476 | struct hbm_client_connect_request *disconnect_req; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 477 | struct hbm_flow_control *flow_control; |
| 478 | struct hbm_props_response *props_res; |
| 479 | struct hbm_host_enum_response *enum_res; |
Tomas Winkler | 5bd6471 | 2012-11-18 15:13:14 +0200 | [diff] [blame] | 480 | struct hbm_host_stop_request *stop_req; |
Oren Weil | abc51b6 | 2011-09-21 16:45:30 +0300 | [diff] [blame] | 481 | int res; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 482 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 483 | |
| 484 | /* read the message to our buffer */ |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 485 | BUG_ON(mei_hdr->length >= sizeof(dev->rd_msg_buf)); |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 486 | mei_read_slots(dev, dev->rd_msg_buf, mei_hdr->length); |
| 487 | mei_msg = (struct mei_bus_message *)dev->rd_msg_buf; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 488 | |
Tomas Winkler | 1ca7e78 | 2012-02-26 23:18:57 +0200 | [diff] [blame] | 489 | switch (mei_msg->hbm_cmd) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 490 | case HOST_START_RES_CMD: |
| 491 | version_res = (struct hbm_host_version_response *) mei_msg; |
| 492 | if (version_res->host_version_supported) { |
| 493 | dev->version.major_version = HBM_MAJOR_VERSION; |
| 494 | dev->version.minor_version = HBM_MINOR_VERSION; |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 495 | if (dev->dev_state == MEI_DEV_INIT_CLIENTS && |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 496 | dev->init_clients_state == MEI_START_MESSAGE) { |
| 497 | dev->init_clients_timer = 0; |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 498 | mei_host_enum_clients_message(dev); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 499 | } else { |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 500 | dev->recvd_msg = false; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 501 | dev_dbg(&dev->pdev->dev, "IMEI reset due to received host start response bus message.\n"); |
| 502 | mei_reset(dev, 1); |
| 503 | return; |
| 504 | } |
| 505 | } else { |
Tomas Winkler | 5bd6471 | 2012-11-18 15:13:14 +0200 | [diff] [blame] | 506 | u32 *buf = dev->wr_msg_buf; |
| 507 | const size_t len = sizeof(struct hbm_host_stop_request); |
| 508 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 509 | dev->version = version_res->me_max_version; |
Tomas Winkler | 5bd6471 | 2012-11-18 15:13:14 +0200 | [diff] [blame] | 510 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 511 | /* send stop message */ |
Tomas Winkler | 5bd6471 | 2012-11-18 15:13:14 +0200 | [diff] [blame] | 512 | mei_hdr = mei_hbm_hdr(&buf[0], len); |
| 513 | stop_req = (struct hbm_host_stop_request *)&buf[1]; |
| 514 | memset(stop_req, 0, len); |
| 515 | stop_req->hbm_cmd = HOST_STOP_REQ_CMD; |
| 516 | stop_req->reason = DRIVER_STOP_REQUEST; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 517 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 518 | mei_write_message(dev, mei_hdr, |
Tomas Winkler | 5bd6471 | 2012-11-18 15:13:14 +0200 | [diff] [blame] | 519 | (unsigned char *)stop_req, len); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 520 | dev_dbg(&dev->pdev->dev, "version mismatch.\n"); |
| 521 | return; |
| 522 | } |
| 523 | |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 524 | dev->recvd_msg = true; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 525 | dev_dbg(&dev->pdev->dev, "host start response message received.\n"); |
| 526 | break; |
| 527 | |
| 528 | case CLIENT_CONNECT_RES_CMD: |
Tomas Winkler | 5bd6471 | 2012-11-18 15:13:14 +0200 | [diff] [blame] | 529 | connect_res = (struct hbm_client_connect_response *) mei_msg; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 530 | mei_client_connect_response(dev, connect_res); |
| 531 | dev_dbg(&dev->pdev->dev, "client connect response message received.\n"); |
| 532 | wake_up(&dev->wait_recvd_msg); |
| 533 | break; |
| 534 | |
| 535 | case CLIENT_DISCONNECT_RES_CMD: |
Tomas Winkler | 5bd6471 | 2012-11-18 15:13:14 +0200 | [diff] [blame] | 536 | disconnect_res = (struct hbm_client_connect_response *) mei_msg; |
Tomas Winkler | 441ab50 | 2011-12-13 23:39:34 +0200 | [diff] [blame] | 537 | mei_client_disconnect_response(dev, disconnect_res); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 538 | dev_dbg(&dev->pdev->dev, "client disconnect response message received.\n"); |
| 539 | wake_up(&dev->wait_recvd_msg); |
| 540 | break; |
| 541 | |
| 542 | case MEI_FLOW_CONTROL_CMD: |
| 543 | flow_control = (struct hbm_flow_control *) mei_msg; |
| 544 | mei_client_flow_control_response(dev, flow_control); |
| 545 | dev_dbg(&dev->pdev->dev, "client flow control response message received.\n"); |
| 546 | break; |
| 547 | |
| 548 | case HOST_CLIENT_PROPERTIES_RES_CMD: |
| 549 | props_res = (struct hbm_props_response *)mei_msg; |
| 550 | if (props_res->status || !dev->me_clients) { |
| 551 | dev_dbg(&dev->pdev->dev, "reset due to received host client properties response bus message wrong status.\n"); |
| 552 | mei_reset(dev, 1); |
| 553 | return; |
| 554 | } |
Tomas Winkler | 441ab50 | 2011-12-13 23:39:34 +0200 | [diff] [blame] | 555 | if (dev->me_clients[dev->me_client_presentation_num] |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 556 | .client_id == props_res->address) { |
| 557 | |
| 558 | dev->me_clients[dev->me_client_presentation_num].props |
| 559 | = props_res->client_properties; |
| 560 | |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 561 | if (dev->dev_state == MEI_DEV_INIT_CLIENTS && |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 562 | dev->init_clients_state == |
| 563 | MEI_CLIENT_PROPERTIES_MESSAGE) { |
| 564 | dev->me_client_index++; |
| 565 | dev->me_client_presentation_num++; |
Oren Weil | abc51b6 | 2011-09-21 16:45:30 +0300 | [diff] [blame] | 566 | |
Justin P. Mattock | 5f9092f3 | 2012-03-12 07:18:09 -0700 | [diff] [blame] | 567 | /** Send Client Properties request **/ |
Oren Weil | abc51b6 | 2011-09-21 16:45:30 +0300 | [diff] [blame] | 568 | res = mei_host_client_properties(dev); |
| 569 | if (res < 0) { |
| 570 | dev_dbg(&dev->pdev->dev, "mei_host_client_properties() failed"); |
| 571 | return; |
| 572 | } else if (!res) { |
| 573 | /* |
| 574 | * No more clients to send to. |
| 575 | * Clear Map for indicating now ME clients |
| 576 | * with associated host client |
| 577 | */ |
| 578 | bitmap_zero(dev->host_clients_map, MEI_CLIENTS_MAX); |
| 579 | dev->open_handle_count = 0; |
| 580 | |
| 581 | /* |
| 582 | * Reserving the first three client IDs |
| 583 | * Client Id 0 - Reserved for MEI Bus Message communications |
| 584 | * Client Id 1 - Reserved for Watchdog |
| 585 | * Client ID 2 - Reserved for AMTHI |
| 586 | */ |
| 587 | bitmap_set(dev->host_clients_map, 0, 3); |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 588 | dev->dev_state = MEI_DEV_ENABLED; |
Oren Weil | abc51b6 | 2011-09-21 16:45:30 +0300 | [diff] [blame] | 589 | |
| 590 | /* if wd initialization fails, initialization the AMTHI client, |
| 591 | * otherwise the AMTHI client will be initialized after the WD client connect response |
| 592 | * will be received |
| 593 | */ |
| 594 | if (mei_wd_host_init(dev)) |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 595 | mei_amthif_host_init(dev); |
Oren Weil | abc51b6 | 2011-09-21 16:45:30 +0300 | [diff] [blame] | 596 | } |
| 597 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 598 | } else { |
| 599 | dev_dbg(&dev->pdev->dev, "reset due to received host client properties response bus message"); |
| 600 | mei_reset(dev, 1); |
| 601 | return; |
| 602 | } |
| 603 | } else { |
| 604 | dev_dbg(&dev->pdev->dev, "reset due to received host client properties response bus message for wrong client ID\n"); |
| 605 | mei_reset(dev, 1); |
| 606 | return; |
| 607 | } |
| 608 | break; |
| 609 | |
| 610 | case HOST_ENUM_RES_CMD: |
| 611 | enum_res = (struct hbm_host_enum_response *) mei_msg; |
| 612 | memcpy(dev->me_clients_map, enum_res->valid_addresses, 32); |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 613 | if (dev->dev_state == MEI_DEV_INIT_CLIENTS && |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 614 | dev->init_clients_state == MEI_ENUM_CLIENTS_MESSAGE) { |
| 615 | dev->init_clients_timer = 0; |
| 616 | dev->me_client_presentation_num = 0; |
| 617 | dev->me_client_index = 0; |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 618 | mei_allocate_me_clients_storage(dev); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 619 | dev->init_clients_state = |
| 620 | MEI_CLIENT_PROPERTIES_MESSAGE; |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 621 | mei_host_client_properties(dev); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 622 | } else { |
| 623 | dev_dbg(&dev->pdev->dev, "reset due to received host enumeration clients response bus message.\n"); |
| 624 | mei_reset(dev, 1); |
| 625 | return; |
| 626 | } |
| 627 | break; |
| 628 | |
| 629 | case HOST_STOP_RES_CMD: |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 630 | dev->dev_state = MEI_DEV_DISABLED; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 631 | dev_dbg(&dev->pdev->dev, "resetting because of FW stop response.\n"); |
| 632 | mei_reset(dev, 1); |
| 633 | break; |
| 634 | |
| 635 | case CLIENT_DISCONNECT_REQ_CMD: |
| 636 | /* search for client */ |
Tomas Winkler | aeba4a0 | 2012-11-11 17:38:04 +0200 | [diff] [blame] | 637 | disconnect_req = (struct hbm_client_connect_request *)mei_msg; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 638 | mei_client_disconnect_request(dev, disconnect_req); |
| 639 | break; |
| 640 | |
| 641 | case ME_STOP_REQ_CMD: |
Tomas Winkler | 5bd6471 | 2012-11-18 15:13:14 +0200 | [diff] [blame] | 642 | { |
| 643 | /* prepare stop request: sent in next interrupt event */ |
| 644 | |
Tomas Winkler | 5bd6471 | 2012-11-18 15:13:14 +0200 | [diff] [blame] | 645 | const size_t len = sizeof(struct hbm_host_stop_request); |
| 646 | |
Tomas Winkler | 5fb54fb | 2012-11-18 15:13:15 +0200 | [diff] [blame^] | 647 | mei_hdr = mei_hbm_hdr((u32 *)&dev->wr_ext_msg.hdr, len); |
| 648 | stop_req = (struct hbm_host_stop_request *)&dev->wr_ext_msg.data; |
Tomas Winkler | 5bd6471 | 2012-11-18 15:13:14 +0200 | [diff] [blame] | 649 | memset(stop_req, 0, len); |
| 650 | stop_req->hbm_cmd = HOST_STOP_REQ_CMD; |
| 651 | stop_req->reason = DRIVER_STOP_REQUEST; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 652 | break; |
Tomas Winkler | 5bd6471 | 2012-11-18 15:13:14 +0200 | [diff] [blame] | 653 | } |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 654 | default: |
| 655 | BUG(); |
| 656 | break; |
| 657 | |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | |
| 662 | /** |
| 663 | * _mei_hb_read - processes read related operation. |
| 664 | * |
| 665 | * @dev: the device structure. |
| 666 | * @slots: free slots. |
| 667 | * @cb_pos: callback block. |
| 668 | * @cl: private data of the file object. |
| 669 | * @cmpl_list: complete list. |
| 670 | * |
| 671 | * returns 0, OK; otherwise, error. |
| 672 | */ |
| 673 | static int _mei_irq_thread_read(struct mei_device *dev, s32 *slots, |
| 674 | struct mei_cl_cb *cb_pos, |
| 675 | struct mei_cl *cl, |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 676 | struct mei_cl_cb *cmpl_list) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 677 | { |
Tomas Winkler | 1e69d64 | 2012-05-29 16:39:12 +0300 | [diff] [blame] | 678 | if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) + |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 679 | sizeof(struct hbm_flow_control))) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 680 | /* return the cancel routine */ |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 681 | list_del(&cb_pos->list); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 682 | return -EBADMSG; |
| 683 | } |
| 684 | |
Tomas Winkler | 7bdf72d | 2012-07-04 19:24:52 +0300 | [diff] [blame] | 685 | *slots -= mei_data2slots(sizeof(struct hbm_flow_control)); |
| 686 | |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 687 | if (mei_send_flow_control(dev, cl)) { |
| 688 | cl->status = -ENODEV; |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 689 | cb_pos->buf_idx = 0; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 690 | list_move_tail(&cb_pos->list, &cmpl_list->list); |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 691 | return -ENODEV; |
| 692 | } |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 693 | list_move_tail(&cb_pos->list, &dev->read_list.list); |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 694 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 695 | return 0; |
| 696 | } |
| 697 | |
| 698 | |
| 699 | /** |
| 700 | * _mei_irq_thread_ioctl - processes ioctl related operation. |
| 701 | * |
| 702 | * @dev: the device structure. |
| 703 | * @slots: free slots. |
| 704 | * @cb_pos: callback block. |
| 705 | * @cl: private data of the file object. |
| 706 | * @cmpl_list: complete list. |
| 707 | * |
| 708 | * returns 0, OK; otherwise, error. |
| 709 | */ |
| 710 | static int _mei_irq_thread_ioctl(struct mei_device *dev, s32 *slots, |
| 711 | struct mei_cl_cb *cb_pos, |
| 712 | struct mei_cl *cl, |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 713 | struct mei_cl_cb *cmpl_list) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 714 | { |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 715 | if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) + |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 716 | sizeof(struct hbm_client_connect_request))) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 717 | /* return the cancel routine */ |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 718 | list_del(&cb_pos->list); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 719 | return -EBADMSG; |
| 720 | } |
| 721 | |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 722 | cl->state = MEI_FILE_CONNECTING; |
| 723 | *slots -= mei_data2slots(sizeof(struct hbm_client_connect_request)); |
| 724 | if (mei_connect(dev, cl)) { |
| 725 | cl->status = -ENODEV; |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 726 | cb_pos->buf_idx = 0; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 727 | list_del(&cb_pos->list); |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 728 | return -ENODEV; |
| 729 | } else { |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 730 | list_move_tail(&cb_pos->list, &dev->ctrl_rd_list.list); |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 731 | cl->timer_count = MEI_CONNECT_TIMEOUT; |
| 732 | } |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 733 | return 0; |
| 734 | } |
| 735 | |
| 736 | /** |
| 737 | * _mei_irq_thread_cmpl - processes completed and no-iamthif operation. |
| 738 | * |
| 739 | * @dev: the device structure. |
| 740 | * @slots: free slots. |
| 741 | * @cb_pos: callback block. |
| 742 | * @cl: private data of the file object. |
| 743 | * @cmpl_list: complete list. |
| 744 | * |
| 745 | * returns 0, OK; otherwise, error. |
| 746 | */ |
| 747 | static int _mei_irq_thread_cmpl(struct mei_device *dev, s32 *slots, |
| 748 | struct mei_cl_cb *cb_pos, |
| 749 | struct mei_cl *cl, |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 750 | struct mei_cl_cb *cmpl_list) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 751 | { |
| 752 | struct mei_msg_hdr *mei_hdr; |
| 753 | |
| 754 | if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) + |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 755 | (cb_pos->request_buffer.size - cb_pos->buf_idx))) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 756 | mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0]; |
| 757 | mei_hdr->host_addr = cl->host_client_id; |
| 758 | mei_hdr->me_addr = cl->me_client_id; |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 759 | mei_hdr->length = cb_pos->request_buffer.size - cb_pos->buf_idx; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 760 | mei_hdr->msg_complete = 1; |
| 761 | mei_hdr->reserved = 0; |
| 762 | dev_dbg(&dev->pdev->dev, "cb_pos->request_buffer.size =%d" |
| 763 | "mei_hdr->msg_complete = %d\n", |
| 764 | cb_pos->request_buffer.size, |
| 765 | mei_hdr->msg_complete); |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 766 | dev_dbg(&dev->pdev->dev, "cb_pos->buf_idx =%lu\n", |
| 767 | cb_pos->buf_idx); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 768 | dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n", |
| 769 | mei_hdr->length); |
Tomas Winkler | 7bdf72d | 2012-07-04 19:24:52 +0300 | [diff] [blame] | 770 | *slots -= mei_data2slots(mei_hdr->length); |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 771 | if (mei_write_message(dev, mei_hdr, |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 772 | (unsigned char *) |
| 773 | (cb_pos->request_buffer.data + |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 774 | cb_pos->buf_idx), |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 775 | mei_hdr->length)) { |
| 776 | cl->status = -ENODEV; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 777 | list_move_tail(&cb_pos->list, &cmpl_list->list); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 778 | return -ENODEV; |
| 779 | } else { |
| 780 | if (mei_flow_ctrl_reduce(dev, cl)) |
| 781 | return -ENODEV; |
| 782 | cl->status = 0; |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 783 | cb_pos->buf_idx += mei_hdr->length; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 784 | list_move_tail(&cb_pos->list, &dev->write_waiting_list.list); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 785 | } |
Tomas Winkler | 24aadc8 | 2012-06-25 23:46:27 +0300 | [diff] [blame] | 786 | } else if (*slots == dev->hbuf_depth) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 787 | /* buffer is still empty */ |
| 788 | mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0]; |
| 789 | mei_hdr->host_addr = cl->host_client_id; |
| 790 | mei_hdr->me_addr = cl->me_client_id; |
| 791 | mei_hdr->length = |
| 792 | (*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr); |
| 793 | mei_hdr->msg_complete = 0; |
| 794 | mei_hdr->reserved = 0; |
Tomas Winkler | 7bdf72d | 2012-07-04 19:24:52 +0300 | [diff] [blame] | 795 | *slots -= mei_data2slots(mei_hdr->length); |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 796 | if (mei_write_message(dev, mei_hdr, |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 797 | (unsigned char *) |
| 798 | (cb_pos->request_buffer.data + |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 799 | cb_pos->buf_idx), |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 800 | mei_hdr->length)) { |
| 801 | cl->status = -ENODEV; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 802 | list_move_tail(&cb_pos->list, &cmpl_list->list); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 803 | return -ENODEV; |
| 804 | } else { |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 805 | cb_pos->buf_idx += mei_hdr->length; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 806 | dev_dbg(&dev->pdev->dev, |
| 807 | "cb_pos->request_buffer.size =%d" |
| 808 | " mei_hdr->msg_complete = %d\n", |
| 809 | cb_pos->request_buffer.size, |
| 810 | mei_hdr->msg_complete); |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 811 | dev_dbg(&dev->pdev->dev, "cb_pos->buf_idx =%lu\n", |
| 812 | cb_pos->buf_idx); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 813 | dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n", |
| 814 | mei_hdr->length); |
| 815 | } |
| 816 | return -EMSGSIZE; |
| 817 | } else { |
| 818 | return -EBADMSG; |
| 819 | } |
| 820 | |
| 821 | return 0; |
| 822 | } |
| 823 | |
| 824 | /** |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 825 | * mei_irq_thread_read_handler - bottom half read routine after ISR to |
| 826 | * handle the read processing. |
| 827 | * |
| 828 | * @cmpl_list: An instance of our list structure |
| 829 | * @dev: the device structure |
| 830 | * @slots: slots to read. |
| 831 | * |
| 832 | * returns 0 on success, <0 on failure. |
| 833 | */ |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 834 | static int mei_irq_thread_read_handler(struct mei_cl_cb *cmpl_list, |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 835 | struct mei_device *dev, |
| 836 | s32 *slots) |
| 837 | { |
| 838 | struct mei_msg_hdr *mei_hdr; |
| 839 | struct mei_cl *cl_pos = NULL; |
| 840 | struct mei_cl *cl_next = NULL; |
| 841 | int ret = 0; |
| 842 | |
| 843 | if (!dev->rd_msg_hdr) { |
| 844 | dev->rd_msg_hdr = mei_mecbrw_read(dev); |
| 845 | dev_dbg(&dev->pdev->dev, "slots =%08x.\n", *slots); |
| 846 | (*slots)--; |
| 847 | dev_dbg(&dev->pdev->dev, "slots =%08x.\n", *slots); |
| 848 | } |
| 849 | mei_hdr = (struct mei_msg_hdr *) &dev->rd_msg_hdr; |
| 850 | dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n", mei_hdr->length); |
| 851 | |
| 852 | if (mei_hdr->reserved || !dev->rd_msg_hdr) { |
| 853 | dev_dbg(&dev->pdev->dev, "corrupted message header.\n"); |
| 854 | ret = -EBADMSG; |
| 855 | goto end; |
| 856 | } |
| 857 | |
| 858 | if (mei_hdr->host_addr || mei_hdr->me_addr) { |
| 859 | list_for_each_entry_safe(cl_pos, cl_next, |
| 860 | &dev->file_list, link) { |
| 861 | dev_dbg(&dev->pdev->dev, |
| 862 | "list_for_each_entry_safe read host" |
| 863 | " client = %d, ME client = %d\n", |
| 864 | cl_pos->host_client_id, |
| 865 | cl_pos->me_client_id); |
| 866 | if (cl_pos->host_client_id == mei_hdr->host_addr && |
| 867 | cl_pos->me_client_id == mei_hdr->me_addr) |
| 868 | break; |
| 869 | } |
| 870 | |
| 871 | if (&cl_pos->link == &dev->file_list) { |
| 872 | dev_dbg(&dev->pdev->dev, "corrupted message header\n"); |
| 873 | ret = -EBADMSG; |
| 874 | goto end; |
| 875 | } |
| 876 | } |
| 877 | if (((*slots) * sizeof(u32)) < mei_hdr->length) { |
| 878 | dev_dbg(&dev->pdev->dev, |
| 879 | "we can't read the message slots =%08x.\n", |
| 880 | *slots); |
| 881 | /* we can't read the message */ |
| 882 | ret = -ERANGE; |
| 883 | goto end; |
| 884 | } |
| 885 | |
| 886 | /* decide where to read the message too */ |
| 887 | if (!mei_hdr->host_addr) { |
| 888 | dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_bus_message.\n"); |
| 889 | mei_irq_thread_read_bus_message(dev, mei_hdr); |
| 890 | dev_dbg(&dev->pdev->dev, "end mei_irq_thread_read_bus_message.\n"); |
| 891 | } else if (mei_hdr->host_addr == dev->iamthif_cl.host_client_id && |
| 892 | (MEI_FILE_CONNECTED == dev->iamthif_cl.state) && |
| 893 | (dev->iamthif_state == MEI_IAMTHIF_READING)) { |
| 894 | dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_iamthif_message.\n"); |
| 895 | dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n", |
| 896 | mei_hdr->length); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 897 | |
| 898 | ret = mei_amthif_irq_read_message(cmpl_list, dev, mei_hdr); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 899 | if (ret) |
| 900 | goto end; |
| 901 | |
| 902 | } else { |
| 903 | dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_client_message.\n"); |
| 904 | ret = mei_irq_thread_read_client_message(cmpl_list, |
| 905 | dev, mei_hdr); |
| 906 | if (ret) |
| 907 | goto end; |
| 908 | |
| 909 | } |
| 910 | |
| 911 | /* reset the number of slots and header */ |
| 912 | *slots = mei_count_full_read_slots(dev); |
| 913 | dev->rd_msg_hdr = 0; |
| 914 | |
| 915 | if (*slots == -EOVERFLOW) { |
| 916 | /* overflow - reset */ |
| 917 | dev_dbg(&dev->pdev->dev, "resetting due to slots overflow.\n"); |
| 918 | /* set the event since message has been read */ |
| 919 | ret = -ERANGE; |
| 920 | goto end; |
| 921 | } |
| 922 | end: |
| 923 | return ret; |
| 924 | } |
| 925 | |
| 926 | |
| 927 | /** |
| 928 | * mei_irq_thread_write_handler - bottom half write routine after |
| 929 | * ISR to handle the write processing. |
| 930 | * |
| 931 | * @cmpl_list: An instance of our list structure |
| 932 | * @dev: the device structure |
| 933 | * @slots: slots to write. |
| 934 | * |
| 935 | * returns 0 on success, <0 on failure. |
| 936 | */ |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 937 | static int mei_irq_thread_write_handler(struct mei_cl_cb *cmpl_list, |
| 938 | struct mei_device *dev, s32 *slots) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 939 | { |
| 940 | |
| 941 | struct mei_cl *cl; |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 942 | struct mei_cl_cb *pos = NULL, *next = NULL; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 943 | struct mei_cl_cb *list; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 944 | int ret; |
| 945 | |
Tomas Winkler | 726917f | 2012-06-25 23:46:28 +0300 | [diff] [blame] | 946 | if (!mei_hbuf_is_empty(dev)) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 947 | dev_dbg(&dev->pdev->dev, "host buffer is not empty.\n"); |
| 948 | return 0; |
| 949 | } |
Tomas Winkler | 726917f | 2012-06-25 23:46:28 +0300 | [diff] [blame] | 950 | *slots = mei_hbuf_empty_slots(dev); |
Tomas Winkler | 7d5e0e5 | 2012-06-19 09:13:36 +0300 | [diff] [blame] | 951 | if (*slots <= 0) |
| 952 | return -EMSGSIZE; |
| 953 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 954 | /* complete all waiting for write CB */ |
| 955 | dev_dbg(&dev->pdev->dev, "complete all waiting for write cb.\n"); |
| 956 | |
| 957 | list = &dev->write_waiting_list; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 958 | list_for_each_entry_safe(pos, next, &list->list, list) { |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 959 | cl = pos->cl; |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 960 | if (cl == NULL) |
| 961 | continue; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 962 | |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 963 | cl->status = 0; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 964 | list_del(&pos->list); |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 965 | if (MEI_WRITING == cl->writing_state && |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 966 | pos->fop_type == MEI_FOP_WRITE && |
| 967 | cl != &dev->iamthif_cl) { |
Tomas Winkler | 483136e | 2012-07-04 19:24:54 +0300 | [diff] [blame] | 968 | dev_dbg(&dev->pdev->dev, "MEI WRITE COMPLETE\n"); |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 969 | cl->writing_state = MEI_WRITE_COMPLETE; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 970 | list_add_tail(&pos->list, &cmpl_list->list); |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 971 | } |
| 972 | if (cl == &dev->iamthif_cl) { |
| 973 | dev_dbg(&dev->pdev->dev, "check iamthif flow control.\n"); |
| 974 | if (dev->iamthif_flow_control_pending) { |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 975 | ret = mei_amthif_irq_read(dev, slots); |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 976 | if (ret) |
| 977 | return ret; |
| 978 | } |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 979 | } |
| 980 | } |
| 981 | |
Tomas Winkler | c216fde | 2012-08-16 19:39:43 +0300 | [diff] [blame] | 982 | if (dev->wd_state == MEI_WD_STOPPING) { |
| 983 | dev->wd_state = MEI_WD_IDLE; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 984 | wake_up_interruptible(&dev->wait_stop_wd); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 985 | } |
| 986 | |
Tomas Winkler | 5fb54fb | 2012-11-18 15:13:15 +0200 | [diff] [blame^] | 987 | if (dev->wr_ext_msg.hdr.length) { |
| 988 | mei_write_message(dev, &dev->wr_ext_msg.hdr, |
| 989 | dev->wr_ext_msg.data, dev->wr_ext_msg.hdr.length); |
| 990 | *slots -= mei_data2slots(dev->wr_ext_msg.hdr.length); |
| 991 | dev->wr_ext_msg.hdr.length = 0; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 992 | } |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 993 | if (dev->dev_state == MEI_DEV_ENABLED) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 994 | if (dev->wd_pending && |
Tomas Winkler | 483136e | 2012-07-04 19:24:54 +0300 | [diff] [blame] | 995 | mei_flow_ctrl_creds(dev, &dev->wd_cl) > 0) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 996 | if (mei_wd_send(dev)) |
| 997 | dev_dbg(&dev->pdev->dev, "wd send failed.\n"); |
Tomas Winkler | 483136e | 2012-07-04 19:24:54 +0300 | [diff] [blame] | 998 | else if (mei_flow_ctrl_reduce(dev, &dev->wd_cl)) |
| 999 | return -ENODEV; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1000 | |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 1001 | dev->wd_pending = false; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1002 | |
Tomas Winkler | c216fde | 2012-08-16 19:39:43 +0300 | [diff] [blame] | 1003 | if (dev->wd_state == MEI_WD_RUNNING) |
Tomas Winkler | 248ffdf | 2012-08-16 19:39:42 +0300 | [diff] [blame] | 1004 | *slots -= mei_data2slots(MEI_WD_START_MSG_SIZE); |
Tomas Winkler | d242a0a | 2012-07-04 19:24:50 +0300 | [diff] [blame] | 1005 | else |
Tomas Winkler | 248ffdf | 2012-08-16 19:39:42 +0300 | [diff] [blame] | 1006 | *slots -= mei_data2slots(MEI_WD_STOP_MSG_SIZE); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1007 | } |
| 1008 | } |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1009 | |
| 1010 | /* complete control write list CB */ |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 1011 | dev_dbg(&dev->pdev->dev, "complete control write list cb.\n"); |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 1012 | list_for_each_entry_safe(pos, next, &dev->ctrl_wr_list.list, list) { |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 1013 | cl = pos->cl; |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 1014 | if (!cl) { |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 1015 | list_del(&pos->list); |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 1016 | return -ENODEV; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1017 | } |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 1018 | switch (pos->fop_type) { |
| 1019 | case MEI_FOP_CLOSE: |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 1020 | /* send disconnect message */ |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 1021 | ret = _mei_irq_thread_close(dev, slots, pos, cl, cmpl_list); |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 1022 | if (ret) |
| 1023 | return ret; |
| 1024 | |
| 1025 | break; |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 1026 | case MEI_FOP_READ: |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 1027 | /* send flow control message */ |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 1028 | ret = _mei_irq_thread_read(dev, slots, pos, cl, cmpl_list); |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 1029 | if (ret) |
| 1030 | return ret; |
| 1031 | |
| 1032 | break; |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 1033 | case MEI_FOP_IOCTL: |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 1034 | /* connect message */ |
Natalia Ovsyanikov | e8cd29d | 2011-12-05 00:16:54 +0200 | [diff] [blame] | 1035 | if (mei_other_client_is_connecting(dev, cl)) |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 1036 | continue; |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 1037 | ret = _mei_irq_thread_ioctl(dev, slots, pos, cl, cmpl_list); |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 1038 | if (ret) |
| 1039 | return ret; |
| 1040 | |
| 1041 | break; |
| 1042 | |
| 1043 | default: |
| 1044 | BUG(); |
| 1045 | } |
| 1046 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1047 | } |
| 1048 | /* complete write list CB */ |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 1049 | dev_dbg(&dev->pdev->dev, "complete write list cb.\n"); |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 1050 | list_for_each_entry_safe(pos, next, &dev->write_list.list, list) { |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 1051 | cl = pos->cl; |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 1052 | if (cl == NULL) |
| 1053 | continue; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1054 | |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 1055 | if (cl != &dev->iamthif_cl) { |
Tomas Winkler | d204115 | 2012-06-19 09:13:34 +0300 | [diff] [blame] | 1056 | if (mei_flow_ctrl_creds(dev, cl) <= 0) { |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 1057 | dev_dbg(&dev->pdev->dev, |
Tomas Winkler | 483136e | 2012-07-04 19:24:54 +0300 | [diff] [blame] | 1058 | "No flow control credentials for client %d, not sending.\n", |
| 1059 | cl->host_client_id); |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 1060 | continue; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1061 | } |
Tomas Winkler | 483136e | 2012-07-04 19:24:54 +0300 | [diff] [blame] | 1062 | ret = _mei_irq_thread_cmpl(dev, slots, pos, |
| 1063 | cl, cmpl_list); |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 1064 | if (ret) |
| 1065 | return ret; |
| 1066 | |
| 1067 | } else if (cl == &dev->iamthif_cl) { |
| 1068 | /* IAMTHIF IOCTL */ |
| 1069 | dev_dbg(&dev->pdev->dev, "complete amthi write cb.\n"); |
Tomas Winkler | d204115 | 2012-06-19 09:13:34 +0300 | [diff] [blame] | 1070 | if (mei_flow_ctrl_creds(dev, cl) <= 0) { |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 1071 | dev_dbg(&dev->pdev->dev, |
Tomas Winkler | 483136e | 2012-07-04 19:24:54 +0300 | [diff] [blame] | 1072 | "No flow control credentials for amthi client %d.\n", |
| 1073 | cl->host_client_id); |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 1074 | continue; |
| 1075 | } |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 1076 | ret = mei_amthif_irq_process_completed(dev, slots, pos, |
| 1077 | cl, cmpl_list); |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 1078 | if (ret) |
| 1079 | return ret; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1080 | |
| 1081 | } |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 1082 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1083 | } |
| 1084 | return 0; |
| 1085 | } |
| 1086 | |
| 1087 | |
| 1088 | |
| 1089 | /** |
| 1090 | * mei_timer - timer function. |
| 1091 | * |
| 1092 | * @work: pointer to the work_struct structure |
| 1093 | * |
| 1094 | * NOTE: This function is called by timer interrupt work |
| 1095 | */ |
Oren Weil | a61c653 | 2011-09-07 09:03:13 +0300 | [diff] [blame] | 1096 | void mei_timer(struct work_struct *work) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1097 | { |
| 1098 | unsigned long timeout; |
| 1099 | struct mei_cl *cl_pos = NULL; |
| 1100 | struct mei_cl *cl_next = NULL; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1101 | struct mei_cl_cb *cb_pos = NULL; |
| 1102 | struct mei_cl_cb *cb_next = NULL; |
| 1103 | |
| 1104 | struct mei_device *dev = container_of(work, |
Oren Weil | a61c653 | 2011-09-07 09:03:13 +0300 | [diff] [blame] | 1105 | struct mei_device, timer_work.work); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1106 | |
| 1107 | |
| 1108 | mutex_lock(&dev->device_lock); |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 1109 | if (dev->dev_state != MEI_DEV_ENABLED) { |
| 1110 | if (dev->dev_state == MEI_DEV_INIT_CLIENTS) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1111 | if (dev->init_clients_timer) { |
| 1112 | if (--dev->init_clients_timer == 0) { |
| 1113 | dev_dbg(&dev->pdev->dev, "IMEI reset due to init clients timeout ,init clients state = %d.\n", |
| 1114 | dev->init_clients_state); |
| 1115 | mei_reset(dev, 1); |
| 1116 | } |
| 1117 | } |
| 1118 | } |
| 1119 | goto out; |
| 1120 | } |
| 1121 | /*** connect/disconnect timeouts ***/ |
| 1122 | list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) { |
| 1123 | if (cl_pos->timer_count) { |
| 1124 | if (--cl_pos->timer_count == 0) { |
| 1125 | dev_dbg(&dev->pdev->dev, "HECI reset due to connect/disconnect timeout.\n"); |
| 1126 | mei_reset(dev, 1); |
| 1127 | goto out; |
| 1128 | } |
| 1129 | } |
| 1130 | } |
| 1131 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1132 | if (dev->iamthif_stall_timer) { |
| 1133 | if (--dev->iamthif_stall_timer == 0) { |
Masanari Iida | 32de21f | 2012-01-25 23:14:56 +0900 | [diff] [blame] | 1134 | dev_dbg(&dev->pdev->dev, "resetting because of hang to amthi.\n"); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1135 | mei_reset(dev, 1); |
| 1136 | dev->iamthif_msg_buf_size = 0; |
| 1137 | dev->iamthif_msg_buf_index = 0; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 1138 | dev->iamthif_canceled = false; |
| 1139 | dev->iamthif_ioctl = true; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1140 | dev->iamthif_state = MEI_IAMTHIF_IDLE; |
| 1141 | dev->iamthif_timer = 0; |
| 1142 | |
Tomas Winkler | 601a1ef | 2012-10-09 16:50:20 +0200 | [diff] [blame] | 1143 | mei_io_cb_free(dev->iamthif_current_cb); |
| 1144 | dev->iamthif_current_cb = NULL; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1145 | |
| 1146 | dev->iamthif_file_object = NULL; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 1147 | mei_amthif_run_next_cmd(dev); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | if (dev->iamthif_timer) { |
| 1152 | |
| 1153 | timeout = dev->iamthif_timer + |
Tomas Winkler | 3870c32 | 2012-11-01 21:17:14 +0200 | [diff] [blame] | 1154 | mei_secs_to_jiffies(MEI_IAMTHIF_READ_TIMER); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1155 | |
| 1156 | dev_dbg(&dev->pdev->dev, "dev->iamthif_timer = %ld\n", |
| 1157 | dev->iamthif_timer); |
| 1158 | dev_dbg(&dev->pdev->dev, "timeout = %ld\n", timeout); |
| 1159 | dev_dbg(&dev->pdev->dev, "jiffies = %ld\n", jiffies); |
| 1160 | if (time_after(jiffies, timeout)) { |
| 1161 | /* |
| 1162 | * User didn't read the AMTHI data on time (15sec) |
| 1163 | * freeing AMTHI for other requests |
| 1164 | */ |
| 1165 | |
| 1166 | dev_dbg(&dev->pdev->dev, "freeing AMTHI for other requests\n"); |
| 1167 | |
Tomas Winkler | e773efc | 2012-11-11 17:37:58 +0200 | [diff] [blame] | 1168 | list_for_each_entry_safe(cb_pos, cb_next, |
| 1169 | &dev->amthif_rd_complete_list.list, list) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1170 | |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 1171 | cl_pos = cb_pos->file_object->private_data; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1172 | |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 1173 | /* Finding the AMTHI entry. */ |
| 1174 | if (cl_pos == &dev->iamthif_cl) |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 1175 | list_del(&cb_pos->list); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1176 | } |
Tomas Winkler | 601a1ef | 2012-10-09 16:50:20 +0200 | [diff] [blame] | 1177 | mei_io_cb_free(dev->iamthif_current_cb); |
| 1178 | dev->iamthif_current_cb = NULL; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1179 | |
| 1180 | dev->iamthif_file_object->private_data = NULL; |
| 1181 | dev->iamthif_file_object = NULL; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1182 | dev->iamthif_timer = 0; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 1183 | mei_amthif_run_next_cmd(dev); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1184 | |
| 1185 | } |
| 1186 | } |
| 1187 | out: |
Tomas Winkler | 441ab50 | 2011-12-13 23:39:34 +0200 | [diff] [blame] | 1188 | schedule_delayed_work(&dev->timer_work, 2 * HZ); |
| 1189 | mutex_unlock(&dev->device_lock); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | /** |
| 1193 | * mei_interrupt_thread_handler - function called after ISR to handle the interrupt |
| 1194 | * processing. |
| 1195 | * |
| 1196 | * @irq: The irq number |
| 1197 | * @dev_id: pointer to the device structure |
| 1198 | * |
| 1199 | * returns irqreturn_t |
| 1200 | * |
| 1201 | */ |
| 1202 | irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id) |
| 1203 | { |
| 1204 | struct mei_device *dev = (struct mei_device *) dev_id; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 1205 | struct mei_cl_cb complete_list; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1206 | struct mei_cl_cb *cb_pos = NULL, *cb_next = NULL; |
| 1207 | struct mei_cl *cl; |
| 1208 | s32 slots; |
| 1209 | int rets; |
| 1210 | bool bus_message_received; |
| 1211 | |
| 1212 | |
| 1213 | dev_dbg(&dev->pdev->dev, "function called after ISR to handle the interrupt processing.\n"); |
| 1214 | /* initialize our complete list */ |
| 1215 | mutex_lock(&dev->device_lock); |
Tomas Winkler | 0288c7c | 2011-06-06 10:44:34 +0300 | [diff] [blame] | 1216 | mei_io_list_init(&complete_list); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1217 | dev->host_hw_state = mei_hcsr_read(dev); |
Tomas Winkler | 4f61a7a | 2011-07-14 20:11:25 +0300 | [diff] [blame] | 1218 | |
| 1219 | /* Ack the interrupt here |
Justin P. Mattock | 5f9092f3 | 2012-03-12 07:18:09 -0700 | [diff] [blame] | 1220 | * In case of MSI we don't go through the quick handler */ |
Tomas Winkler | 4f61a7a | 2011-07-14 20:11:25 +0300 | [diff] [blame] | 1221 | if (pci_dev_msi_enabled(dev->pdev)) |
| 1222 | mei_reg_write(dev, H_CSR, dev->host_hw_state); |
| 1223 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1224 | dev->me_hw_state = mei_mecsr_read(dev); |
| 1225 | |
| 1226 | /* check if ME wants a reset */ |
| 1227 | if ((dev->me_hw_state & ME_RDY_HRA) == 0 && |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 1228 | dev->dev_state != MEI_DEV_RESETING && |
| 1229 | dev->dev_state != MEI_DEV_INITIALIZING) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1230 | dev_dbg(&dev->pdev->dev, "FW not ready.\n"); |
| 1231 | mei_reset(dev, 1); |
| 1232 | mutex_unlock(&dev->device_lock); |
| 1233 | return IRQ_HANDLED; |
| 1234 | } |
| 1235 | |
| 1236 | /* check if we need to start the dev */ |
| 1237 | if ((dev->host_hw_state & H_RDY) == 0) { |
| 1238 | if ((dev->me_hw_state & ME_RDY_HRA) == ME_RDY_HRA) { |
| 1239 | dev_dbg(&dev->pdev->dev, "we need to start the dev.\n"); |
| 1240 | dev->host_hw_state |= (H_IE | H_IG | H_RDY); |
| 1241 | mei_hcsr_set(dev); |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 1242 | dev->dev_state = MEI_DEV_INIT_CLIENTS; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1243 | dev_dbg(&dev->pdev->dev, "link is established start sending messages.\n"); |
| 1244 | /* link is established |
| 1245 | * start sending messages. |
| 1246 | */ |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 1247 | mei_host_start_message(dev); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1248 | mutex_unlock(&dev->device_lock); |
| 1249 | return IRQ_HANDLED; |
| 1250 | } else { |
| 1251 | dev_dbg(&dev->pdev->dev, "FW not ready.\n"); |
| 1252 | mutex_unlock(&dev->device_lock); |
| 1253 | return IRQ_HANDLED; |
| 1254 | } |
| 1255 | } |
Justin P. Mattock | 5f9092f3 | 2012-03-12 07:18:09 -0700 | [diff] [blame] | 1256 | /* check slots available for reading */ |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1257 | slots = mei_count_full_read_slots(dev); |
Tomas Winkler | 5fb54fb | 2012-11-18 15:13:15 +0200 | [diff] [blame^] | 1258 | while (slots > 0) { |
| 1259 | /* we have urgent data to send so break the read */ |
| 1260 | if (dev->wr_ext_msg.hdr.length) |
| 1261 | break; |
| 1262 | dev_dbg(&dev->pdev->dev, "slots =%08x\n", slots); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1263 | dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_handler.\n"); |
| 1264 | rets = mei_irq_thread_read_handler(&complete_list, dev, &slots); |
| 1265 | if (rets) |
| 1266 | goto end; |
| 1267 | } |
| 1268 | rets = mei_irq_thread_write_handler(&complete_list, dev, &slots); |
| 1269 | end: |
| 1270 | dev_dbg(&dev->pdev->dev, "end of bottom half function.\n"); |
| 1271 | dev->host_hw_state = mei_hcsr_read(dev); |
Tomas Winkler | 726917f | 2012-06-25 23:46:28 +0300 | [diff] [blame] | 1272 | dev->mei_host_buffer_is_empty = mei_hbuf_is_empty(dev); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1273 | |
| 1274 | bus_message_received = false; |
| 1275 | if (dev->recvd_msg && waitqueue_active(&dev->wait_recvd_msg)) { |
| 1276 | dev_dbg(&dev->pdev->dev, "received waiting bus message\n"); |
| 1277 | bus_message_received = true; |
| 1278 | } |
| 1279 | mutex_unlock(&dev->device_lock); |
| 1280 | if (bus_message_received) { |
| 1281 | dev_dbg(&dev->pdev->dev, "wake up dev->wait_recvd_msg\n"); |
| 1282 | wake_up_interruptible(&dev->wait_recvd_msg); |
| 1283 | bus_message_received = false; |
| 1284 | } |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 1285 | if (list_empty(&complete_list.list)) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1286 | return IRQ_HANDLED; |
| 1287 | |
| 1288 | |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 1289 | list_for_each_entry_safe(cb_pos, cb_next, &complete_list.list, list) { |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 1290 | cl = cb_pos->cl; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 1291 | list_del(&cb_pos->list); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1292 | if (cl) { |
| 1293 | if (cl != &dev->iamthif_cl) { |
| 1294 | dev_dbg(&dev->pdev->dev, "completing call back.\n"); |
| 1295 | _mei_cmpl(cl, cb_pos); |
| 1296 | cb_pos = NULL; |
| 1297 | } else if (cl == &dev->iamthif_cl) { |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 1298 | mei_amthif_complete(dev, cb_pos); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1299 | } |
| 1300 | } |
| 1301 | } |
| 1302 | return IRQ_HANDLED; |
| 1303 | } |