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