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 | 733ba91 | 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 | |
Tomas Winkler | 4f3afe1 | 2012-05-09 16:38:59 +0300 | [diff] [blame] | 24 | #include <linux/mei.h> |
Tomas Winkler | 47a7380 | 2012-12-25 19:06:03 +0200 | [diff] [blame] | 25 | |
| 26 | #include "mei_dev.h" |
Tomas Winkler | 0edb23f | 2013-01-08 23:07:12 +0200 | [diff] [blame] | 27 | #include "hbm.h" |
Tomas Winkler | 9dc64d6 | 2013-01-08 23:07:17 +0200 | [diff] [blame] | 28 | #include "hw-me.h" |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 29 | #include "client.h" |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 30 | |
| 31 | |
| 32 | /** |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame^] | 33 | * mei_complete_handler - processes completed operation. |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 34 | * |
| 35 | * @cl: private data of the file object. |
| 36 | * @cb_pos: callback block. |
| 37 | */ |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame^] | 38 | void mei_irq_complete_handler(struct mei_cl *cl, struct mei_cl_cb *cb_pos) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 39 | { |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 40 | if (cb_pos->fop_type == MEI_FOP_WRITE) { |
Tomas Winkler | 601a1ef | 2012-10-09 16:50:20 +0200 | [diff] [blame] | 41 | mei_io_cb_free(cb_pos); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 42 | cb_pos = NULL; |
| 43 | cl->writing_state = MEI_WRITE_COMPLETE; |
| 44 | if (waitqueue_active(&cl->tx_wait)) |
| 45 | wake_up_interruptible(&cl->tx_wait); |
| 46 | |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 47 | } else if (cb_pos->fop_type == MEI_FOP_READ && |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 48 | MEI_READING == cl->reading_state) { |
| 49 | cl->reading_state = MEI_READ_COMPLETE; |
| 50 | if (waitqueue_active(&cl->rx_wait)) |
| 51 | wake_up_interruptible(&cl->rx_wait); |
| 52 | |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 57 | * _mei_irq_thread_state_ok - checks if mei header matches file private data |
| 58 | * |
| 59 | * @cl: private data of the file object |
| 60 | * @mei_hdr: header of mei client message |
| 61 | * |
| 62 | * returns !=0 if matches, 0 if no match. |
| 63 | */ |
| 64 | static int _mei_irq_thread_state_ok(struct mei_cl *cl, |
| 65 | struct mei_msg_hdr *mei_hdr) |
| 66 | { |
| 67 | return (cl->host_client_id == mei_hdr->host_addr && |
| 68 | cl->me_client_id == mei_hdr->me_addr && |
| 69 | cl->state == MEI_FILE_CONNECTED && |
| 70 | MEI_READ_COMPLETE != cl->reading_state); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * mei_irq_thread_read_client_message - bottom half read routine after ISR to |
| 75 | * handle the read mei client message data processing. |
| 76 | * |
| 77 | * @complete_list: An instance of our list structure |
| 78 | * @dev: the device structure |
| 79 | * @mei_hdr: header of mei client message |
| 80 | * |
| 81 | * returns 0 on success, <0 on failure. |
| 82 | */ |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 83 | 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] | 84 | struct mei_device *dev, |
| 85 | struct mei_msg_hdr *mei_hdr) |
| 86 | { |
| 87 | struct mei_cl *cl; |
| 88 | struct mei_cl_cb *cb_pos = NULL, *cb_next = NULL; |
Tomas Winkler | 479bc59 | 2011-06-16 00:46:03 +0300 | [diff] [blame] | 89 | unsigned char *buffer = NULL; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 90 | |
| 91 | dev_dbg(&dev->pdev->dev, "start client msg\n"); |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 92 | if (list_empty(&dev->read_list.list)) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 93 | goto quit; |
| 94 | |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 95 | 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] | 96 | cl = cb_pos->cl; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 97 | if (cl && _mei_irq_thread_state_ok(cl, mei_hdr)) { |
| 98 | cl->reading_state = MEI_READING; |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 99 | buffer = cb_pos->response_buffer.data + cb_pos->buf_idx; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 100 | |
| 101 | if (cb_pos->response_buffer.size < |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 102 | mei_hdr->length + cb_pos->buf_idx) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 103 | dev_dbg(&dev->pdev->dev, "message overflow.\n"); |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 104 | list_del(&cb_pos->list); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 105 | return -ENOMEM; |
| 106 | } |
| 107 | if (buffer) |
| 108 | mei_read_slots(dev, buffer, mei_hdr->length); |
| 109 | |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 110 | cb_pos->buf_idx += mei_hdr->length; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 111 | if (mei_hdr->msg_complete) { |
| 112 | cl->status = 0; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 113 | list_del(&cb_pos->list); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 114 | dev_dbg(&dev->pdev->dev, |
Tomas Winkler | a4136b4 | 2012-09-11 00:43:22 +0300 | [diff] [blame] | 115 | "completed read H cl = %d, ME cl = %d, length = %lu\n", |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 116 | cl->host_client_id, |
| 117 | cl->me_client_id, |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 118 | cb_pos->buf_idx); |
| 119 | |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 120 | list_add_tail(&cb_pos->list, |
| 121 | &complete_list->list); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | break; |
| 125 | } |
| 126 | |
| 127 | } |
| 128 | |
| 129 | quit: |
| 130 | dev_dbg(&dev->pdev->dev, "message read\n"); |
| 131 | if (!buffer) { |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 132 | mei_read_slots(dev, dev->rd_msg_buf, mei_hdr->length); |
Tomas Winkler | 15d4acc | 2012-12-25 19:06:00 +0200 | [diff] [blame] | 133 | dev_dbg(&dev->pdev->dev, "discarding message " MEI_HDR_FMT "\n", |
| 134 | MEI_HDR_PRM(mei_hdr)); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | /** |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 141 | * _mei_irq_thread_close - processes close related operation. |
| 142 | * |
| 143 | * @dev: the device structure. |
| 144 | * @slots: free slots. |
| 145 | * @cb_pos: callback block. |
| 146 | * @cl: private data of the file object. |
| 147 | * @cmpl_list: complete list. |
| 148 | * |
| 149 | * returns 0, OK; otherwise, error. |
| 150 | */ |
| 151 | static int _mei_irq_thread_close(struct mei_device *dev, s32 *slots, |
| 152 | struct mei_cl_cb *cb_pos, |
| 153 | struct mei_cl *cl, |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 154 | struct mei_cl_cb *cmpl_list) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 155 | { |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 156 | if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) + |
Tomas Winkler | aeba4a0 | 2012-11-11 17:38:04 +0200 | [diff] [blame] | 157 | sizeof(struct hbm_client_connect_request))) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 158 | return -EBADMSG; |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 159 | |
Tomas Winkler | aeba4a0 | 2012-11-11 17:38:04 +0200 | [diff] [blame] | 160 | *slots -= mei_data2slots(sizeof(struct hbm_client_connect_request)); |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 161 | |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 162 | if (mei_hbm_cl_disconnect_req(dev, cl)) { |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 163 | cl->status = 0; |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 164 | cb_pos->buf_idx = 0; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 165 | list_move_tail(&cb_pos->list, &cmpl_list->list); |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 166 | return -EMSGSIZE; |
| 167 | } else { |
| 168 | cl->state = MEI_FILE_DISCONNECTING; |
| 169 | cl->status = 0; |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 170 | cb_pos->buf_idx = 0; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 171 | list_move_tail(&cb_pos->list, &dev->ctrl_rd_list.list); |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 172 | cl->timer_count = MEI_CONNECT_TIMEOUT; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 178 | |
| 179 | /** |
| 180 | * _mei_hb_read - processes read related operation. |
| 181 | * |
| 182 | * @dev: the device structure. |
| 183 | * @slots: free slots. |
| 184 | * @cb_pos: callback block. |
| 185 | * @cl: private data of the file object. |
| 186 | * @cmpl_list: complete list. |
| 187 | * |
| 188 | * returns 0, OK; otherwise, error. |
| 189 | */ |
| 190 | static int _mei_irq_thread_read(struct mei_device *dev, s32 *slots, |
| 191 | struct mei_cl_cb *cb_pos, |
| 192 | struct mei_cl *cl, |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 193 | struct mei_cl_cb *cmpl_list) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 194 | { |
Tomas Winkler | 1e69d64 | 2012-05-29 16:39:12 +0300 | [diff] [blame] | 195 | if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) + |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 196 | sizeof(struct hbm_flow_control))) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 197 | /* return the cancel routine */ |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 198 | list_del(&cb_pos->list); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 199 | return -EBADMSG; |
| 200 | } |
| 201 | |
Tomas Winkler | 7bdf72d | 2012-07-04 19:24:52 +0300 | [diff] [blame] | 202 | *slots -= mei_data2slots(sizeof(struct hbm_flow_control)); |
| 203 | |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 204 | if (mei_hbm_cl_flow_control_req(dev, cl)) { |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 205 | cl->status = -ENODEV; |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 206 | cb_pos->buf_idx = 0; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 207 | list_move_tail(&cb_pos->list, &cmpl_list->list); |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 208 | return -ENODEV; |
| 209 | } |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 210 | list_move_tail(&cb_pos->list, &dev->read_list.list); |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 211 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | |
| 216 | /** |
| 217 | * _mei_irq_thread_ioctl - processes ioctl related operation. |
| 218 | * |
| 219 | * @dev: the device structure. |
| 220 | * @slots: free slots. |
| 221 | * @cb_pos: callback block. |
| 222 | * @cl: private data of the file object. |
| 223 | * @cmpl_list: complete list. |
| 224 | * |
| 225 | * returns 0, OK; otherwise, error. |
| 226 | */ |
| 227 | static int _mei_irq_thread_ioctl(struct mei_device *dev, s32 *slots, |
| 228 | struct mei_cl_cb *cb_pos, |
| 229 | struct mei_cl *cl, |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 230 | struct mei_cl_cb *cmpl_list) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 231 | { |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 232 | if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) + |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 233 | sizeof(struct hbm_client_connect_request))) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 234 | /* return the cancel routine */ |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 235 | list_del(&cb_pos->list); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 236 | return -EBADMSG; |
| 237 | } |
| 238 | |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 239 | cl->state = MEI_FILE_CONNECTING; |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 240 | *slots -= mei_data2slots(sizeof(struct hbm_client_connect_request)); |
| 241 | if (mei_hbm_cl_connect_req(dev, cl)) { |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 242 | cl->status = -ENODEV; |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 243 | cb_pos->buf_idx = 0; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 244 | list_del(&cb_pos->list); |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 245 | return -ENODEV; |
| 246 | } else { |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 247 | list_move_tail(&cb_pos->list, &dev->ctrl_rd_list.list); |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 248 | cl->timer_count = MEI_CONNECT_TIMEOUT; |
| 249 | } |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | /** |
Tomas Winkler | ea3b5fb | 2012-11-18 15:13:16 +0200 | [diff] [blame] | 254 | * mei_irq_thread_write_complete - write messages to device. |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 255 | * |
| 256 | * @dev: the device structure. |
| 257 | * @slots: free slots. |
Tomas Winkler | ea3b5fb | 2012-11-18 15:13:16 +0200 | [diff] [blame] | 258 | * @cb: callback block. |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 259 | * @cmpl_list: complete list. |
| 260 | * |
| 261 | * returns 0, OK; otherwise, error. |
| 262 | */ |
Tomas Winkler | ea3b5fb | 2012-11-18 15:13:16 +0200 | [diff] [blame] | 263 | static int mei_irq_thread_write_complete(struct mei_device *dev, s32 *slots, |
| 264 | struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 265 | { |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 266 | struct mei_msg_hdr mei_hdr; |
Tomas Winkler | ea3b5fb | 2012-11-18 15:13:16 +0200 | [diff] [blame] | 267 | struct mei_cl *cl = cb->cl; |
| 268 | size_t len = cb->request_buffer.size - cb->buf_idx; |
| 269 | size_t msg_slots = mei_data2slots(len); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 270 | |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 271 | mei_hdr.host_addr = cl->host_client_id; |
| 272 | mei_hdr.me_addr = cl->me_client_id; |
| 273 | mei_hdr.reserved = 0; |
Tomas Winkler | ea3b5fb | 2012-11-18 15:13:16 +0200 | [diff] [blame] | 274 | |
| 275 | if (*slots >= msg_slots) { |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 276 | mei_hdr.length = len; |
| 277 | mei_hdr.msg_complete = 1; |
Tomas Winkler | ea3b5fb | 2012-11-18 15:13:16 +0200 | [diff] [blame] | 278 | /* Split the message only if we can write the whole host buffer */ |
Tomas Winkler | 24aadc8 | 2012-06-25 23:46:27 +0300 | [diff] [blame] | 279 | } else if (*slots == dev->hbuf_depth) { |
Tomas Winkler | ea3b5fb | 2012-11-18 15:13:16 +0200 | [diff] [blame] | 280 | msg_slots = *slots; |
| 281 | len = (*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr); |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 282 | mei_hdr.length = len; |
| 283 | mei_hdr.msg_complete = 0; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 284 | } else { |
Tomas Winkler | ea3b5fb | 2012-11-18 15:13:16 +0200 | [diff] [blame] | 285 | /* wait for next time the host buffer is empty */ |
| 286 | return 0; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 287 | } |
| 288 | |
Tomas Winkler | ea3b5fb | 2012-11-18 15:13:16 +0200 | [diff] [blame] | 289 | dev_dbg(&dev->pdev->dev, "buf: size = %d idx = %lu\n", |
| 290 | cb->request_buffer.size, cb->buf_idx); |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 291 | dev_dbg(&dev->pdev->dev, MEI_HDR_FMT, MEI_HDR_PRM(&mei_hdr)); |
Tomas Winkler | ea3b5fb | 2012-11-18 15:13:16 +0200 | [diff] [blame] | 292 | |
| 293 | *slots -= msg_slots; |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 294 | if (mei_write_message(dev, &mei_hdr, |
Tomas Winkler | 438763f | 2012-12-25 19:05:59 +0200 | [diff] [blame] | 295 | cb->request_buffer.data + cb->buf_idx)) { |
Tomas Winkler | ea3b5fb | 2012-11-18 15:13:16 +0200 | [diff] [blame] | 296 | cl->status = -ENODEV; |
| 297 | list_move_tail(&cb->list, &cmpl_list->list); |
| 298 | return -ENODEV; |
| 299 | } |
| 300 | |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 301 | if (mei_cl_flow_ctrl_reduce(cl)) |
Tomas Winkler | ea3b5fb | 2012-11-18 15:13:16 +0200 | [diff] [blame] | 302 | return -ENODEV; |
| 303 | |
| 304 | cl->status = 0; |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 305 | cb->buf_idx += mei_hdr.length; |
| 306 | if (mei_hdr.msg_complete) |
Tomas Winkler | ea3b5fb | 2012-11-18 15:13:16 +0200 | [diff] [blame] | 307 | list_move_tail(&cb->list, &dev->write_waiting_list.list); |
| 308 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | /** |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 313 | * mei_irq_thread_read_handler - bottom half read routine after ISR to |
| 314 | * handle the read processing. |
| 315 | * |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 316 | * @dev: the device structure |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame^] | 317 | * @cmpl_list: An instance of our list structure |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 318 | * @slots: slots to read. |
| 319 | * |
| 320 | * returns 0 on success, <0 on failure. |
| 321 | */ |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame^] | 322 | int mei_irq_read_handler(struct mei_device *dev, |
| 323 | struct mei_cl_cb *cmpl_list, s32 *slots) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 324 | { |
| 325 | struct mei_msg_hdr *mei_hdr; |
| 326 | struct mei_cl *cl_pos = NULL; |
| 327 | struct mei_cl *cl_next = NULL; |
| 328 | int ret = 0; |
| 329 | |
| 330 | if (!dev->rd_msg_hdr) { |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 331 | dev->rd_msg_hdr = mei_read_hdr(dev); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 332 | dev_dbg(&dev->pdev->dev, "slots =%08x.\n", *slots); |
| 333 | (*slots)--; |
| 334 | dev_dbg(&dev->pdev->dev, "slots =%08x.\n", *slots); |
| 335 | } |
| 336 | mei_hdr = (struct mei_msg_hdr *) &dev->rd_msg_hdr; |
Tomas Winkler | 15d4acc | 2012-12-25 19:06:00 +0200 | [diff] [blame] | 337 | dev_dbg(&dev->pdev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr)); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 338 | |
| 339 | if (mei_hdr->reserved || !dev->rd_msg_hdr) { |
| 340 | dev_dbg(&dev->pdev->dev, "corrupted message header.\n"); |
| 341 | ret = -EBADMSG; |
| 342 | goto end; |
| 343 | } |
| 344 | |
| 345 | if (mei_hdr->host_addr || mei_hdr->me_addr) { |
| 346 | list_for_each_entry_safe(cl_pos, cl_next, |
| 347 | &dev->file_list, link) { |
| 348 | dev_dbg(&dev->pdev->dev, |
| 349 | "list_for_each_entry_safe read host" |
| 350 | " client = %d, ME client = %d\n", |
| 351 | cl_pos->host_client_id, |
| 352 | cl_pos->me_client_id); |
| 353 | if (cl_pos->host_client_id == mei_hdr->host_addr && |
| 354 | cl_pos->me_client_id == mei_hdr->me_addr) |
| 355 | break; |
| 356 | } |
| 357 | |
| 358 | if (&cl_pos->link == &dev->file_list) { |
| 359 | dev_dbg(&dev->pdev->dev, "corrupted message header\n"); |
| 360 | ret = -EBADMSG; |
| 361 | goto end; |
| 362 | } |
| 363 | } |
| 364 | if (((*slots) * sizeof(u32)) < mei_hdr->length) { |
| 365 | dev_dbg(&dev->pdev->dev, |
| 366 | "we can't read the message slots =%08x.\n", |
| 367 | *slots); |
| 368 | /* we can't read the message */ |
| 369 | ret = -ERANGE; |
| 370 | goto end; |
| 371 | } |
| 372 | |
| 373 | /* decide where to read the message too */ |
| 374 | if (!mei_hdr->host_addr) { |
| 375 | dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_bus_message.\n"); |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 376 | mei_hbm_dispatch(dev, mei_hdr); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 377 | dev_dbg(&dev->pdev->dev, "end mei_irq_thread_read_bus_message.\n"); |
| 378 | } else if (mei_hdr->host_addr == dev->iamthif_cl.host_client_id && |
| 379 | (MEI_FILE_CONNECTED == dev->iamthif_cl.state) && |
| 380 | (dev->iamthif_state == MEI_IAMTHIF_READING)) { |
| 381 | dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_iamthif_message.\n"); |
Tomas Winkler | 15d4acc | 2012-12-25 19:06:00 +0200 | [diff] [blame] | 382 | |
| 383 | dev_dbg(&dev->pdev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr)); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 384 | |
| 385 | ret = mei_amthif_irq_read_message(cmpl_list, dev, mei_hdr); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 386 | if (ret) |
| 387 | goto end; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 388 | } else { |
| 389 | dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_client_message.\n"); |
| 390 | ret = mei_irq_thread_read_client_message(cmpl_list, |
| 391 | dev, mei_hdr); |
| 392 | if (ret) |
| 393 | goto end; |
| 394 | |
| 395 | } |
| 396 | |
| 397 | /* reset the number of slots and header */ |
| 398 | *slots = mei_count_full_read_slots(dev); |
| 399 | dev->rd_msg_hdr = 0; |
| 400 | |
| 401 | if (*slots == -EOVERFLOW) { |
| 402 | /* overflow - reset */ |
| 403 | dev_dbg(&dev->pdev->dev, "resetting due to slots overflow.\n"); |
| 404 | /* set the event since message has been read */ |
| 405 | ret = -ERANGE; |
| 406 | goto end; |
| 407 | } |
| 408 | end: |
| 409 | return ret; |
| 410 | } |
| 411 | |
| 412 | |
| 413 | /** |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame^] | 414 | * mei_irq_write_handler - dispatch write requests |
| 415 | * after irq received |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 416 | * |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 417 | * @dev: the device structure |
Tomas Winkler | 9a84d61 | 2012-11-18 15:13:18 +0200 | [diff] [blame] | 418 | * @cmpl_list: An instance of our list structure |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 419 | * |
| 420 | * returns 0 on success, <0 on failure. |
| 421 | */ |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame^] | 422 | int mei_irq_write_handler(struct mei_device *dev, |
Tomas Winkler | 9a84d61 | 2012-11-18 15:13:18 +0200 | [diff] [blame] | 423 | struct mei_cl_cb *cmpl_list) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 424 | { |
| 425 | |
| 426 | struct mei_cl *cl; |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 427 | struct mei_cl_cb *pos = NULL, *next = NULL; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 428 | struct mei_cl_cb *list; |
Tomas Winkler | 9a84d61 | 2012-11-18 15:13:18 +0200 | [diff] [blame] | 429 | s32 slots; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 430 | int ret; |
| 431 | |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 432 | if (!mei_hbuf_is_ready(dev)) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 433 | dev_dbg(&dev->pdev->dev, "host buffer is not empty.\n"); |
| 434 | return 0; |
| 435 | } |
Tomas Winkler | 9a84d61 | 2012-11-18 15:13:18 +0200 | [diff] [blame] | 436 | slots = mei_hbuf_empty_slots(dev); |
| 437 | if (slots <= 0) |
Tomas Winkler | 7d5e0e5 | 2012-06-19 09:13:36 +0300 | [diff] [blame] | 438 | return -EMSGSIZE; |
| 439 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 440 | /* complete all waiting for write CB */ |
| 441 | dev_dbg(&dev->pdev->dev, "complete all waiting for write cb.\n"); |
| 442 | |
| 443 | list = &dev->write_waiting_list; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 444 | list_for_each_entry_safe(pos, next, &list->list, list) { |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 445 | cl = pos->cl; |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 446 | if (cl == NULL) |
| 447 | continue; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 448 | |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 449 | cl->status = 0; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 450 | list_del(&pos->list); |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 451 | if (MEI_WRITING == cl->writing_state && |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 452 | pos->fop_type == MEI_FOP_WRITE && |
| 453 | cl != &dev->iamthif_cl) { |
Tomas Winkler | 483136e | 2012-07-04 19:24:54 +0300 | [diff] [blame] | 454 | dev_dbg(&dev->pdev->dev, "MEI WRITE COMPLETE\n"); |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 455 | cl->writing_state = MEI_WRITE_COMPLETE; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 456 | list_add_tail(&pos->list, &cmpl_list->list); |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 457 | } |
| 458 | if (cl == &dev->iamthif_cl) { |
| 459 | dev_dbg(&dev->pdev->dev, "check iamthif flow control.\n"); |
| 460 | if (dev->iamthif_flow_control_pending) { |
Tomas Winkler | 9a84d61 | 2012-11-18 15:13:18 +0200 | [diff] [blame] | 461 | ret = mei_amthif_irq_read(dev, &slots); |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 462 | if (ret) |
| 463 | return ret; |
| 464 | } |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 465 | } |
| 466 | } |
| 467 | |
Tomas Winkler | c216fde | 2012-08-16 19:39:43 +0300 | [diff] [blame] | 468 | if (dev->wd_state == MEI_WD_STOPPING) { |
| 469 | dev->wd_state = MEI_WD_IDLE; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 470 | wake_up_interruptible(&dev->wait_stop_wd); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 471 | } |
| 472 | |
Tomas Winkler | 5fb54fb | 2012-11-18 15:13:15 +0200 | [diff] [blame] | 473 | if (dev->wr_ext_msg.hdr.length) { |
| 474 | mei_write_message(dev, &dev->wr_ext_msg.hdr, |
Tomas Winkler | 438763f | 2012-12-25 19:05:59 +0200 | [diff] [blame] | 475 | dev->wr_ext_msg.data); |
Tomas Winkler | 9a84d61 | 2012-11-18 15:13:18 +0200 | [diff] [blame] | 476 | slots -= mei_data2slots(dev->wr_ext_msg.hdr.length); |
Tomas Winkler | 5fb54fb | 2012-11-18 15:13:15 +0200 | [diff] [blame] | 477 | dev->wr_ext_msg.hdr.length = 0; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 478 | } |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 479 | if (dev->dev_state == MEI_DEV_ENABLED) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 480 | if (dev->wd_pending && |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 481 | mei_cl_flow_ctrl_creds(&dev->wd_cl) > 0) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 482 | if (mei_wd_send(dev)) |
| 483 | dev_dbg(&dev->pdev->dev, "wd send failed.\n"); |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 484 | else if (mei_cl_flow_ctrl_reduce(&dev->wd_cl)) |
Tomas Winkler | 483136e | 2012-07-04 19:24:54 +0300 | [diff] [blame] | 485 | return -ENODEV; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 486 | |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 487 | dev->wd_pending = false; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 488 | |
Tomas Winkler | c216fde | 2012-08-16 19:39:43 +0300 | [diff] [blame] | 489 | if (dev->wd_state == MEI_WD_RUNNING) |
Tomas Winkler | 9a84d61 | 2012-11-18 15:13:18 +0200 | [diff] [blame] | 490 | slots -= mei_data2slots(MEI_WD_START_MSG_SIZE); |
Tomas Winkler | d242a0a | 2012-07-04 19:24:50 +0300 | [diff] [blame] | 491 | else |
Tomas Winkler | 9a84d61 | 2012-11-18 15:13:18 +0200 | [diff] [blame] | 492 | slots -= mei_data2slots(MEI_WD_STOP_MSG_SIZE); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 493 | } |
| 494 | } |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 495 | |
| 496 | /* complete control write list CB */ |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 497 | dev_dbg(&dev->pdev->dev, "complete control write list cb.\n"); |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 498 | 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] | 499 | cl = pos->cl; |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 500 | if (!cl) { |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 501 | list_del(&pos->list); |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 502 | return -ENODEV; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 503 | } |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 504 | switch (pos->fop_type) { |
| 505 | case MEI_FOP_CLOSE: |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 506 | /* send disconnect message */ |
Tomas Winkler | 9a84d61 | 2012-11-18 15:13:18 +0200 | [diff] [blame] | 507 | ret = _mei_irq_thread_close(dev, &slots, pos, |
| 508 | cl, cmpl_list); |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 509 | if (ret) |
| 510 | return ret; |
| 511 | |
| 512 | break; |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 513 | case MEI_FOP_READ: |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 514 | /* send flow control message */ |
Tomas Winkler | 9a84d61 | 2012-11-18 15:13:18 +0200 | [diff] [blame] | 515 | ret = _mei_irq_thread_read(dev, &slots, pos, |
| 516 | cl, cmpl_list); |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 517 | if (ret) |
| 518 | return ret; |
| 519 | |
| 520 | break; |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 521 | case MEI_FOP_IOCTL: |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 522 | /* connect message */ |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 523 | if (mei_cl_is_other_connecting(cl)) |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 524 | continue; |
Tomas Winkler | 9a84d61 | 2012-11-18 15:13:18 +0200 | [diff] [blame] | 525 | ret = _mei_irq_thread_ioctl(dev, &slots, pos, |
| 526 | cl, cmpl_list); |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 527 | if (ret) |
| 528 | return ret; |
| 529 | |
| 530 | break; |
| 531 | |
| 532 | default: |
| 533 | BUG(); |
| 534 | } |
| 535 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 536 | } |
| 537 | /* complete write list CB */ |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 538 | dev_dbg(&dev->pdev->dev, "complete write list cb.\n"); |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 539 | list_for_each_entry_safe(pos, next, &dev->write_list.list, list) { |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 540 | cl = pos->cl; |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 541 | if (cl == NULL) |
| 542 | continue; |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 543 | if (mei_cl_flow_ctrl_creds(cl) <= 0) { |
Tomas Winkler | be9d87a | 2012-11-18 15:13:19 +0200 | [diff] [blame] | 544 | dev_dbg(&dev->pdev->dev, |
| 545 | "No flow control credentials for client %d, not sending.\n", |
| 546 | cl->host_client_id); |
| 547 | continue; |
| 548 | } |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 549 | |
Tomas Winkler | be9d87a | 2012-11-18 15:13:19 +0200 | [diff] [blame] | 550 | if (cl == &dev->iamthif_cl) |
Tomas Winkler | 9a84d61 | 2012-11-18 15:13:18 +0200 | [diff] [blame] | 551 | ret = mei_amthif_irq_write_complete(dev, &slots, |
Tomas Winkler | 24c656e | 2012-11-18 15:13:17 +0200 | [diff] [blame] | 552 | pos, cmpl_list); |
Tomas Winkler | be9d87a | 2012-11-18 15:13:19 +0200 | [diff] [blame] | 553 | else |
| 554 | ret = mei_irq_thread_write_complete(dev, &slots, pos, |
| 555 | cmpl_list); |
| 556 | if (ret) |
| 557 | return ret; |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 558 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 559 | } |
| 560 | return 0; |
| 561 | } |
| 562 | |
| 563 | |
| 564 | |
| 565 | /** |
| 566 | * mei_timer - timer function. |
| 567 | * |
| 568 | * @work: pointer to the work_struct structure |
| 569 | * |
| 570 | * NOTE: This function is called by timer interrupt work |
| 571 | */ |
Oren Weil | a61c653 | 2011-09-07 09:03:13 +0300 | [diff] [blame] | 572 | void mei_timer(struct work_struct *work) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 573 | { |
| 574 | unsigned long timeout; |
| 575 | struct mei_cl *cl_pos = NULL; |
| 576 | struct mei_cl *cl_next = NULL; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 577 | struct mei_cl_cb *cb_pos = NULL; |
| 578 | struct mei_cl_cb *cb_next = NULL; |
| 579 | |
| 580 | struct mei_device *dev = container_of(work, |
Oren Weil | a61c653 | 2011-09-07 09:03:13 +0300 | [diff] [blame] | 581 | struct mei_device, timer_work.work); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 582 | |
| 583 | |
| 584 | mutex_lock(&dev->device_lock); |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 585 | if (dev->dev_state != MEI_DEV_ENABLED) { |
| 586 | if (dev->dev_state == MEI_DEV_INIT_CLIENTS) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 587 | if (dev->init_clients_timer) { |
| 588 | if (--dev->init_clients_timer == 0) { |
| 589 | dev_dbg(&dev->pdev->dev, "IMEI reset due to init clients timeout ,init clients state = %d.\n", |
| 590 | dev->init_clients_state); |
| 591 | mei_reset(dev, 1); |
| 592 | } |
| 593 | } |
| 594 | } |
| 595 | goto out; |
| 596 | } |
| 597 | /*** connect/disconnect timeouts ***/ |
| 598 | list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) { |
| 599 | if (cl_pos->timer_count) { |
| 600 | if (--cl_pos->timer_count == 0) { |
| 601 | dev_dbg(&dev->pdev->dev, "HECI reset due to connect/disconnect timeout.\n"); |
| 602 | mei_reset(dev, 1); |
| 603 | goto out; |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 608 | if (dev->iamthif_stall_timer) { |
| 609 | if (--dev->iamthif_stall_timer == 0) { |
Masanari Iida | 32de21f | 2012-01-25 23:14:56 +0900 | [diff] [blame] | 610 | dev_dbg(&dev->pdev->dev, "resetting because of hang to amthi.\n"); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 611 | mei_reset(dev, 1); |
| 612 | dev->iamthif_msg_buf_size = 0; |
| 613 | dev->iamthif_msg_buf_index = 0; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 614 | dev->iamthif_canceled = false; |
| 615 | dev->iamthif_ioctl = true; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 616 | dev->iamthif_state = MEI_IAMTHIF_IDLE; |
| 617 | dev->iamthif_timer = 0; |
| 618 | |
Tomas Winkler | 601a1ef | 2012-10-09 16:50:20 +0200 | [diff] [blame] | 619 | mei_io_cb_free(dev->iamthif_current_cb); |
| 620 | dev->iamthif_current_cb = NULL; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 621 | |
| 622 | dev->iamthif_file_object = NULL; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 623 | mei_amthif_run_next_cmd(dev); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 624 | } |
| 625 | } |
| 626 | |
| 627 | if (dev->iamthif_timer) { |
| 628 | |
| 629 | timeout = dev->iamthif_timer + |
Tomas Winkler | 3870c32 | 2012-11-01 21:17:14 +0200 | [diff] [blame] | 630 | mei_secs_to_jiffies(MEI_IAMTHIF_READ_TIMER); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 631 | |
| 632 | dev_dbg(&dev->pdev->dev, "dev->iamthif_timer = %ld\n", |
| 633 | dev->iamthif_timer); |
| 634 | dev_dbg(&dev->pdev->dev, "timeout = %ld\n", timeout); |
| 635 | dev_dbg(&dev->pdev->dev, "jiffies = %ld\n", jiffies); |
| 636 | if (time_after(jiffies, timeout)) { |
| 637 | /* |
| 638 | * User didn't read the AMTHI data on time (15sec) |
| 639 | * freeing AMTHI for other requests |
| 640 | */ |
| 641 | |
| 642 | dev_dbg(&dev->pdev->dev, "freeing AMTHI for other requests\n"); |
| 643 | |
Tomas Winkler | e773efc | 2012-11-11 17:37:58 +0200 | [diff] [blame] | 644 | list_for_each_entry_safe(cb_pos, cb_next, |
| 645 | &dev->amthif_rd_complete_list.list, list) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 646 | |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 647 | cl_pos = cb_pos->file_object->private_data; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 648 | |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 649 | /* Finding the AMTHI entry. */ |
| 650 | if (cl_pos == &dev->iamthif_cl) |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 651 | list_del(&cb_pos->list); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 652 | } |
Tomas Winkler | 601a1ef | 2012-10-09 16:50:20 +0200 | [diff] [blame] | 653 | mei_io_cb_free(dev->iamthif_current_cb); |
| 654 | dev->iamthif_current_cb = NULL; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 655 | |
| 656 | dev->iamthif_file_object->private_data = NULL; |
| 657 | dev->iamthif_file_object = NULL; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 658 | dev->iamthif_timer = 0; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 659 | mei_amthif_run_next_cmd(dev); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 660 | |
| 661 | } |
| 662 | } |
| 663 | out: |
Tomas Winkler | 441ab50 | 2011-12-13 23:39:34 +0200 | [diff] [blame] | 664 | schedule_delayed_work(&dev->timer_work, 2 * HZ); |
| 665 | mutex_unlock(&dev->device_lock); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 666 | } |
| 667 | |