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