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