Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +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 | 91f01c6 | 2011-05-15 13:43:44 +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 | #include <linux/pci.h> |
| 18 | #include <linux/sched.h> |
| 19 | #include <linux/wait.h> |
| 20 | #include <linux/delay.h> |
| 21 | |
| 22 | #include "mei_dev.h" |
| 23 | #include "hw.h" |
| 24 | #include "interface.h" |
Tomas Winkler | 4f3afe1 | 2012-05-09 16:38:59 +0300 | [diff] [blame] | 25 | #include <linux/mei.h> |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 26 | |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame^] | 27 | const char *mei_dev_state_str(int state) |
| 28 | { |
| 29 | #define MEI_DEV_STATE(state) case MEI_DEV_##state: return #state |
| 30 | switch (state) { |
| 31 | MEI_DEV_STATE(INITIALIZING); |
| 32 | MEI_DEV_STATE(INIT_CLIENTS); |
| 33 | MEI_DEV_STATE(ENABLED); |
| 34 | MEI_DEV_STATE(RESETING); |
| 35 | MEI_DEV_STATE(DISABLED); |
| 36 | MEI_DEV_STATE(RECOVERING_FROM_RESET); |
| 37 | MEI_DEV_STATE(POWER_DOWN); |
| 38 | MEI_DEV_STATE(POWER_UP); |
| 39 | default: |
| 40 | return "unkown"; |
| 41 | } |
| 42 | #undef MEI_DEV_STATE |
| 43 | } |
| 44 | |
| 45 | |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 46 | const uuid_le mei_amthi_guid = UUID_LE(0x12f80028, 0xb4b7, 0x4b2d, 0xac, |
| 47 | 0xa8, 0x46, 0xe0, 0xff, 0x65, |
| 48 | 0x81, 0x4c); |
| 49 | |
| 50 | /** |
Tomas Winkler | 0288c7c | 2011-06-06 10:44:34 +0300 | [diff] [blame] | 51 | * mei_io_list_init - Sets up a queue list. |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 52 | * |
Tomas Winkler | 0288c7c | 2011-06-06 10:44:34 +0300 | [diff] [blame] | 53 | * @list: An instance io list structure |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 54 | * @dev: the device structure |
| 55 | */ |
Tomas Winkler | 0288c7c | 2011-06-06 10:44:34 +0300 | [diff] [blame] | 56 | void mei_io_list_init(struct mei_io_list *list) |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 57 | { |
| 58 | /* initialize our queue list */ |
| 59 | INIT_LIST_HEAD(&list->mei_cb.cb_list); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /** |
Tomas Winkler | 0288c7c | 2011-06-06 10:44:34 +0300 | [diff] [blame] | 63 | * mei_io_list_flush - removes list entry belonging to cl. |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 64 | * |
| 65 | * @list: An instance of our list structure |
| 66 | * @cl: private data of the file object |
| 67 | */ |
Tomas Winkler | 0288c7c | 2011-06-06 10:44:34 +0300 | [diff] [blame] | 68 | void mei_io_list_flush(struct mei_io_list *list, struct mei_cl *cl) |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 69 | { |
Tomas Winkler | 3a5352f | 2011-12-04 16:16:27 +0200 | [diff] [blame] | 70 | struct mei_cl_cb *pos; |
| 71 | struct mei_cl_cb *next; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 72 | |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 73 | list_for_each_entry_safe(pos, next, &list->mei_cb.cb_list, cb_list) { |
Tomas Winkler | 3a5352f | 2011-12-04 16:16:27 +0200 | [diff] [blame] | 74 | if (pos->file_private) { |
Tomas Winkler | 0288c7c | 2011-06-06 10:44:34 +0300 | [diff] [blame] | 75 | struct mei_cl *cl_tmp; |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 76 | cl_tmp = (struct mei_cl *)pos->file_private; |
Tomas Winkler | 0288c7c | 2011-06-06 10:44:34 +0300 | [diff] [blame] | 77 | if (mei_cl_cmp_id(cl, cl_tmp)) |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 78 | list_del(&pos->cb_list); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | } |
Tomas Winkler | 0288c7c | 2011-06-06 10:44:34 +0300 | [diff] [blame] | 82 | /** |
| 83 | * mei_cl_flush_queues - flushes queue lists belonging to cl. |
| 84 | * |
| 85 | * @dev: the device structure |
| 86 | * @cl: private data of the file object |
| 87 | */ |
| 88 | int mei_cl_flush_queues(struct mei_cl *cl) |
| 89 | { |
| 90 | if (!cl || !cl->dev) |
| 91 | return -EINVAL; |
| 92 | |
| 93 | dev_dbg(&cl->dev->pdev->dev, "remove list entry belonging to cl\n"); |
| 94 | mei_io_list_flush(&cl->dev->read_list, cl); |
| 95 | mei_io_list_flush(&cl->dev->write_list, cl); |
| 96 | mei_io_list_flush(&cl->dev->write_waiting_list, cl); |
| 97 | mei_io_list_flush(&cl->dev->ctrl_wr_list, cl); |
| 98 | mei_io_list_flush(&cl->dev->ctrl_rd_list, cl); |
| 99 | mei_io_list_flush(&cl->dev->amthi_cmd_list, cl); |
| 100 | mei_io_list_flush(&cl->dev->amthi_read_complete_list, cl); |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 105 | |
| 106 | /** |
| 107 | * mei_reset_iamthif_params - initializes mei device iamthif |
| 108 | * |
| 109 | * @dev: the device structure |
| 110 | */ |
| 111 | static void mei_reset_iamthif_params(struct mei_device *dev) |
| 112 | { |
| 113 | /* reset iamthif parameters. */ |
| 114 | dev->iamthif_current_cb = NULL; |
| 115 | dev->iamthif_msg_buf_size = 0; |
| 116 | dev->iamthif_msg_buf_index = 0; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 117 | dev->iamthif_canceled = false; |
| 118 | dev->iamthif_ioctl = false; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 119 | dev->iamthif_state = MEI_IAMTHIF_IDLE; |
| 120 | dev->iamthif_timer = 0; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * init_mei_device - allocates and initializes the mei device structure |
| 125 | * |
| 126 | * @pdev: The pci device structure |
| 127 | * |
| 128 | * returns The mei_device_device pointer on success, NULL on failure. |
| 129 | */ |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 130 | struct mei_device *mei_device_init(struct pci_dev *pdev) |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 131 | { |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 132 | struct mei_device *dev; |
| 133 | |
| 134 | dev = kzalloc(sizeof(struct mei_device), GFP_KERNEL); |
| 135 | if (!dev) |
| 136 | return NULL; |
| 137 | |
| 138 | /* setup our list array */ |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 139 | INIT_LIST_HEAD(&dev->file_list); |
| 140 | INIT_LIST_HEAD(&dev->wd_cl.link); |
| 141 | INIT_LIST_HEAD(&dev->iamthif_cl.link); |
| 142 | mutex_init(&dev->device_lock); |
| 143 | init_waitqueue_head(&dev->wait_recvd_msg); |
| 144 | init_waitqueue_head(&dev->wait_stop_wd); |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame^] | 145 | dev->dev_state = MEI_DEV_INITIALIZING; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 146 | dev->iamthif_state = MEI_IAMTHIF_IDLE; |
Oren Weil | 9ce178e | 2011-09-07 09:03:09 +0300 | [diff] [blame] | 147 | dev->wd_interface_reg = false; |
Tomas Winkler | 0288c7c | 2011-06-06 10:44:34 +0300 | [diff] [blame] | 148 | |
| 149 | |
| 150 | mei_io_list_init(&dev->read_list); |
| 151 | mei_io_list_init(&dev->write_list); |
| 152 | mei_io_list_init(&dev->write_waiting_list); |
| 153 | mei_io_list_init(&dev->ctrl_wr_list); |
| 154 | mei_io_list_init(&dev->ctrl_rd_list); |
| 155 | mei_io_list_init(&dev->amthi_cmd_list); |
| 156 | mei_io_list_init(&dev->amthi_read_complete_list); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 157 | dev->pdev = pdev; |
| 158 | return dev; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * mei_hw_init - initializes host and fw to start work. |
| 163 | * |
| 164 | * @dev: the device structure |
| 165 | * |
| 166 | * returns 0 on success, <0 on failure. |
| 167 | */ |
| 168 | int mei_hw_init(struct mei_device *dev) |
| 169 | { |
| 170 | int err = 0; |
| 171 | int ret; |
| 172 | |
| 173 | mutex_lock(&dev->device_lock); |
| 174 | |
| 175 | dev->host_hw_state = mei_hcsr_read(dev); |
| 176 | dev->me_hw_state = mei_mecsr_read(dev); |
| 177 | dev_dbg(&dev->pdev->dev, "host_hw_state = 0x%08x, mestate = 0x%08x.\n", |
| 178 | dev->host_hw_state, dev->me_hw_state); |
| 179 | |
| 180 | /* acknowledge interrupt and stop interupts */ |
| 181 | if ((dev->host_hw_state & H_IS) == H_IS) |
| 182 | mei_reg_write(dev, H_CSR, dev->host_hw_state); |
| 183 | |
Tomas Winkler | 24aadc8 | 2012-06-25 23:46:27 +0300 | [diff] [blame] | 184 | /* Doesn't change in runtime */ |
| 185 | dev->hbuf_depth = (dev->host_hw_state & H_CBD) >> 24; |
| 186 | |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 187 | dev->recvd_msg = false; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 188 | dev_dbg(&dev->pdev->dev, "reset in start the mei device.\n"); |
| 189 | |
| 190 | mei_reset(dev, 1); |
| 191 | |
| 192 | dev_dbg(&dev->pdev->dev, "host_hw_state = 0x%08x, me_hw_state = 0x%08x.\n", |
| 193 | dev->host_hw_state, dev->me_hw_state); |
| 194 | |
| 195 | /* wait for ME to turn on ME_RDY */ |
| 196 | if (!dev->recvd_msg) { |
| 197 | mutex_unlock(&dev->device_lock); |
| 198 | err = wait_event_interruptible_timeout(dev->wait_recvd_msg, |
| 199 | dev->recvd_msg, MEI_INTEROP_TIMEOUT); |
| 200 | mutex_lock(&dev->device_lock); |
| 201 | } |
| 202 | |
Tomas Winkler | a534bb6 | 2011-06-13 16:39:31 +0300 | [diff] [blame] | 203 | if (err <= 0 && !dev->recvd_msg) { |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame^] | 204 | dev->dev_state = MEI_DEV_DISABLED; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 205 | dev_dbg(&dev->pdev->dev, |
| 206 | "wait_event_interruptible_timeout failed" |
| 207 | "on wait for ME to turn on ME_RDY.\n"); |
| 208 | ret = -ENODEV; |
| 209 | goto out; |
| 210 | } |
| 211 | |
| 212 | if (!(((dev->host_hw_state & H_RDY) == H_RDY) && |
| 213 | ((dev->me_hw_state & ME_RDY_HRA) == ME_RDY_HRA))) { |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame^] | 214 | dev->dev_state = MEI_DEV_DISABLED; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 215 | dev_dbg(&dev->pdev->dev, |
| 216 | "host_hw_state = 0x%08x, me_hw_state = 0x%08x.\n", |
| 217 | dev->host_hw_state, dev->me_hw_state); |
| 218 | |
Dan Carpenter | 8eb73c6 | 2011-06-09 10:18:23 +0300 | [diff] [blame] | 219 | if (!(dev->host_hw_state & H_RDY)) |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 220 | dev_dbg(&dev->pdev->dev, "host turn off H_RDY.\n"); |
| 221 | |
Dan Carpenter | 8eb73c6 | 2011-06-09 10:18:23 +0300 | [diff] [blame] | 222 | if (!(dev->me_hw_state & ME_RDY_HRA)) |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 223 | dev_dbg(&dev->pdev->dev, "ME turn off ME_RDY.\n"); |
| 224 | |
Tomas Winkler | d39a464 | 2012-03-19 17:58:42 +0200 | [diff] [blame] | 225 | dev_err(&dev->pdev->dev, "link layer initialization failed.\n"); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 226 | ret = -ENODEV; |
| 227 | goto out; |
| 228 | } |
| 229 | |
| 230 | if (dev->version.major_version != HBM_MAJOR_VERSION || |
| 231 | dev->version.minor_version != HBM_MINOR_VERSION) { |
| 232 | dev_dbg(&dev->pdev->dev, "MEI start failed.\n"); |
| 233 | ret = -ENODEV; |
| 234 | goto out; |
| 235 | } |
| 236 | |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 237 | dev->recvd_msg = false; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 238 | dev_dbg(&dev->pdev->dev, "host_hw_state = 0x%08x, me_hw_state = 0x%08x.\n", |
| 239 | dev->host_hw_state, dev->me_hw_state); |
| 240 | dev_dbg(&dev->pdev->dev, "ME turn on ME_RDY and host turn on H_RDY.\n"); |
| 241 | dev_dbg(&dev->pdev->dev, "link layer has been established.\n"); |
| 242 | dev_dbg(&dev->pdev->dev, "MEI start success.\n"); |
| 243 | ret = 0; |
| 244 | |
| 245 | out: |
| 246 | mutex_unlock(&dev->device_lock); |
| 247 | return ret; |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * mei_hw_reset - resets fw via mei csr register. |
| 252 | * |
| 253 | * @dev: the device structure |
| 254 | * @interrupts_enabled: if interrupt should be enabled after reset. |
| 255 | */ |
| 256 | static void mei_hw_reset(struct mei_device *dev, int interrupts_enabled) |
| 257 | { |
| 258 | dev->host_hw_state |= (H_RST | H_IG); |
| 259 | |
| 260 | if (interrupts_enabled) |
| 261 | mei_enable_interrupts(dev); |
| 262 | else |
| 263 | mei_disable_interrupts(dev); |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * mei_reset - resets host and fw. |
| 268 | * |
| 269 | * @dev: the device structure |
| 270 | * @interrupts_enabled: if interrupt should be enabled after reset. |
| 271 | */ |
| 272 | void mei_reset(struct mei_device *dev, int interrupts_enabled) |
| 273 | { |
| 274 | struct mei_cl *cl_pos = NULL; |
| 275 | struct mei_cl *cl_next = NULL; |
| 276 | struct mei_cl_cb *cb_pos = NULL; |
| 277 | struct mei_cl_cb *cb_next = NULL; |
| 278 | bool unexpected; |
| 279 | |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame^] | 280 | if (dev->dev_state == MEI_DEV_RECOVERING_FROM_RESET) { |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 281 | dev->need_reset = true; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 282 | return; |
| 283 | } |
| 284 | |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame^] | 285 | unexpected = (dev->dev_state != MEI_DEV_INITIALIZING && |
| 286 | dev->dev_state != MEI_DEV_DISABLED && |
| 287 | dev->dev_state != MEI_DEV_POWER_DOWN && |
| 288 | dev->dev_state != MEI_DEV_POWER_UP); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 289 | |
| 290 | dev->host_hw_state = mei_hcsr_read(dev); |
| 291 | |
| 292 | dev_dbg(&dev->pdev->dev, "before reset host_hw_state = 0x%08x.\n", |
| 293 | dev->host_hw_state); |
| 294 | |
| 295 | mei_hw_reset(dev, interrupts_enabled); |
| 296 | |
| 297 | dev->host_hw_state &= ~H_RST; |
| 298 | dev->host_hw_state |= H_IG; |
| 299 | |
| 300 | mei_hcsr_set(dev); |
| 301 | |
| 302 | dev_dbg(&dev->pdev->dev, "currently saved host_hw_state = 0x%08x.\n", |
| 303 | dev->host_hw_state); |
| 304 | |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 305 | dev->need_reset = false; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 306 | |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame^] | 307 | if (dev->dev_state != MEI_DEV_INITIALIZING) { |
| 308 | if (dev->dev_state != MEI_DEV_DISABLED && |
| 309 | dev->dev_state != MEI_DEV_POWER_DOWN) |
| 310 | dev->dev_state = MEI_DEV_RESETING; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 311 | |
| 312 | list_for_each_entry_safe(cl_pos, |
| 313 | cl_next, &dev->file_list, link) { |
| 314 | cl_pos->state = MEI_FILE_DISCONNECTED; |
| 315 | cl_pos->mei_flow_ctrl_creds = 0; |
| 316 | cl_pos->read_cb = NULL; |
| 317 | cl_pos->timer_count = 0; |
| 318 | } |
| 319 | /* remove entry if already in list */ |
| 320 | dev_dbg(&dev->pdev->dev, "list del iamthif and wd file list.\n"); |
| 321 | mei_remove_client_from_file_list(dev, |
| 322 | dev->wd_cl.host_client_id); |
| 323 | |
| 324 | mei_remove_client_from_file_list(dev, |
| 325 | dev->iamthif_cl.host_client_id); |
| 326 | |
| 327 | mei_reset_iamthif_params(dev); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 328 | dev->extra_write_index = 0; |
| 329 | } |
| 330 | |
Tomas Winkler | cf9673d | 2011-06-06 10:44:33 +0300 | [diff] [blame] | 331 | dev->me_clients_num = 0; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 332 | dev->rd_msg_hdr = 0; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 333 | dev->stop = false; |
| 334 | dev->wd_pending = false; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 335 | |
| 336 | /* update the state of the registers after reset */ |
| 337 | dev->host_hw_state = mei_hcsr_read(dev); |
| 338 | dev->me_hw_state = mei_mecsr_read(dev); |
| 339 | |
| 340 | dev_dbg(&dev->pdev->dev, "after reset host_hw_state = 0x%08x, me_hw_state = 0x%08x.\n", |
| 341 | dev->host_hw_state, dev->me_hw_state); |
| 342 | |
| 343 | if (unexpected) |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame^] | 344 | dev_warn(&dev->pdev->dev, "unexpected reset: dev_state = %s\n", |
| 345 | mei_dev_state_str(dev->dev_state)); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 346 | |
| 347 | /* Wake up all readings so they can be interrupted */ |
| 348 | list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) { |
| 349 | if (waitqueue_active(&cl_pos->rx_wait)) { |
| 350 | dev_dbg(&dev->pdev->dev, "Waking up client!\n"); |
| 351 | wake_up_interruptible(&cl_pos->rx_wait); |
| 352 | } |
| 353 | } |
| 354 | /* remove all waiting requests */ |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 355 | list_for_each_entry_safe(cb_pos, cb_next, |
| 356 | &dev->write_list.mei_cb.cb_list, cb_list) { |
Tomas Winkler | 3a5352f | 2011-12-04 16:16:27 +0200 | [diff] [blame] | 357 | list_del(&cb_pos->cb_list); |
| 358 | mei_free_cb_private(cb_pos); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
| 362 | |
| 363 | |
| 364 | /** |
| 365 | * host_start_message - mei host sends start message. |
| 366 | * |
| 367 | * @dev: the device structure |
| 368 | * |
| 369 | * returns none. |
| 370 | */ |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 371 | void mei_host_start_message(struct mei_device *dev) |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 372 | { |
| 373 | struct mei_msg_hdr *mei_hdr; |
| 374 | struct hbm_host_version_request *host_start_req; |
| 375 | |
| 376 | /* host start message */ |
| 377 | mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0]; |
| 378 | mei_hdr->host_addr = 0; |
| 379 | mei_hdr->me_addr = 0; |
| 380 | mei_hdr->length = sizeof(struct hbm_host_version_request); |
| 381 | mei_hdr->msg_complete = 1; |
| 382 | mei_hdr->reserved = 0; |
| 383 | |
| 384 | host_start_req = |
| 385 | (struct hbm_host_version_request *) &dev->wr_msg_buf[1]; |
| 386 | memset(host_start_req, 0, sizeof(struct hbm_host_version_request)); |
Tomas Winkler | 1ca7e78 | 2012-02-26 23:18:57 +0200 | [diff] [blame] | 387 | host_start_req->hbm_cmd = HOST_START_REQ_CMD; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 388 | host_start_req->host_version.major_version = HBM_MAJOR_VERSION; |
| 389 | host_start_req->host_version.minor_version = HBM_MINOR_VERSION; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 390 | dev->recvd_msg = false; |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 391 | if (mei_write_message(dev, mei_hdr, (unsigned char *)host_start_req, |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 392 | mei_hdr->length)) { |
| 393 | dev_dbg(&dev->pdev->dev, "write send version message to FW fail.\n"); |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame^] | 394 | dev->dev_state = MEI_DEV_RESETING; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 395 | mei_reset(dev, 1); |
| 396 | } |
| 397 | dev->init_clients_state = MEI_START_MESSAGE; |
| 398 | dev->init_clients_timer = INIT_CLIENTS_TIMEOUT; |
| 399 | return ; |
| 400 | } |
| 401 | |
| 402 | /** |
| 403 | * host_enum_clients_message - host sends enumeration client request message. |
| 404 | * |
| 405 | * @dev: the device structure |
| 406 | * |
| 407 | * returns none. |
| 408 | */ |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 409 | void mei_host_enum_clients_message(struct mei_device *dev) |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 410 | { |
| 411 | struct mei_msg_hdr *mei_hdr; |
| 412 | struct hbm_host_enum_request *host_enum_req; |
| 413 | mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0]; |
| 414 | /* enumerate clients */ |
| 415 | mei_hdr->host_addr = 0; |
| 416 | mei_hdr->me_addr = 0; |
| 417 | mei_hdr->length = sizeof(struct hbm_host_enum_request); |
| 418 | mei_hdr->msg_complete = 1; |
| 419 | mei_hdr->reserved = 0; |
| 420 | |
| 421 | host_enum_req = (struct hbm_host_enum_request *) &dev->wr_msg_buf[1]; |
| 422 | memset(host_enum_req, 0, sizeof(struct hbm_host_enum_request)); |
Tomas Winkler | 1ca7e78 | 2012-02-26 23:18:57 +0200 | [diff] [blame] | 423 | host_enum_req->hbm_cmd = HOST_ENUM_REQ_CMD; |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 424 | if (mei_write_message(dev, mei_hdr, (unsigned char *)host_enum_req, |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 425 | mei_hdr->length)) { |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame^] | 426 | dev->dev_state = MEI_DEV_RESETING; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 427 | dev_dbg(&dev->pdev->dev, "write send enumeration request message to FW fail.\n"); |
| 428 | mei_reset(dev, 1); |
| 429 | } |
| 430 | dev->init_clients_state = MEI_ENUM_CLIENTS_MESSAGE; |
| 431 | dev->init_clients_timer = INIT_CLIENTS_TIMEOUT; |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 432 | return; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | |
| 436 | /** |
| 437 | * allocate_me_clients_storage - allocates storage for me clients |
| 438 | * |
| 439 | * @dev: the device structure |
| 440 | * |
| 441 | * returns none. |
| 442 | */ |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 443 | void mei_allocate_me_clients_storage(struct mei_device *dev) |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 444 | { |
| 445 | struct mei_me_client *clients; |
| 446 | int b; |
| 447 | |
| 448 | /* count how many ME clients we have */ |
| 449 | for_each_set_bit(b, dev->me_clients_map, MEI_CLIENTS_MAX) |
Tomas Winkler | cf9673d | 2011-06-06 10:44:33 +0300 | [diff] [blame] | 450 | dev->me_clients_num++; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 451 | |
Tomas Winkler | cf9673d | 2011-06-06 10:44:33 +0300 | [diff] [blame] | 452 | if (dev->me_clients_num <= 0) |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 453 | return ; |
| 454 | |
| 455 | |
| 456 | if (dev->me_clients != NULL) { |
| 457 | kfree(dev->me_clients); |
| 458 | dev->me_clients = NULL; |
| 459 | } |
| 460 | dev_dbg(&dev->pdev->dev, "memory allocation for ME clients size=%zd.\n", |
Tomas Winkler | cf9673d | 2011-06-06 10:44:33 +0300 | [diff] [blame] | 461 | dev->me_clients_num * sizeof(struct mei_me_client)); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 462 | /* allocate storage for ME clients representation */ |
Tomas Winkler | cf9673d | 2011-06-06 10:44:33 +0300 | [diff] [blame] | 463 | clients = kcalloc(dev->me_clients_num, |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 464 | sizeof(struct mei_me_client), GFP_KERNEL); |
| 465 | if (!clients) { |
| 466 | dev_dbg(&dev->pdev->dev, "memory allocation for ME clients failed.\n"); |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame^] | 467 | dev->dev_state = MEI_DEV_RESETING; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 468 | mei_reset(dev, 1); |
| 469 | return ; |
| 470 | } |
| 471 | dev->me_clients = clients; |
| 472 | return ; |
| 473 | } |
| 474 | /** |
| 475 | * host_client_properties - reads properties for client |
| 476 | * |
| 477 | * @dev: the device structure |
| 478 | * |
Oren Weil | abc51b6 | 2011-09-21 16:45:30 +0300 | [diff] [blame] | 479 | * returns: |
| 480 | * < 0 - Error. |
| 481 | * = 0 - no more clients. |
| 482 | * = 1 - still have clients to send properties request. |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 483 | */ |
Oren Weil | abc51b6 | 2011-09-21 16:45:30 +0300 | [diff] [blame] | 484 | int mei_host_client_properties(struct mei_device *dev) |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 485 | { |
| 486 | struct mei_msg_hdr *mei_header; |
| 487 | struct hbm_props_request *host_cli_req; |
| 488 | int b; |
| 489 | u8 client_num = dev->me_client_presentation_num; |
| 490 | |
| 491 | b = dev->me_client_index; |
| 492 | b = find_next_bit(dev->me_clients_map, MEI_CLIENTS_MAX, b); |
| 493 | if (b < MEI_CLIENTS_MAX) { |
| 494 | dev->me_clients[client_num].client_id = b; |
| 495 | dev->me_clients[client_num].mei_flow_ctrl_creds = 0; |
| 496 | mei_header = (struct mei_msg_hdr *)&dev->wr_msg_buf[0]; |
| 497 | mei_header->host_addr = 0; |
| 498 | mei_header->me_addr = 0; |
| 499 | mei_header->length = sizeof(struct hbm_props_request); |
| 500 | mei_header->msg_complete = 1; |
| 501 | mei_header->reserved = 0; |
| 502 | |
| 503 | host_cli_req = (struct hbm_props_request *)&dev->wr_msg_buf[1]; |
| 504 | |
| 505 | memset(host_cli_req, 0, sizeof(struct hbm_props_request)); |
| 506 | |
Tomas Winkler | 1ca7e78 | 2012-02-26 23:18:57 +0200 | [diff] [blame] | 507 | host_cli_req->hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 508 | host_cli_req->address = b; |
| 509 | |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 510 | if (mei_write_message(dev, mei_header, |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 511 | (unsigned char *)host_cli_req, |
| 512 | mei_header->length)) { |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame^] | 513 | dev->dev_state = MEI_DEV_RESETING; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 514 | dev_dbg(&dev->pdev->dev, "write send enumeration request message to FW fail.\n"); |
| 515 | mei_reset(dev, 1); |
Oren Weil | abc51b6 | 2011-09-21 16:45:30 +0300 | [diff] [blame] | 516 | return -EIO; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | dev->init_clients_timer = INIT_CLIENTS_TIMEOUT; |
| 520 | dev->me_client_index = b; |
Oren Weil | abc51b6 | 2011-09-21 16:45:30 +0300 | [diff] [blame] | 521 | return 1; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 522 | } |
| 523 | |
Oren Weil | abc51b6 | 2011-09-21 16:45:30 +0300 | [diff] [blame] | 524 | return 0; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | /** |
| 528 | * mei_init_file_private - initializes private file structure. |
| 529 | * |
| 530 | * @priv: private file structure to be initialized |
| 531 | * @file: the file structure |
| 532 | */ |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 533 | void mei_cl_init(struct mei_cl *priv, struct mei_device *dev) |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 534 | { |
| 535 | memset(priv, 0, sizeof(struct mei_cl)); |
| 536 | init_waitqueue_head(&priv->wait); |
| 537 | init_waitqueue_head(&priv->rx_wait); |
| 538 | init_waitqueue_head(&priv->tx_wait); |
| 539 | INIT_LIST_HEAD(&priv->link); |
| 540 | priv->reading_state = MEI_IDLE; |
| 541 | priv->writing_state = MEI_IDLE; |
| 542 | priv->dev = dev; |
| 543 | } |
| 544 | |
Tomas Winkler | 07b509b | 2012-07-23 14:05:39 +0300 | [diff] [blame] | 545 | int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid) |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 546 | { |
Tomas Winkler | 07b509b | 2012-07-23 14:05:39 +0300 | [diff] [blame] | 547 | int i, res = -ENOENT; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 548 | |
Tomas Winkler | cf9673d | 2011-06-06 10:44:33 +0300 | [diff] [blame] | 549 | for (i = 0; i < dev->me_clients_num; ++i) |
Tomas Winkler | 07b509b | 2012-07-23 14:05:39 +0300 | [diff] [blame] | 550 | if (uuid_le_cmp(*cuuid, |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 551 | dev->me_clients[i].props.protocol_name) == 0) { |
| 552 | res = i; |
| 553 | break; |
| 554 | } |
| 555 | |
| 556 | return res; |
| 557 | } |
| 558 | |
| 559 | |
| 560 | /** |
Tomas Winkler | 07b509b | 2012-07-23 14:05:39 +0300 | [diff] [blame] | 561 | * mei_me_cl_update_filext - searches for ME client guid |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 562 | * sets client_id in mei_file_private if found |
| 563 | * @dev: the device structure |
Tomas Winkler | 07b509b | 2012-07-23 14:05:39 +0300 | [diff] [blame] | 564 | * @cl: private file structure to set client_id in |
| 565 | * @cuuid: searched uuid of ME client |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 566 | * @client_id: id of host client to be set in file private structure |
| 567 | * |
| 568 | * returns ME client index |
| 569 | */ |
Tomas Winkler | 07b509b | 2012-07-23 14:05:39 +0300 | [diff] [blame] | 570 | int mei_me_cl_update_filext(struct mei_device *dev, struct mei_cl *cl, |
| 571 | const uuid_le *cuuid, u8 host_cl_id) |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 572 | { |
| 573 | int i; |
| 574 | |
Tomas Winkler | 07b509b | 2012-07-23 14:05:39 +0300 | [diff] [blame] | 575 | if (!dev || !cl || !cuuid) |
| 576 | return -EINVAL; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 577 | |
| 578 | /* check for valid client id */ |
Tomas Winkler | 07b509b | 2012-07-23 14:05:39 +0300 | [diff] [blame] | 579 | i = mei_me_cl_by_uuid(dev, cuuid); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 580 | if (i >= 0) { |
Tomas Winkler | 07b509b | 2012-07-23 14:05:39 +0300 | [diff] [blame] | 581 | cl->me_client_id = dev->me_clients[i].client_id; |
| 582 | cl->state = MEI_FILE_CONNECTING; |
| 583 | cl->host_client_id = host_cl_id; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 584 | |
Tomas Winkler | 07b509b | 2012-07-23 14:05:39 +0300 | [diff] [blame] | 585 | list_add_tail(&cl->link, &dev->file_list); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 586 | return (u8)i; |
| 587 | } |
| 588 | |
Tomas Winkler | 07b509b | 2012-07-23 14:05:39 +0300 | [diff] [blame] | 589 | return -ENOENT; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | /** |
| 593 | * host_init_iamthif - mei initialization iamthif client. |
| 594 | * |
| 595 | * @dev: the device structure |
| 596 | * |
| 597 | */ |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 598 | void mei_host_init_iamthif(struct mei_device *dev) |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 599 | { |
Tomas Winkler | 07b509b | 2012-07-23 14:05:39 +0300 | [diff] [blame] | 600 | int i; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 601 | unsigned char *msg_buf; |
| 602 | |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 603 | mei_cl_init(&dev->iamthif_cl, dev); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 604 | dev->iamthif_cl.state = MEI_FILE_DISCONNECTED; |
| 605 | |
| 606 | /* find ME amthi client */ |
Tomas Winkler | 07b509b | 2012-07-23 14:05:39 +0300 | [diff] [blame] | 607 | i = mei_me_cl_update_filext(dev, &dev->iamthif_cl, |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 608 | &mei_amthi_guid, MEI_IAMTHIF_HOST_CLIENT_ID); |
Tomas Winkler | 07b509b | 2012-07-23 14:05:39 +0300 | [diff] [blame] | 609 | if (i < 0) { |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 610 | dev_dbg(&dev->pdev->dev, "failed to find iamthif client.\n"); |
| 611 | return; |
| 612 | } |
| 613 | |
Tomas Winkler | c9667bf | 2011-12-13 23:39:33 +0200 | [diff] [blame] | 614 | /* Assign iamthif_mtu to the value received from ME */ |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 615 | |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 616 | dev->iamthif_mtu = dev->me_clients[i].props.max_msg_length; |
Tomas Winkler | c9667bf | 2011-12-13 23:39:33 +0200 | [diff] [blame] | 617 | dev_dbg(&dev->pdev->dev, "IAMTHIF_MTU = %d\n", |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 618 | dev->me_clients[i].props.max_msg_length); |
| 619 | |
| 620 | kfree(dev->iamthif_msg_buf); |
| 621 | dev->iamthif_msg_buf = NULL; |
| 622 | |
| 623 | /* allocate storage for ME message buffer */ |
| 624 | msg_buf = kcalloc(dev->iamthif_mtu, |
| 625 | sizeof(unsigned char), GFP_KERNEL); |
| 626 | if (!msg_buf) { |
| 627 | dev_dbg(&dev->pdev->dev, "memory allocation for ME message buffer failed.\n"); |
| 628 | return; |
| 629 | } |
| 630 | |
| 631 | dev->iamthif_msg_buf = msg_buf; |
| 632 | |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 633 | if (mei_connect(dev, &dev->iamthif_cl)) { |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 634 | dev_dbg(&dev->pdev->dev, "Failed to connect to AMTHI client\n"); |
| 635 | dev->iamthif_cl.state = MEI_FILE_DISCONNECTED; |
| 636 | dev->iamthif_cl.host_client_id = 0; |
| 637 | } else { |
| 638 | dev->iamthif_cl.timer_count = CONNECT_TIMEOUT; |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | /** |
| 643 | * mei_alloc_file_private - allocates a private file structure and sets it up. |
| 644 | * @file: the file structure |
| 645 | * |
| 646 | * returns The allocated file or NULL on failure |
| 647 | */ |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 648 | struct mei_cl *mei_cl_allocate(struct mei_device *dev) |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 649 | { |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 650 | struct mei_cl *cl; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 651 | |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 652 | cl = kmalloc(sizeof(struct mei_cl), GFP_KERNEL); |
| 653 | if (!cl) |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 654 | return NULL; |
| 655 | |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 656 | mei_cl_init(cl, dev); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 657 | |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 658 | return cl; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | |
| 662 | |
| 663 | /** |
| 664 | * mei_disconnect_host_client - sends disconnect message to fw from host client. |
| 665 | * |
| 666 | * @dev: the device structure |
| 667 | * @cl: private data of the file object |
| 668 | * |
| 669 | * Locking: called under "dev->device_lock" lock |
| 670 | * |
| 671 | * returns 0 on success, <0 on failure. |
| 672 | */ |
| 673 | int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl) |
| 674 | { |
| 675 | int rets, err; |
| 676 | long timeout = 15; /* 15 seconds */ |
| 677 | struct mei_cl_cb *cb; |
| 678 | |
| 679 | if (!dev || !cl) |
| 680 | return -ENODEV; |
| 681 | |
| 682 | if (cl->state != MEI_FILE_DISCONNECTING) |
| 683 | return 0; |
| 684 | |
| 685 | cb = kzalloc(sizeof(struct mei_cl_cb), GFP_KERNEL); |
| 686 | if (!cb) |
| 687 | return -ENOMEM; |
| 688 | |
| 689 | INIT_LIST_HEAD(&cb->cb_list); |
| 690 | cb->file_private = cl; |
| 691 | cb->major_file_operations = MEI_CLOSE; |
| 692 | if (dev->mei_host_buffer_is_empty) { |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 693 | dev->mei_host_buffer_is_empty = false; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 694 | if (mei_disconnect(dev, cl)) { |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 695 | rets = -ENODEV; |
| 696 | dev_dbg(&dev->pdev->dev, "failed to call mei_disconnect.\n"); |
| 697 | goto free; |
| 698 | } |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 699 | mdelay(10); /* Wait for hardware disconnection ready */ |
| 700 | list_add_tail(&cb->cb_list, &dev->ctrl_rd_list.mei_cb.cb_list); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 701 | } else { |
| 702 | dev_dbg(&dev->pdev->dev, "add disconnect cb to control write list\n"); |
| 703 | list_add_tail(&cb->cb_list, |
| 704 | &dev->ctrl_wr_list.mei_cb.cb_list); |
| 705 | } |
| 706 | mutex_unlock(&dev->device_lock); |
| 707 | |
| 708 | err = wait_event_timeout(dev->wait_recvd_msg, |
| 709 | (MEI_FILE_DISCONNECTED == cl->state), |
| 710 | timeout * HZ); |
| 711 | |
| 712 | mutex_lock(&dev->device_lock); |
| 713 | if (MEI_FILE_DISCONNECTED == cl->state) { |
| 714 | rets = 0; |
| 715 | dev_dbg(&dev->pdev->dev, "successfully disconnected from FW client.\n"); |
| 716 | } else { |
| 717 | rets = -ENODEV; |
| 718 | if (MEI_FILE_DISCONNECTED != cl->state) |
| 719 | dev_dbg(&dev->pdev->dev, "wrong status client disconnect.\n"); |
| 720 | |
| 721 | if (err) |
| 722 | dev_dbg(&dev->pdev->dev, |
| 723 | "wait failed disconnect err=%08x\n", |
| 724 | err); |
| 725 | |
| 726 | dev_dbg(&dev->pdev->dev, "failed to disconnect from FW client.\n"); |
| 727 | } |
| 728 | |
Tomas Winkler | 0288c7c | 2011-06-06 10:44:34 +0300 | [diff] [blame] | 729 | mei_io_list_flush(&dev->ctrl_rd_list, cl); |
| 730 | mei_io_list_flush(&dev->ctrl_wr_list, cl); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 731 | free: |
| 732 | mei_free_cb_private(cb); |
| 733 | return rets; |
| 734 | } |
| 735 | |
| 736 | /** |
| 737 | * mei_remove_client_from_file_list - |
| 738 | * removes file private data from device file list |
| 739 | * |
| 740 | * @dev: the device structure |
| 741 | * @host_client_id: host client id to be removed |
| 742 | */ |
| 743 | void mei_remove_client_from_file_list(struct mei_device *dev, |
| 744 | u8 host_client_id) |
| 745 | { |
| 746 | struct mei_cl *cl_pos = NULL; |
| 747 | struct mei_cl *cl_next = NULL; |
| 748 | list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) { |
| 749 | if (host_client_id == cl_pos->host_client_id) { |
| 750 | dev_dbg(&dev->pdev->dev, "remove host client = %d, ME client = %d\n", |
| 751 | cl_pos->host_client_id, |
| 752 | cl_pos->me_client_id); |
| 753 | list_del_init(&cl_pos->link); |
| 754 | break; |
| 755 | } |
| 756 | } |
| 757 | } |