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