Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Intel Management Engine Interface (Intel MEI) Linux driver |
| 4 | * Copyright (c) 2003-2012, Intel Corporation. |
| 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 | #include <linux/kernel.h> |
| 18 | #include <linux/fs.h> |
| 19 | #include <linux/errno.h> |
| 20 | #include <linux/types.h> |
| 21 | #include <linux/fcntl.h> |
| 22 | #include <linux/aio.h> |
| 23 | #include <linux/pci.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/ioctl.h> |
| 26 | #include <linux/cdev.h> |
| 27 | #include <linux/list.h> |
| 28 | #include <linux/delay.h> |
| 29 | #include <linux/sched.h> |
| 30 | #include <linux/uuid.h> |
| 31 | #include <linux/jiffies.h> |
| 32 | #include <linux/uaccess.h> |
| 33 | |
Tomas Winkler | 47a7380 | 2012-12-25 19:06:03 +0200 | [diff] [blame] | 34 | #include <linux/mei.h> |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 35 | |
| 36 | #include "mei_dev.h" |
Tomas Winkler | 0edb23f | 2013-01-08 23:07:12 +0200 | [diff] [blame] | 37 | #include "hbm.h" |
Tomas Winkler | 9dc64d6 | 2013-01-08 23:07:17 +0200 | [diff] [blame] | 38 | #include "hw-me.h" |
Tomas Winkler | 90e0b5f1 | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 39 | #include "client.h" |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 40 | |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 41 | const uuid_le mei_amthif_guid = UUID_LE(0x12f80028, 0xb4b7, 0x4b2d, |
| 42 | 0xac, 0xa8, 0x46, 0xe0, |
| 43 | 0xff, 0x65, 0x81, 0x4c); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * mei_amthif_reset_params - initializes mei device iamthif |
| 47 | * |
| 48 | * @dev: the device structure |
| 49 | */ |
| 50 | void mei_amthif_reset_params(struct mei_device *dev) |
| 51 | { |
| 52 | /* reset iamthif parameters. */ |
| 53 | dev->iamthif_current_cb = NULL; |
| 54 | dev->iamthif_msg_buf_size = 0; |
| 55 | dev->iamthif_msg_buf_index = 0; |
| 56 | dev->iamthif_canceled = false; |
| 57 | dev->iamthif_ioctl = false; |
| 58 | dev->iamthif_state = MEI_IAMTHIF_IDLE; |
| 59 | dev->iamthif_timer = 0; |
| 60 | } |
| 61 | |
| 62 | /** |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 63 | * mei_amthif_host_init - mei initialization amthif client. |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 64 | * |
| 65 | * @dev: the device structure |
| 66 | * |
| 67 | */ |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 68 | int mei_amthif_host_init(struct mei_device *dev) |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 69 | { |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 70 | struct mei_cl *cl = &dev->iamthif_cl; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 71 | unsigned char *msg_buf; |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 72 | int ret, i; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 73 | |
Tomas Winkler | 6222f7b | 2013-01-08 23:07:23 +0200 | [diff] [blame] | 74 | dev->iamthif_state = MEI_IAMTHIF_IDLE; |
| 75 | |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 76 | mei_cl_init(cl, dev); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 77 | |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 78 | i = mei_me_cl_by_uuid(dev, &mei_amthif_guid); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 79 | if (i < 0) { |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 80 | dev_info(&dev->pdev->dev, "amthif: failed to find the client\n"); |
| 81 | return -ENOENT; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 82 | } |
| 83 | |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 84 | cl->me_client_id = dev->me_clients[i].client_id; |
| 85 | |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 86 | /* Assign iamthif_mtu to the value received from ME */ |
| 87 | |
| 88 | dev->iamthif_mtu = dev->me_clients[i].props.max_msg_length; |
| 89 | dev_dbg(&dev->pdev->dev, "IAMTHIF_MTU = %d\n", |
| 90 | dev->me_clients[i].props.max_msg_length); |
| 91 | |
| 92 | kfree(dev->iamthif_msg_buf); |
| 93 | dev->iamthif_msg_buf = NULL; |
| 94 | |
| 95 | /* allocate storage for ME message buffer */ |
| 96 | msg_buf = kcalloc(dev->iamthif_mtu, |
| 97 | sizeof(unsigned char), GFP_KERNEL); |
| 98 | if (!msg_buf) { |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 99 | dev_err(&dev->pdev->dev, "amthif: memory allocation for ME message buffer failed.\n"); |
| 100 | return -ENOMEM; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | dev->iamthif_msg_buf = msg_buf; |
| 104 | |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 105 | ret = mei_cl_link(cl, MEI_IAMTHIF_HOST_CLIENT_ID); |
| 106 | |
| 107 | if (ret < 0) { |
| 108 | dev_err(&dev->pdev->dev, "amthif: failed link client\n"); |
| 109 | return -ENOENT; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 110 | } |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 111 | |
| 112 | cl->state = MEI_FILE_CONNECTING; |
| 113 | |
| 114 | if (mei_hbm_cl_connect_req(dev, cl)) { |
| 115 | dev_dbg(&dev->pdev->dev, "amthif: Failed to connect to ME client\n"); |
| 116 | cl->state = MEI_FILE_DISCONNECTED; |
| 117 | cl->host_client_id = 0; |
| 118 | } else { |
| 119 | cl->timer_count = MEI_CONNECT_TIMEOUT; |
| 120 | } |
| 121 | return 0; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | /** |
| 125 | * mei_amthif_find_read_list_entry - finds a amthilist entry for current file |
| 126 | * |
| 127 | * @dev: the device structure |
| 128 | * @file: pointer to file object |
| 129 | * |
| 130 | * returns returned a list entry on success, NULL on failure. |
| 131 | */ |
| 132 | struct mei_cl_cb *mei_amthif_find_read_list_entry(struct mei_device *dev, |
| 133 | struct file *file) |
| 134 | { |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 135 | struct mei_cl_cb *pos = NULL; |
| 136 | struct mei_cl_cb *next = NULL; |
| 137 | |
| 138 | list_for_each_entry_safe(pos, next, |
Tomas Winkler | e773efc | 2012-11-11 17:37:58 +0200 | [diff] [blame] | 139 | &dev->amthif_rd_complete_list.list, list) { |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 140 | if (pos->cl && pos->cl == &dev->iamthif_cl && |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 141 | pos->file_object == file) |
| 142 | return pos; |
| 143 | } |
| 144 | return NULL; |
| 145 | } |
| 146 | |
| 147 | |
| 148 | /** |
| 149 | * mei_amthif_read - read data from AMTHIF client |
| 150 | * |
| 151 | * @dev: the device structure |
| 152 | * @if_num: minor number |
| 153 | * @file: pointer to file object |
| 154 | * @*ubuf: pointer to user data in user space |
| 155 | * @length: data length to read |
| 156 | * @offset: data read offset |
| 157 | * |
| 158 | * Locking: called under "dev->device_lock" lock |
| 159 | * |
| 160 | * returns |
| 161 | * returned data length on success, |
| 162 | * zero if no data to read, |
| 163 | * negative on failure. |
| 164 | */ |
| 165 | int mei_amthif_read(struct mei_device *dev, struct file *file, |
| 166 | char __user *ubuf, size_t length, loff_t *offset) |
| 167 | { |
| 168 | int rets; |
| 169 | int wait_ret; |
| 170 | struct mei_cl_cb *cb = NULL; |
| 171 | struct mei_cl *cl = file->private_data; |
| 172 | unsigned long timeout; |
| 173 | int i; |
| 174 | |
| 175 | /* Only Posible if we are in timeout */ |
| 176 | if (!cl || cl != &dev->iamthif_cl) { |
| 177 | dev_dbg(&dev->pdev->dev, "bad file ext.\n"); |
| 178 | return -ETIMEDOUT; |
| 179 | } |
| 180 | |
| 181 | i = mei_me_cl_by_id(dev, dev->iamthif_cl.me_client_id); |
| 182 | |
| 183 | if (i < 0) { |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 184 | dev_dbg(&dev->pdev->dev, "amthif client not found.\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 185 | return -ENODEV; |
| 186 | } |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 187 | dev_dbg(&dev->pdev->dev, "checking amthif data\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 188 | cb = mei_amthif_find_read_list_entry(dev, file); |
| 189 | |
| 190 | /* Check for if we can block or not*/ |
| 191 | if (cb == NULL && file->f_flags & O_NONBLOCK) |
| 192 | return -EAGAIN; |
| 193 | |
| 194 | |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 195 | dev_dbg(&dev->pdev->dev, "waiting for amthif data\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 196 | while (cb == NULL) { |
| 197 | /* unlock the Mutex */ |
| 198 | mutex_unlock(&dev->device_lock); |
| 199 | |
| 200 | wait_ret = wait_event_interruptible(dev->iamthif_cl.wait, |
| 201 | (cb = mei_amthif_find_read_list_entry(dev, file))); |
| 202 | |
Alexey Khoroshilov | e6028db | 2012-12-22 01:44:16 +0400 | [diff] [blame] | 203 | /* Locking again the Mutex */ |
| 204 | mutex_lock(&dev->device_lock); |
| 205 | |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 206 | if (wait_ret) |
| 207 | return -ERESTARTSYS; |
| 208 | |
| 209 | dev_dbg(&dev->pdev->dev, "woke up from sleep\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 213 | dev_dbg(&dev->pdev->dev, "Got amthif data\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 214 | dev->iamthif_timer = 0; |
| 215 | |
| 216 | if (cb) { |
| 217 | timeout = cb->read_time + |
| 218 | mei_secs_to_jiffies(MEI_IAMTHIF_READ_TIMER); |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 219 | dev_dbg(&dev->pdev->dev, "amthif timeout = %lud\n", |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 220 | timeout); |
| 221 | |
| 222 | if (time_after(jiffies, timeout)) { |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 223 | dev_dbg(&dev->pdev->dev, "amthif Time out\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 224 | /* 15 sec for the message has expired */ |
| 225 | list_del(&cb->list); |
| 226 | rets = -ETIMEDOUT; |
| 227 | goto free; |
| 228 | } |
| 229 | } |
| 230 | /* if the whole message will fit remove it from the list */ |
| 231 | if (cb->buf_idx >= *offset && length >= (cb->buf_idx - *offset)) |
| 232 | list_del(&cb->list); |
| 233 | else if (cb->buf_idx > 0 && cb->buf_idx <= *offset) { |
| 234 | /* end of the message has been reached */ |
| 235 | list_del(&cb->list); |
| 236 | rets = 0; |
| 237 | goto free; |
| 238 | } |
| 239 | /* else means that not full buffer will be read and do not |
| 240 | * remove message from deletion list |
| 241 | */ |
| 242 | |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 243 | dev_dbg(&dev->pdev->dev, "amthif cb->response_buffer size - %d\n", |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 244 | cb->response_buffer.size); |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 245 | dev_dbg(&dev->pdev->dev, "amthif cb->buf_idx - %lu\n", cb->buf_idx); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 246 | |
| 247 | /* length is being turncated to PAGE_SIZE, however, |
| 248 | * the buf_idx may point beyond */ |
| 249 | length = min_t(size_t, length, (cb->buf_idx - *offset)); |
| 250 | |
| 251 | if (copy_to_user(ubuf, cb->response_buffer.data + *offset, length)) |
| 252 | rets = -EFAULT; |
| 253 | else { |
| 254 | rets = length; |
| 255 | if ((*offset + length) < cb->buf_idx) { |
| 256 | *offset += length; |
| 257 | goto out; |
| 258 | } |
| 259 | } |
| 260 | free: |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 261 | dev_dbg(&dev->pdev->dev, "free amthif cb memory.\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 262 | *offset = 0; |
| 263 | mei_io_cb_free(cb); |
| 264 | out: |
| 265 | return rets; |
| 266 | } |
| 267 | |
| 268 | /** |
Tomas Winkler | ab5c4a5 | 2012-11-01 21:17:18 +0200 | [diff] [blame] | 269 | * mei_amthif_send_cmd - send amthif command to the ME |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 270 | * |
| 271 | * @dev: the device structure |
| 272 | * @cb: mei call back struct |
| 273 | * |
| 274 | * returns 0 on success, <0 on failure. |
Tomas Winkler | ab5c4a5 | 2012-11-01 21:17:18 +0200 | [diff] [blame] | 275 | * |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 276 | */ |
Tomas Winkler | ab5c4a5 | 2012-11-01 21:17:18 +0200 | [diff] [blame] | 277 | static int mei_amthif_send_cmd(struct mei_device *dev, struct mei_cl_cb *cb) |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 278 | { |
| 279 | struct mei_msg_hdr mei_hdr; |
| 280 | int ret; |
| 281 | |
| 282 | if (!dev || !cb) |
| 283 | return -ENODEV; |
| 284 | |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 285 | dev_dbg(&dev->pdev->dev, "write data to amthif client.\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 286 | |
| 287 | dev->iamthif_state = MEI_IAMTHIF_WRITING; |
| 288 | dev->iamthif_current_cb = cb; |
| 289 | dev->iamthif_file_object = cb->file_object; |
| 290 | dev->iamthif_canceled = false; |
| 291 | dev->iamthif_ioctl = true; |
| 292 | dev->iamthif_msg_buf_size = cb->request_buffer.size; |
| 293 | memcpy(dev->iamthif_msg_buf, cb->request_buffer.data, |
| 294 | cb->request_buffer.size); |
| 295 | |
Tomas Winkler | 90e0b5f1 | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 296 | ret = mei_cl_flow_ctrl_creds(&dev->iamthif_cl); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 297 | if (ret < 0) |
| 298 | return ret; |
| 299 | |
Tomas Winkler | 330dd7d | 2013-02-06 14:06:43 +0200 | [diff] [blame] | 300 | if (ret && dev->hbuf_is_ready) { |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 301 | ret = 0; |
Tomas Winkler | 330dd7d | 2013-02-06 14:06:43 +0200 | [diff] [blame] | 302 | dev->hbuf_is_ready = false; |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 303 | if (cb->request_buffer.size > mei_hbuf_max_len(dev)) { |
| 304 | mei_hdr.length = mei_hbuf_max_len(dev); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 305 | mei_hdr.msg_complete = 0; |
| 306 | } else { |
| 307 | mei_hdr.length = cb->request_buffer.size; |
| 308 | mei_hdr.msg_complete = 1; |
| 309 | } |
| 310 | |
| 311 | mei_hdr.host_addr = dev->iamthif_cl.host_client_id; |
| 312 | mei_hdr.me_addr = dev->iamthif_cl.me_client_id; |
| 313 | mei_hdr.reserved = 0; |
| 314 | dev->iamthif_msg_buf_index += mei_hdr.length; |
| 315 | if (mei_write_message(dev, &mei_hdr, |
Tomas Winkler | 438763f | 2012-12-25 19:05:59 +0200 | [diff] [blame] | 316 | (unsigned char *)dev->iamthif_msg_buf)) |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 317 | return -ENODEV; |
| 318 | |
| 319 | if (mei_hdr.msg_complete) { |
Tomas Winkler | 90e0b5f1 | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 320 | if (mei_cl_flow_ctrl_reduce(&dev->iamthif_cl)) |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 321 | return -ENODEV; |
| 322 | dev->iamthif_flow_control_pending = true; |
| 323 | dev->iamthif_state = MEI_IAMTHIF_FLOW_CONTROL; |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 324 | dev_dbg(&dev->pdev->dev, "add amthif cb to write waiting list\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 325 | dev->iamthif_current_cb = cb; |
| 326 | dev->iamthif_file_object = cb->file_object; |
| 327 | list_add_tail(&cb->list, &dev->write_waiting_list.list); |
| 328 | } else { |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 329 | dev_dbg(&dev->pdev->dev, "message does not complete, so add amthif cb to write list.\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 330 | list_add_tail(&cb->list, &dev->write_list.list); |
| 331 | } |
| 332 | } else { |
Tomas Winkler | 330dd7d | 2013-02-06 14:06:43 +0200 | [diff] [blame] | 333 | if (!dev->hbuf_is_ready) |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 334 | dev_dbg(&dev->pdev->dev, "host buffer is not empty"); |
| 335 | |
| 336 | dev_dbg(&dev->pdev->dev, "No flow control credentials, so add iamthif cb to write list.\n"); |
| 337 | list_add_tail(&cb->list, &dev->write_list.list); |
| 338 | } |
| 339 | return 0; |
| 340 | } |
| 341 | |
| 342 | /** |
Tomas Winkler | ab5c4a5 | 2012-11-01 21:17:18 +0200 | [diff] [blame] | 343 | * mei_amthif_write - write amthif data to amthif client |
| 344 | * |
| 345 | * @dev: the device structure |
| 346 | * @cb: mei call back struct |
| 347 | * |
| 348 | * returns 0 on success, <0 on failure. |
| 349 | * |
| 350 | */ |
| 351 | int mei_amthif_write(struct mei_device *dev, struct mei_cl_cb *cb) |
| 352 | { |
| 353 | int ret; |
| 354 | |
| 355 | if (!dev || !cb) |
| 356 | return -ENODEV; |
| 357 | |
| 358 | ret = mei_io_cb_alloc_resp_buf(cb, dev->iamthif_mtu); |
| 359 | if (ret) |
| 360 | return ret; |
| 361 | |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 362 | cb->fop_type = MEI_FOP_IOCTL; |
Tomas Winkler | ab5c4a5 | 2012-11-01 21:17:18 +0200 | [diff] [blame] | 363 | |
Tomas Winkler | e773efc | 2012-11-11 17:37:58 +0200 | [diff] [blame] | 364 | if (!list_empty(&dev->amthif_cmd_list.list) || |
Tomas Winkler | ab5c4a5 | 2012-11-01 21:17:18 +0200 | [diff] [blame] | 365 | dev->iamthif_state != MEI_IAMTHIF_IDLE) { |
| 366 | dev_dbg(&dev->pdev->dev, |
| 367 | "amthif state = %d\n", dev->iamthif_state); |
| 368 | dev_dbg(&dev->pdev->dev, "AMTHIF: add cb to the wait list\n"); |
Tomas Winkler | e773efc | 2012-11-11 17:37:58 +0200 | [diff] [blame] | 369 | list_add_tail(&cb->list, &dev->amthif_cmd_list.list); |
Tomas Winkler | ab5c4a5 | 2012-11-01 21:17:18 +0200 | [diff] [blame] | 370 | return 0; |
| 371 | } |
| 372 | return mei_amthif_send_cmd(dev, cb); |
| 373 | } |
| 374 | /** |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 375 | * mei_amthif_run_next_cmd |
| 376 | * |
| 377 | * @dev: the device structure |
| 378 | * |
| 379 | * returns 0 on success, <0 on failure. |
| 380 | */ |
| 381 | void mei_amthif_run_next_cmd(struct mei_device *dev) |
| 382 | { |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 383 | struct mei_cl_cb *pos = NULL; |
| 384 | struct mei_cl_cb *next = NULL; |
| 385 | int status; |
| 386 | |
| 387 | if (!dev) |
| 388 | return; |
| 389 | |
| 390 | dev->iamthif_msg_buf_size = 0; |
| 391 | dev->iamthif_msg_buf_index = 0; |
| 392 | dev->iamthif_canceled = false; |
| 393 | dev->iamthif_ioctl = true; |
| 394 | dev->iamthif_state = MEI_IAMTHIF_IDLE; |
| 395 | dev->iamthif_timer = 0; |
| 396 | dev->iamthif_file_object = NULL; |
| 397 | |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 398 | dev_dbg(&dev->pdev->dev, "complete amthif cmd_list cb.\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 399 | |
Tomas Winkler | e773efc | 2012-11-11 17:37:58 +0200 | [diff] [blame] | 400 | list_for_each_entry_safe(pos, next, &dev->amthif_cmd_list.list, list) { |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 401 | list_del(&pos->list); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 402 | |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 403 | if (pos->cl && pos->cl == &dev->iamthif_cl) { |
Tomas Winkler | ab5c4a5 | 2012-11-01 21:17:18 +0200 | [diff] [blame] | 404 | status = mei_amthif_send_cmd(dev, pos); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 405 | if (status) { |
| 406 | dev_dbg(&dev->pdev->dev, |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 407 | "amthif write failed status = %d\n", |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 408 | status); |
| 409 | return; |
| 410 | } |
| 411 | break; |
| 412 | } |
| 413 | } |
| 414 | } |
| 415 | |
Tomas Winkler | 744f0f2 | 2012-11-11 17:38:02 +0200 | [diff] [blame] | 416 | |
| 417 | unsigned int mei_amthif_poll(struct mei_device *dev, |
| 418 | struct file *file, poll_table *wait) |
| 419 | { |
| 420 | unsigned int mask = 0; |
| 421 | mutex_unlock(&dev->device_lock); |
| 422 | poll_wait(file, &dev->iamthif_cl.wait, wait); |
| 423 | mutex_lock(&dev->device_lock); |
| 424 | if (dev->iamthif_state == MEI_IAMTHIF_READ_COMPLETE && |
| 425 | dev->iamthif_file_object == file) { |
| 426 | mask |= (POLLIN | POLLRDNORM); |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 427 | dev_dbg(&dev->pdev->dev, "run next amthif cb\n"); |
Tomas Winkler | 744f0f2 | 2012-11-11 17:38:02 +0200 | [diff] [blame] | 428 | mei_amthif_run_next_cmd(dev); |
| 429 | } |
| 430 | return mask; |
| 431 | } |
| 432 | |
| 433 | |
| 434 | |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 435 | /** |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 436 | * mei_amthif_irq_write_completed - processes completed iamthif operation. |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 437 | * |
| 438 | * @dev: the device structure. |
| 439 | * @slots: free slots. |
| 440 | * @cb_pos: callback block. |
| 441 | * @cl: private data of the file object. |
| 442 | * @cmpl_list: complete list. |
| 443 | * |
| 444 | * returns 0, OK; otherwise, error. |
| 445 | */ |
Tomas Winkler | 24c656e | 2012-11-18 15:13:17 +0200 | [diff] [blame] | 446 | int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots, |
| 447 | struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list) |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 448 | { |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 449 | struct mei_msg_hdr mei_hdr; |
Tomas Winkler | 24c656e | 2012-11-18 15:13:17 +0200 | [diff] [blame] | 450 | struct mei_cl *cl = cb->cl; |
| 451 | size_t len = dev->iamthif_msg_buf_size - dev->iamthif_msg_buf_index; |
Tomas Winkler | c8c8d08 | 2013-03-11 18:27:02 +0200 | [diff] [blame] | 452 | u32 msg_slots = mei_data2slots(len); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 453 | |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 454 | mei_hdr.host_addr = cl->host_client_id; |
| 455 | mei_hdr.me_addr = cl->me_client_id; |
| 456 | mei_hdr.reserved = 0; |
Tomas Winkler | 24c656e | 2012-11-18 15:13:17 +0200 | [diff] [blame] | 457 | |
| 458 | if (*slots >= msg_slots) { |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 459 | mei_hdr.length = len; |
| 460 | mei_hdr.msg_complete = 1; |
Tomas Winkler | 24c656e | 2012-11-18 15:13:17 +0200 | [diff] [blame] | 461 | /* Split the message only if we can write the whole host buffer */ |
| 462 | } else if (*slots == dev->hbuf_depth) { |
| 463 | msg_slots = *slots; |
| 464 | len = (*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr); |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 465 | mei_hdr.length = len; |
| 466 | mei_hdr.msg_complete = 0; |
Tomas Winkler | 24c656e | 2012-11-18 15:13:17 +0200 | [diff] [blame] | 467 | } else { |
| 468 | /* wait for next time the host buffer is empty */ |
| 469 | return 0; |
| 470 | } |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 471 | |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 472 | 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] | 473 | |
Tomas Winkler | 24c656e | 2012-11-18 15:13:17 +0200 | [diff] [blame] | 474 | *slots -= msg_slots; |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 475 | if (mei_write_message(dev, &mei_hdr, |
Tomas Winkler | 438763f | 2012-12-25 19:05:59 +0200 | [diff] [blame] | 476 | dev->iamthif_msg_buf + dev->iamthif_msg_buf_index)) { |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 477 | dev->iamthif_state = MEI_IAMTHIF_IDLE; |
| 478 | cl->status = -ENODEV; |
Tomas Winkler | 24c656e | 2012-11-18 15:13:17 +0200 | [diff] [blame] | 479 | list_del(&cb->list); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 480 | return -ENODEV; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 481 | } |
| 482 | |
Tomas Winkler | 90e0b5f1 | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 483 | if (mei_cl_flow_ctrl_reduce(cl)) |
Tomas Winkler | 24c656e | 2012-11-18 15:13:17 +0200 | [diff] [blame] | 484 | return -ENODEV; |
| 485 | |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 486 | dev->iamthif_msg_buf_index += mei_hdr.length; |
Tomas Winkler | 24c656e | 2012-11-18 15:13:17 +0200 | [diff] [blame] | 487 | cl->status = 0; |
| 488 | |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 489 | if (mei_hdr.msg_complete) { |
Tomas Winkler | 24c656e | 2012-11-18 15:13:17 +0200 | [diff] [blame] | 490 | dev->iamthif_state = MEI_IAMTHIF_FLOW_CONTROL; |
| 491 | dev->iamthif_flow_control_pending = true; |
| 492 | |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 493 | /* save iamthif cb sent to amthif client */ |
Tomas Winkler | 24c656e | 2012-11-18 15:13:17 +0200 | [diff] [blame] | 494 | cb->buf_idx = dev->iamthif_msg_buf_index; |
| 495 | dev->iamthif_current_cb = cb; |
| 496 | |
| 497 | list_move_tail(&cb->list, &dev->write_waiting_list.list); |
| 498 | } |
| 499 | |
| 500 | |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | /** |
| 505 | * mei_amthif_irq_read_message - read routine after ISR to |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 506 | * handle the read amthif message |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 507 | * |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 508 | * @dev: the device structure |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 509 | * @mei_hdr: header of amthif message |
Tomas Winkler | 5ceb46e | 2013-04-19 21:16:53 +0300 | [diff] [blame] | 510 | * @complete_list: An instance of our list structure |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 511 | * |
| 512 | * returns 0 on success, <0 on failure. |
| 513 | */ |
Tomas Winkler | 5ceb46e | 2013-04-19 21:16:53 +0300 | [diff] [blame] | 514 | int mei_amthif_irq_read_msg(struct mei_device *dev, |
| 515 | struct mei_msg_hdr *mei_hdr, |
| 516 | struct mei_cl_cb *complete_list) |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 517 | { |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 518 | struct mei_cl_cb *cb; |
| 519 | unsigned char *buffer; |
| 520 | |
| 521 | BUG_ON(mei_hdr->me_addr != dev->iamthif_cl.me_client_id); |
| 522 | BUG_ON(dev->iamthif_state != MEI_IAMTHIF_READING); |
| 523 | |
| 524 | buffer = dev->iamthif_msg_buf + dev->iamthif_msg_buf_index; |
| 525 | BUG_ON(dev->iamthif_mtu < dev->iamthif_msg_buf_index + mei_hdr->length); |
| 526 | |
| 527 | mei_read_slots(dev, buffer, mei_hdr->length); |
| 528 | |
| 529 | dev->iamthif_msg_buf_index += mei_hdr->length; |
| 530 | |
| 531 | if (!mei_hdr->msg_complete) |
| 532 | return 0; |
| 533 | |
Tomas Winkler | 5ceb46e | 2013-04-19 21:16:53 +0300 | [diff] [blame] | 534 | dev_dbg(&dev->pdev->dev, "amthif_message_buffer_index =%d\n", |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 535 | mei_hdr->length); |
| 536 | |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 537 | dev_dbg(&dev->pdev->dev, "completed amthif read.\n "); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 538 | if (!dev->iamthif_current_cb) |
| 539 | return -ENODEV; |
| 540 | |
| 541 | cb = dev->iamthif_current_cb; |
| 542 | dev->iamthif_current_cb = NULL; |
| 543 | |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 544 | if (!cb->cl) |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 545 | return -ENODEV; |
| 546 | |
| 547 | dev->iamthif_stall_timer = 0; |
| 548 | cb->buf_idx = dev->iamthif_msg_buf_index; |
| 549 | cb->read_time = jiffies; |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 550 | if (dev->iamthif_ioctl && cb->cl == &dev->iamthif_cl) { |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 551 | /* found the iamthif cb */ |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 552 | dev_dbg(&dev->pdev->dev, "complete the amthif read cb.\n "); |
| 553 | dev_dbg(&dev->pdev->dev, "add the amthif read cb to complete.\n "); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 554 | list_add_tail(&cb->list, &complete_list->list); |
| 555 | } |
| 556 | return 0; |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * mei_amthif_irq_read - prepares to read amthif data. |
| 561 | * |
| 562 | * @dev: the device structure. |
| 563 | * @slots: free slots. |
| 564 | * |
| 565 | * returns 0, OK; otherwise, error. |
| 566 | */ |
| 567 | int mei_amthif_irq_read(struct mei_device *dev, s32 *slots) |
| 568 | { |
Tomas Winkler | c8c8d08 | 2013-03-11 18:27:02 +0200 | [diff] [blame] | 569 | u32 msg_slots = mei_data2slots(sizeof(struct hbm_flow_control)); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 570 | |
Tomas Winkler | c8c8d08 | 2013-03-11 18:27:02 +0200 | [diff] [blame] | 571 | if (*slots < msg_slots) |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 572 | return -EMSGSIZE; |
Tomas Winkler | c8c8d08 | 2013-03-11 18:27:02 +0200 | [diff] [blame] | 573 | |
| 574 | *slots -= msg_slots; |
| 575 | |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 576 | if (mei_hbm_cl_flow_control_req(dev, &dev->iamthif_cl)) { |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 577 | dev_dbg(&dev->pdev->dev, "iamthif flow control failed\n"); |
| 578 | return -EIO; |
| 579 | } |
| 580 | |
| 581 | dev_dbg(&dev->pdev->dev, "iamthif flow control success\n"); |
| 582 | dev->iamthif_state = MEI_IAMTHIF_READING; |
| 583 | dev->iamthif_flow_control_pending = false; |
| 584 | dev->iamthif_msg_buf_index = 0; |
| 585 | dev->iamthif_msg_buf_size = 0; |
| 586 | dev->iamthif_stall_timer = MEI_IAMTHIF_STALL_TIMER; |
Tomas Winkler | 330dd7d | 2013-02-06 14:06:43 +0200 | [diff] [blame] | 587 | dev->hbuf_is_ready = mei_hbuf_is_ready(dev); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 588 | return 0; |
| 589 | } |
| 590 | |
| 591 | /** |
| 592 | * mei_amthif_complete - complete amthif callback. |
| 593 | * |
| 594 | * @dev: the device structure. |
| 595 | * @cb_pos: callback block. |
| 596 | */ |
| 597 | void mei_amthif_complete(struct mei_device *dev, struct mei_cl_cb *cb) |
| 598 | { |
| 599 | if (dev->iamthif_canceled != 1) { |
| 600 | dev->iamthif_state = MEI_IAMTHIF_READ_COMPLETE; |
| 601 | dev->iamthif_stall_timer = 0; |
| 602 | memcpy(cb->response_buffer.data, |
| 603 | dev->iamthif_msg_buf, |
| 604 | dev->iamthif_msg_buf_index); |
Tomas Winkler | e773efc | 2012-11-11 17:37:58 +0200 | [diff] [blame] | 605 | list_add_tail(&cb->list, &dev->amthif_rd_complete_list.list); |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 606 | dev_dbg(&dev->pdev->dev, "amthif read completed\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 607 | dev->iamthif_timer = jiffies; |
| 608 | dev_dbg(&dev->pdev->dev, "dev->iamthif_timer = %ld\n", |
| 609 | dev->iamthif_timer); |
| 610 | } else { |
| 611 | mei_amthif_run_next_cmd(dev); |
| 612 | } |
| 613 | |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 614 | dev_dbg(&dev->pdev->dev, "completing amthif call back.\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 615 | wake_up_interruptible(&dev->iamthif_cl.wait); |
| 616 | } |
| 617 | |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 618 | /** |
| 619 | * mei_clear_list - removes all callbacks associated with file |
| 620 | * from mei_cb_list |
| 621 | * |
| 622 | * @dev: device structure. |
| 623 | * @file: file structure |
| 624 | * @mei_cb_list: callbacks list |
| 625 | * |
| 626 | * mei_clear_list is called to clear resources associated with file |
| 627 | * when application calls close function or Ctrl-C was pressed |
| 628 | * |
| 629 | * returns true if callback removed from the list, false otherwise |
| 630 | */ |
| 631 | static bool mei_clear_list(struct mei_device *dev, |
| 632 | const struct file *file, struct list_head *mei_cb_list) |
| 633 | { |
| 634 | struct mei_cl_cb *cb_pos = NULL; |
| 635 | struct mei_cl_cb *cb_next = NULL; |
| 636 | bool removed = false; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 637 | |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 638 | /* list all list member */ |
| 639 | list_for_each_entry_safe(cb_pos, cb_next, mei_cb_list, list) { |
| 640 | /* check if list member associated with a file */ |
| 641 | if (file == cb_pos->file_object) { |
| 642 | /* remove member from the list */ |
| 643 | list_del(&cb_pos->list); |
| 644 | /* check if cb equal to current iamthif cb */ |
| 645 | if (dev->iamthif_current_cb == cb_pos) { |
| 646 | dev->iamthif_current_cb = NULL; |
| 647 | /* send flow control to iamthif client */ |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 648 | mei_hbm_cl_flow_control_req(dev, |
| 649 | &dev->iamthif_cl); |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 650 | } |
| 651 | /* free all allocated buffers */ |
| 652 | mei_io_cb_free(cb_pos); |
| 653 | cb_pos = NULL; |
| 654 | removed = true; |
| 655 | } |
| 656 | } |
| 657 | return removed; |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * mei_clear_lists - removes all callbacks associated with file |
| 662 | * |
| 663 | * @dev: device structure |
| 664 | * @file: file structure |
| 665 | * |
| 666 | * mei_clear_lists is called to clear resources associated with file |
| 667 | * when application calls close function or Ctrl-C was pressed |
| 668 | * |
| 669 | * returns true if callback removed from the list, false otherwise |
| 670 | */ |
| 671 | static bool mei_clear_lists(struct mei_device *dev, struct file *file) |
| 672 | { |
| 673 | bool removed = false; |
| 674 | |
| 675 | /* remove callbacks associated with a file */ |
| 676 | mei_clear_list(dev, file, &dev->amthif_cmd_list.list); |
| 677 | if (mei_clear_list(dev, file, &dev->amthif_rd_complete_list.list)) |
| 678 | removed = true; |
| 679 | |
| 680 | mei_clear_list(dev, file, &dev->ctrl_rd_list.list); |
| 681 | |
| 682 | if (mei_clear_list(dev, file, &dev->ctrl_wr_list.list)) |
| 683 | removed = true; |
| 684 | |
| 685 | if (mei_clear_list(dev, file, &dev->write_waiting_list.list)) |
| 686 | removed = true; |
| 687 | |
| 688 | if (mei_clear_list(dev, file, &dev->write_list.list)) |
| 689 | removed = true; |
| 690 | |
| 691 | /* check if iamthif_current_cb not NULL */ |
| 692 | if (dev->iamthif_current_cb && !removed) { |
| 693 | /* check file and iamthif current cb association */ |
| 694 | if (dev->iamthif_current_cb->file_object == file) { |
| 695 | /* remove cb */ |
| 696 | mei_io_cb_free(dev->iamthif_current_cb); |
| 697 | dev->iamthif_current_cb = NULL; |
| 698 | removed = true; |
| 699 | } |
| 700 | } |
| 701 | return removed; |
| 702 | } |
| 703 | |
| 704 | /** |
| 705 | * mei_amthif_release - the release function |
| 706 | * |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 707 | * @dev: device structure |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 708 | * @file: pointer to file structure |
| 709 | * |
| 710 | * returns 0 on success, <0 on error |
| 711 | */ |
| 712 | int mei_amthif_release(struct mei_device *dev, struct file *file) |
| 713 | { |
| 714 | if (dev->open_handle_count > 0) |
| 715 | dev->open_handle_count--; |
| 716 | |
| 717 | if (dev->iamthif_file_object == file && |
| 718 | dev->iamthif_state != MEI_IAMTHIF_IDLE) { |
| 719 | |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 720 | dev_dbg(&dev->pdev->dev, "amthif canceled iamthif state %d\n", |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 721 | dev->iamthif_state); |
| 722 | dev->iamthif_canceled = true; |
| 723 | if (dev->iamthif_state == MEI_IAMTHIF_READ_COMPLETE) { |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 724 | dev_dbg(&dev->pdev->dev, "run next amthif iamthif cb\n"); |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 725 | mei_amthif_run_next_cmd(dev); |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | if (mei_clear_lists(dev, file)) |
| 730 | dev->iamthif_state = MEI_IAMTHIF_IDLE; |
| 731 | |
| 732 | return 0; |
| 733 | } |