Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Intel Management Engine Interface (Intel MEI) Linux driver |
| 4 | * Copyright (c) 2003-2012, Intel Corporation. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | #include <linux/pci.h> |
| 18 | #include <linux/sched.h> |
| 19 | #include <linux/wait.h> |
| 20 | #include <linux/delay.h> |
Tomas Winkler | 04bb139 | 2014-03-18 22:52:04 +0200 | [diff] [blame] | 21 | #include <linux/pm_runtime.h> |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 22 | |
| 23 | #include <linux/mei.h> |
| 24 | |
| 25 | #include "mei_dev.h" |
| 26 | #include "hbm.h" |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 27 | #include "client.h" |
| 28 | |
| 29 | /** |
| 30 | * mei_me_cl_by_uuid - locate index of me client |
| 31 | * |
| 32 | * @dev: mei device |
Alexander Usyskin | a27a76d | 2014-02-17 15:13:22 +0200 | [diff] [blame] | 33 | * |
| 34 | * Locking: called under "dev->device_lock" lock |
| 35 | * |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 36 | * returns me client index or -ENOENT if not found |
| 37 | */ |
| 38 | int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *uuid) |
| 39 | { |
Alexander Usyskin | a27a76d | 2014-02-17 15:13:22 +0200 | [diff] [blame] | 40 | int i; |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 41 | |
| 42 | for (i = 0; i < dev->me_clients_num; ++i) |
| 43 | if (uuid_le_cmp(*uuid, |
Alexander Usyskin | a27a76d | 2014-02-17 15:13:22 +0200 | [diff] [blame] | 44 | dev->me_clients[i].props.protocol_name) == 0) |
| 45 | return i; |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 46 | |
Alexander Usyskin | a27a76d | 2014-02-17 15:13:22 +0200 | [diff] [blame] | 47 | return -ENOENT; |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | |
| 51 | /** |
| 52 | * mei_me_cl_by_id return index to me_clients for client_id |
| 53 | * |
| 54 | * @dev: the device structure |
| 55 | * @client_id: me client id |
| 56 | * |
| 57 | * Locking: called under "dev->device_lock" lock |
| 58 | * |
| 59 | * returns index on success, -ENOENT on failure. |
| 60 | */ |
| 61 | |
| 62 | int mei_me_cl_by_id(struct mei_device *dev, u8 client_id) |
| 63 | { |
| 64 | int i; |
Alexander Usyskin | a27a76d | 2014-02-17 15:13:22 +0200 | [diff] [blame] | 65 | |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 66 | for (i = 0; i < dev->me_clients_num; i++) |
| 67 | if (dev->me_clients[i].client_id == client_id) |
Alexander Usyskin | a27a76d | 2014-02-17 15:13:22 +0200 | [diff] [blame] | 68 | return i; |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 69 | |
Alexander Usyskin | a27a76d | 2014-02-17 15:13:22 +0200 | [diff] [blame] | 70 | return -ENOENT; |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 71 | } |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 72 | |
| 73 | |
| 74 | /** |
Tomas Winkler | cc99ecf | 2014-03-10 15:10:40 +0200 | [diff] [blame] | 75 | * mei_cl_cmp_id - tells if the clients are the same |
| 76 | * |
| 77 | * @cl1: host client 1 |
| 78 | * @cl2: host client 2 |
| 79 | * |
| 80 | * returns true - if the clients has same host and me ids |
| 81 | * false - otherwise |
| 82 | */ |
| 83 | static inline bool mei_cl_cmp_id(const struct mei_cl *cl1, |
| 84 | const struct mei_cl *cl2) |
| 85 | { |
| 86 | return cl1 && cl2 && |
| 87 | (cl1->host_client_id == cl2->host_client_id) && |
| 88 | (cl1->me_client_id == cl2->me_client_id); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * mei_io_list_flush - removes cbs belonging to cl. |
| 93 | * |
| 94 | * @list: an instance of our list structure |
| 95 | * @cl: host client, can be NULL for flushing the whole list |
| 96 | * @free: whether to free the cbs |
| 97 | */ |
| 98 | static void __mei_io_list_flush(struct mei_cl_cb *list, |
| 99 | struct mei_cl *cl, bool free) |
| 100 | { |
| 101 | struct mei_cl_cb *cb; |
| 102 | struct mei_cl_cb *next; |
| 103 | |
| 104 | /* enable removing everything if no cl is specified */ |
| 105 | list_for_each_entry_safe(cb, next, &list->list, list) { |
| 106 | if (!cl || (cb->cl && mei_cl_cmp_id(cl, cb->cl))) { |
| 107 | list_del(&cb->list); |
| 108 | if (free) |
| 109 | mei_io_cb_free(cb); |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | /** |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 115 | * mei_io_list_flush - removes list entry belonging to cl. |
| 116 | * |
| 117 | * @list: An instance of our list structure |
| 118 | * @cl: host client |
| 119 | */ |
Tomas Winkler | cc99ecf | 2014-03-10 15:10:40 +0200 | [diff] [blame] | 120 | static inline void mei_io_list_flush(struct mei_cl_cb *list, struct mei_cl *cl) |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 121 | { |
Tomas Winkler | cc99ecf | 2014-03-10 15:10:40 +0200 | [diff] [blame] | 122 | __mei_io_list_flush(list, cl, false); |
| 123 | } |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 124 | |
Tomas Winkler | cc99ecf | 2014-03-10 15:10:40 +0200 | [diff] [blame] | 125 | |
| 126 | /** |
| 127 | * mei_io_list_free - removes cb belonging to cl and free them |
| 128 | * |
| 129 | * @list: An instance of our list structure |
| 130 | * @cl: host client |
| 131 | */ |
| 132 | static inline void mei_io_list_free(struct mei_cl_cb *list, struct mei_cl *cl) |
| 133 | { |
| 134 | __mei_io_list_flush(list, cl, true); |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /** |
| 138 | * mei_io_cb_free - free mei_cb_private related memory |
| 139 | * |
| 140 | * @cb: mei callback struct |
| 141 | */ |
| 142 | void mei_io_cb_free(struct mei_cl_cb *cb) |
| 143 | { |
| 144 | if (cb == NULL) |
| 145 | return; |
| 146 | |
| 147 | kfree(cb->request_buffer.data); |
| 148 | kfree(cb->response_buffer.data); |
| 149 | kfree(cb); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * mei_io_cb_init - allocate and initialize io callback |
| 154 | * |
| 155 | * @cl - mei client |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 156 | * @fp: pointer to file structure |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 157 | * |
| 158 | * returns mei_cl_cb pointer or NULL; |
| 159 | */ |
| 160 | struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, struct file *fp) |
| 161 | { |
| 162 | struct mei_cl_cb *cb; |
| 163 | |
| 164 | cb = kzalloc(sizeof(struct mei_cl_cb), GFP_KERNEL); |
| 165 | if (!cb) |
| 166 | return NULL; |
| 167 | |
| 168 | mei_io_list_init(cb); |
| 169 | |
| 170 | cb->file_object = fp; |
| 171 | cb->cl = cl; |
| 172 | cb->buf_idx = 0; |
| 173 | return cb; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * mei_io_cb_alloc_req_buf - allocate request buffer |
| 178 | * |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 179 | * @cb: io callback structure |
| 180 | * @length: size of the buffer |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 181 | * |
| 182 | * returns 0 on success |
| 183 | * -EINVAL if cb is NULL |
| 184 | * -ENOMEM if allocation failed |
| 185 | */ |
| 186 | int mei_io_cb_alloc_req_buf(struct mei_cl_cb *cb, size_t length) |
| 187 | { |
| 188 | if (!cb) |
| 189 | return -EINVAL; |
| 190 | |
| 191 | if (length == 0) |
| 192 | return 0; |
| 193 | |
| 194 | cb->request_buffer.data = kmalloc(length, GFP_KERNEL); |
| 195 | if (!cb->request_buffer.data) |
| 196 | return -ENOMEM; |
| 197 | cb->request_buffer.size = length; |
| 198 | return 0; |
| 199 | } |
| 200 | /** |
Alexander Usyskin | 83ce074 | 2014-01-08 22:31:46 +0200 | [diff] [blame] | 201 | * mei_io_cb_alloc_resp_buf - allocate response buffer |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 202 | * |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 203 | * @cb: io callback structure |
| 204 | * @length: size of the buffer |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 205 | * |
| 206 | * returns 0 on success |
| 207 | * -EINVAL if cb is NULL |
| 208 | * -ENOMEM if allocation failed |
| 209 | */ |
| 210 | int mei_io_cb_alloc_resp_buf(struct mei_cl_cb *cb, size_t length) |
| 211 | { |
| 212 | if (!cb) |
| 213 | return -EINVAL; |
| 214 | |
| 215 | if (length == 0) |
| 216 | return 0; |
| 217 | |
| 218 | cb->response_buffer.data = kmalloc(length, GFP_KERNEL); |
| 219 | if (!cb->response_buffer.data) |
| 220 | return -ENOMEM; |
| 221 | cb->response_buffer.size = length; |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | |
| 226 | |
| 227 | /** |
| 228 | * mei_cl_flush_queues - flushes queue lists belonging to cl. |
| 229 | * |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 230 | * @cl: host client |
| 231 | */ |
| 232 | int mei_cl_flush_queues(struct mei_cl *cl) |
| 233 | { |
Alexander Usyskin | c0abffb | 2013-09-15 18:11:07 +0300 | [diff] [blame] | 234 | struct mei_device *dev; |
| 235 | |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 236 | if (WARN_ON(!cl || !cl->dev)) |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 237 | return -EINVAL; |
| 238 | |
Alexander Usyskin | c0abffb | 2013-09-15 18:11:07 +0300 | [diff] [blame] | 239 | dev = cl->dev; |
| 240 | |
| 241 | cl_dbg(dev, cl, "remove list entry belonging to cl\n"); |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 242 | mei_io_list_flush(&cl->dev->read_list, cl); |
Tomas Winkler | cc99ecf | 2014-03-10 15:10:40 +0200 | [diff] [blame] | 243 | mei_io_list_free(&cl->dev->write_list, cl); |
| 244 | mei_io_list_free(&cl->dev->write_waiting_list, cl); |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 245 | mei_io_list_flush(&cl->dev->ctrl_wr_list, cl); |
| 246 | mei_io_list_flush(&cl->dev->ctrl_rd_list, cl); |
| 247 | mei_io_list_flush(&cl->dev->amthif_cmd_list, cl); |
| 248 | mei_io_list_flush(&cl->dev->amthif_rd_complete_list, cl); |
| 249 | return 0; |
| 250 | } |
| 251 | |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 252 | |
| 253 | /** |
Alexander Usyskin | 83ce074 | 2014-01-08 22:31:46 +0200 | [diff] [blame] | 254 | * mei_cl_init - initializes cl. |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 255 | * |
| 256 | * @cl: host client to be initialized |
| 257 | * @dev: mei device |
| 258 | */ |
| 259 | void mei_cl_init(struct mei_cl *cl, struct mei_device *dev) |
| 260 | { |
| 261 | memset(cl, 0, sizeof(struct mei_cl)); |
| 262 | init_waitqueue_head(&cl->wait); |
| 263 | init_waitqueue_head(&cl->rx_wait); |
| 264 | init_waitqueue_head(&cl->tx_wait); |
| 265 | INIT_LIST_HEAD(&cl->link); |
Samuel Ortiz | a7b71bc | 2013-03-27 17:29:56 +0200 | [diff] [blame] | 266 | INIT_LIST_HEAD(&cl->device_link); |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 267 | cl->reading_state = MEI_IDLE; |
| 268 | cl->writing_state = MEI_IDLE; |
| 269 | cl->dev = dev; |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * mei_cl_allocate - allocates cl structure and sets it up. |
| 274 | * |
| 275 | * @dev: mei device |
| 276 | * returns The allocated file or NULL on failure |
| 277 | */ |
| 278 | struct mei_cl *mei_cl_allocate(struct mei_device *dev) |
| 279 | { |
| 280 | struct mei_cl *cl; |
| 281 | |
| 282 | cl = kmalloc(sizeof(struct mei_cl), GFP_KERNEL); |
| 283 | if (!cl) |
| 284 | return NULL; |
| 285 | |
| 286 | mei_cl_init(cl, dev); |
| 287 | |
| 288 | return cl; |
| 289 | } |
| 290 | |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 291 | /** |
| 292 | * mei_cl_find_read_cb - find this cl's callback in the read list |
| 293 | * |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 294 | * @cl: host client |
| 295 | * |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 296 | * returns cb on success, NULL on error |
| 297 | */ |
| 298 | struct mei_cl_cb *mei_cl_find_read_cb(struct mei_cl *cl) |
| 299 | { |
| 300 | struct mei_device *dev = cl->dev; |
Tomas Winkler | 31f88f5 | 2014-02-17 15:13:25 +0200 | [diff] [blame] | 301 | struct mei_cl_cb *cb; |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 302 | |
Tomas Winkler | 31f88f5 | 2014-02-17 15:13:25 +0200 | [diff] [blame] | 303 | list_for_each_entry(cb, &dev->read_list.list, list) |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 304 | if (mei_cl_cmp_id(cl, cb->cl)) |
| 305 | return cb; |
| 306 | return NULL; |
| 307 | } |
| 308 | |
Alexander Usyskin | 83ce074 | 2014-01-08 22:31:46 +0200 | [diff] [blame] | 309 | /** mei_cl_link: allocate host id in the host map |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 310 | * |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 311 | * @cl - host client |
Alexander Usyskin | 83ce074 | 2014-01-08 22:31:46 +0200 | [diff] [blame] | 312 | * @id - fixed host id or -1 for generic one |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 313 | * |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 314 | * returns 0 on success |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 315 | * -EINVAL on incorrect values |
| 316 | * -ENONET if client not found |
| 317 | */ |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 318 | int mei_cl_link(struct mei_cl *cl, int id) |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 319 | { |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 320 | struct mei_device *dev; |
Tomas Winkler | 22f96a0 | 2013-09-16 23:44:47 +0300 | [diff] [blame] | 321 | long open_handle_count; |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 322 | |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 323 | if (WARN_ON(!cl || !cl->dev)) |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 324 | return -EINVAL; |
| 325 | |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 326 | dev = cl->dev; |
| 327 | |
Alexander Usyskin | 83ce074 | 2014-01-08 22:31:46 +0200 | [diff] [blame] | 328 | /* If Id is not assigned get one*/ |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 329 | if (id == MEI_HOST_CLIENT_ID_ANY) |
| 330 | id = find_first_zero_bit(dev->host_clients_map, |
| 331 | MEI_CLIENTS_MAX); |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 332 | |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 333 | if (id >= MEI_CLIENTS_MAX) { |
Alexander Usyskin | 83ce074 | 2014-01-08 22:31:46 +0200 | [diff] [blame] | 334 | dev_err(&dev->pdev->dev, "id exceeded %d", MEI_CLIENTS_MAX); |
Tomas Winkler | e036cc5 | 2013-09-16 23:44:46 +0300 | [diff] [blame] | 335 | return -EMFILE; |
| 336 | } |
| 337 | |
Tomas Winkler | 22f96a0 | 2013-09-16 23:44:47 +0300 | [diff] [blame] | 338 | open_handle_count = dev->open_handle_count + dev->iamthif_open_count; |
| 339 | if (open_handle_count >= MEI_MAX_OPEN_HANDLE_COUNT) { |
Alexander Usyskin | 83ce074 | 2014-01-08 22:31:46 +0200 | [diff] [blame] | 340 | dev_err(&dev->pdev->dev, "open_handle_count exceeded %d", |
Tomas Winkler | e036cc5 | 2013-09-16 23:44:46 +0300 | [diff] [blame] | 341 | MEI_MAX_OPEN_HANDLE_COUNT); |
| 342 | return -EMFILE; |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 343 | } |
| 344 | |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 345 | dev->open_handle_count++; |
| 346 | |
| 347 | cl->host_client_id = id; |
| 348 | list_add_tail(&cl->link, &dev->file_list); |
| 349 | |
| 350 | set_bit(id, dev->host_clients_map); |
| 351 | |
| 352 | cl->state = MEI_FILE_INITIALIZING; |
| 353 | |
Alexander Usyskin | c0abffb | 2013-09-15 18:11:07 +0300 | [diff] [blame] | 354 | cl_dbg(dev, cl, "link cl\n"); |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 355 | return 0; |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 356 | } |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 357 | |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 358 | /** |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 359 | * mei_cl_unlink - remove me_cl from the list |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 360 | * |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 361 | * @cl: host client |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 362 | */ |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 363 | int mei_cl_unlink(struct mei_cl *cl) |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 364 | { |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 365 | struct mei_device *dev; |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 366 | |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 367 | /* don't shout on error exit path */ |
| 368 | if (!cl) |
| 369 | return 0; |
| 370 | |
Tomas Winkler | 8e9a4a9 | 2013-01-10 17:32:14 +0200 | [diff] [blame] | 371 | /* wd and amthif might not be initialized */ |
| 372 | if (!cl->dev) |
| 373 | return 0; |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 374 | |
| 375 | dev = cl->dev; |
| 376 | |
Tomas Winkler | a14c44d | 2013-09-16 23:44:45 +0300 | [diff] [blame] | 377 | cl_dbg(dev, cl, "unlink client"); |
| 378 | |
Tomas Winkler | 22f96a0 | 2013-09-16 23:44:47 +0300 | [diff] [blame] | 379 | if (dev->open_handle_count > 0) |
| 380 | dev->open_handle_count--; |
| 381 | |
| 382 | /* never clear the 0 bit */ |
| 383 | if (cl->host_client_id) |
| 384 | clear_bit(cl->host_client_id, dev->host_clients_map); |
| 385 | |
| 386 | list_del_init(&cl->link); |
| 387 | |
| 388 | cl->state = MEI_FILE_INITIALIZING; |
| 389 | |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 390 | return 0; |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | |
| 394 | void mei_host_client_init(struct work_struct *work) |
| 395 | { |
| 396 | struct mei_device *dev = container_of(work, |
| 397 | struct mei_device, init_work); |
| 398 | struct mei_client_properties *client_props; |
| 399 | int i; |
| 400 | |
| 401 | mutex_lock(&dev->device_lock); |
| 402 | |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 403 | for (i = 0; i < dev->me_clients_num; i++) { |
| 404 | client_props = &dev->me_clients[i].props; |
| 405 | |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 406 | if (!uuid_le_cmp(client_props->protocol_name, mei_amthif_guid)) |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 407 | mei_amthif_host_init(dev); |
| 408 | else if (!uuid_le_cmp(client_props->protocol_name, mei_wd_guid)) |
| 409 | mei_wd_host_init(dev); |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 410 | else if (!uuid_le_cmp(client_props->protocol_name, mei_nfc_guid)) |
| 411 | mei_nfc_host_init(dev); |
| 412 | |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | dev->dev_state = MEI_DEV_ENABLED; |
Tomas Winkler | 6adb8ef | 2014-01-12 00:36:10 +0200 | [diff] [blame] | 416 | dev->reset_count = 0; |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 417 | |
| 418 | mutex_unlock(&dev->device_lock); |
Tomas Winkler | 04bb139 | 2014-03-18 22:52:04 +0200 | [diff] [blame] | 419 | |
| 420 | pm_runtime_mark_last_busy(&dev->pdev->dev); |
| 421 | dev_dbg(&dev->pdev->dev, "rpm: autosuspend\n"); |
| 422 | pm_runtime_autosuspend(&dev->pdev->dev); |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 423 | } |
| 424 | |
Tomas Winkler | 6aae48f | 2014-02-19 17:35:47 +0200 | [diff] [blame] | 425 | /** |
| 426 | * mei_hbuf_acquire: try to acquire host buffer |
| 427 | * |
| 428 | * @dev: the device structure |
| 429 | * returns true if host buffer was acquired |
| 430 | */ |
| 431 | bool mei_hbuf_acquire(struct mei_device *dev) |
| 432 | { |
Tomas Winkler | 04bb139 | 2014-03-18 22:52:04 +0200 | [diff] [blame] | 433 | if (mei_pg_state(dev) == MEI_PG_ON || |
| 434 | dev->pg_event == MEI_PG_EVENT_WAIT) { |
| 435 | dev_dbg(&dev->pdev->dev, "device is in pg\n"); |
| 436 | return false; |
| 437 | } |
| 438 | |
Tomas Winkler | 6aae48f | 2014-02-19 17:35:47 +0200 | [diff] [blame] | 439 | if (!dev->hbuf_is_ready) { |
| 440 | dev_dbg(&dev->pdev->dev, "hbuf is not ready\n"); |
| 441 | return false; |
| 442 | } |
| 443 | |
| 444 | dev->hbuf_is_ready = false; |
| 445 | |
| 446 | return true; |
| 447 | } |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 448 | |
| 449 | /** |
Alexander Usyskin | 83ce074 | 2014-01-08 22:31:46 +0200 | [diff] [blame] | 450 | * mei_cl_disconnect - disconnect host client from the me one |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 451 | * |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 452 | * @cl: host client |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 453 | * |
| 454 | * Locking: called under "dev->device_lock" lock |
| 455 | * |
| 456 | * returns 0 on success, <0 on failure. |
| 457 | */ |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 458 | int mei_cl_disconnect(struct mei_cl *cl) |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 459 | { |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 460 | struct mei_device *dev; |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 461 | struct mei_cl_cb *cb; |
| 462 | int rets, err; |
| 463 | |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 464 | if (WARN_ON(!cl || !cl->dev)) |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 465 | return -ENODEV; |
| 466 | |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 467 | dev = cl->dev; |
| 468 | |
Alexander Usyskin | c0abffb | 2013-09-15 18:11:07 +0300 | [diff] [blame] | 469 | cl_dbg(dev, cl, "disconnecting"); |
| 470 | |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 471 | if (cl->state != MEI_FILE_DISCONNECTING) |
| 472 | return 0; |
| 473 | |
Tomas Winkler | 04bb139 | 2014-03-18 22:52:04 +0200 | [diff] [blame] | 474 | rets = pm_runtime_get(&dev->pdev->dev); |
| 475 | if (rets < 0 && rets != -EINPROGRESS) { |
| 476 | pm_runtime_put_noidle(&dev->pdev->dev); |
| 477 | cl_err(dev, cl, "rpm: get failed %d\n", rets); |
| 478 | return rets; |
| 479 | } |
| 480 | |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 481 | cb = mei_io_cb_init(cl, NULL); |
Tomas Winkler | 04bb139 | 2014-03-18 22:52:04 +0200 | [diff] [blame] | 482 | if (!cb) { |
| 483 | rets = -ENOMEM; |
| 484 | goto free; |
| 485 | } |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 486 | |
| 487 | cb->fop_type = MEI_FOP_CLOSE; |
Tomas Winkler | 6aae48f | 2014-02-19 17:35:47 +0200 | [diff] [blame] | 488 | if (mei_hbuf_acquire(dev)) { |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 489 | if (mei_hbm_cl_disconnect_req(dev, cl)) { |
| 490 | rets = -ENODEV; |
Alexander Usyskin | c0abffb | 2013-09-15 18:11:07 +0300 | [diff] [blame] | 491 | cl_err(dev, cl, "failed to disconnect.\n"); |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 492 | goto free; |
| 493 | } |
| 494 | mdelay(10); /* Wait for hardware disconnection ready */ |
| 495 | list_add_tail(&cb->list, &dev->ctrl_rd_list.list); |
| 496 | } else { |
Alexander Usyskin | c0abffb | 2013-09-15 18:11:07 +0300 | [diff] [blame] | 497 | cl_dbg(dev, cl, "add disconnect cb to control write list\n"); |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 498 | list_add_tail(&cb->list, &dev->ctrl_wr_list.list); |
| 499 | |
| 500 | } |
| 501 | mutex_unlock(&dev->device_lock); |
| 502 | |
| 503 | err = wait_event_timeout(dev->wait_recvd_msg, |
| 504 | MEI_FILE_DISCONNECTED == cl->state, |
| 505 | mei_secs_to_jiffies(MEI_CL_CONNECT_TIMEOUT)); |
| 506 | |
| 507 | mutex_lock(&dev->device_lock); |
| 508 | if (MEI_FILE_DISCONNECTED == cl->state) { |
| 509 | rets = 0; |
Alexander Usyskin | c0abffb | 2013-09-15 18:11:07 +0300 | [diff] [blame] | 510 | cl_dbg(dev, cl, "successfully disconnected from FW client.\n"); |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 511 | } else { |
| 512 | rets = -ENODEV; |
| 513 | if (MEI_FILE_DISCONNECTED != cl->state) |
Alexander Usyskin | c0abffb | 2013-09-15 18:11:07 +0300 | [diff] [blame] | 514 | cl_err(dev, cl, "wrong status client disconnect.\n"); |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 515 | |
| 516 | if (err) |
Tomas Winkler | 04bb139 | 2014-03-18 22:52:04 +0200 | [diff] [blame] | 517 | cl_dbg(dev, cl, "wait failed disconnect err=%d\n", err); |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 518 | |
Alexander Usyskin | c0abffb | 2013-09-15 18:11:07 +0300 | [diff] [blame] | 519 | cl_err(dev, cl, "failed to disconnect from FW client.\n"); |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | mei_io_list_flush(&dev->ctrl_rd_list, cl); |
| 523 | mei_io_list_flush(&dev->ctrl_wr_list, cl); |
| 524 | free: |
Tomas Winkler | 04bb139 | 2014-03-18 22:52:04 +0200 | [diff] [blame] | 525 | cl_dbg(dev, cl, "rpm: autosuspend\n"); |
| 526 | pm_runtime_mark_last_busy(&dev->pdev->dev); |
| 527 | pm_runtime_put_autosuspend(&dev->pdev->dev); |
| 528 | |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 529 | mei_io_cb_free(cb); |
| 530 | return rets; |
| 531 | } |
| 532 | |
| 533 | |
| 534 | /** |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 535 | * mei_cl_is_other_connecting - checks if other |
| 536 | * client with the same me client id is connecting |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 537 | * |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 538 | * @cl: private data of the file object |
| 539 | * |
Alexander Usyskin | 83ce074 | 2014-01-08 22:31:46 +0200 | [diff] [blame] | 540 | * returns true if other client is connected, false - otherwise. |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 541 | */ |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 542 | bool mei_cl_is_other_connecting(struct mei_cl *cl) |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 543 | { |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 544 | struct mei_device *dev; |
Tomas Winkler | 31f88f5 | 2014-02-17 15:13:25 +0200 | [diff] [blame] | 545 | struct mei_cl *ocl; /* the other client */ |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 546 | |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 547 | if (WARN_ON(!cl || !cl->dev)) |
| 548 | return false; |
| 549 | |
| 550 | dev = cl->dev; |
| 551 | |
Tomas Winkler | 31f88f5 | 2014-02-17 15:13:25 +0200 | [diff] [blame] | 552 | list_for_each_entry(ocl, &dev->file_list, link) { |
| 553 | if (ocl->state == MEI_FILE_CONNECTING && |
| 554 | ocl != cl && |
| 555 | cl->me_client_id == ocl->me_client_id) |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 556 | return true; |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 557 | |
| 558 | } |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 559 | |
| 560 | return false; |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | /** |
Alexander Usyskin | 83ce074 | 2014-01-08 22:31:46 +0200 | [diff] [blame] | 564 | * mei_cl_connect - connect host client to the me one |
Tomas Winkler | 9f81abda | 2013-01-08 23:07:15 +0200 | [diff] [blame] | 565 | * |
| 566 | * @cl: host client |
| 567 | * |
| 568 | * Locking: called under "dev->device_lock" lock |
| 569 | * |
| 570 | * returns 0 on success, <0 on failure. |
| 571 | */ |
| 572 | int mei_cl_connect(struct mei_cl *cl, struct file *file) |
| 573 | { |
| 574 | struct mei_device *dev; |
| 575 | struct mei_cl_cb *cb; |
Tomas Winkler | 9f81abda | 2013-01-08 23:07:15 +0200 | [diff] [blame] | 576 | int rets; |
| 577 | |
| 578 | if (WARN_ON(!cl || !cl->dev)) |
| 579 | return -ENODEV; |
| 580 | |
| 581 | dev = cl->dev; |
| 582 | |
Tomas Winkler | 04bb139 | 2014-03-18 22:52:04 +0200 | [diff] [blame] | 583 | rets = pm_runtime_get(&dev->pdev->dev); |
| 584 | if (rets < 0 && rets != -EINPROGRESS) { |
| 585 | pm_runtime_put_noidle(&dev->pdev->dev); |
| 586 | cl_err(dev, cl, "rpm: get failed %d\n", rets); |
| 587 | return rets; |
| 588 | } |
| 589 | |
Tomas Winkler | 9f81abda | 2013-01-08 23:07:15 +0200 | [diff] [blame] | 590 | cb = mei_io_cb_init(cl, file); |
| 591 | if (!cb) { |
| 592 | rets = -ENOMEM; |
| 593 | goto out; |
| 594 | } |
| 595 | |
Tomas Winkler | 02a7eec | 2014-02-12 21:41:51 +0200 | [diff] [blame] | 596 | cb->fop_type = MEI_FOP_CONNECT; |
Tomas Winkler | 9f81abda | 2013-01-08 23:07:15 +0200 | [diff] [blame] | 597 | |
Tomas Winkler | 6aae48f | 2014-02-19 17:35:47 +0200 | [diff] [blame] | 598 | /* run hbuf acquire last so we don't have to undo */ |
| 599 | if (!mei_cl_is_other_connecting(cl) && mei_hbuf_acquire(dev)) { |
Alexander Usyskin | e4d8270 | 2014-04-27 15:42:21 +0300 | [diff] [blame^] | 600 | cl->state = MEI_FILE_CONNECTING; |
Tomas Winkler | 9f81abda | 2013-01-08 23:07:15 +0200 | [diff] [blame] | 601 | if (mei_hbm_cl_connect_req(dev, cl)) { |
| 602 | rets = -ENODEV; |
| 603 | goto out; |
| 604 | } |
| 605 | cl->timer_count = MEI_CONNECT_TIMEOUT; |
| 606 | list_add_tail(&cb->list, &dev->ctrl_rd_list.list); |
| 607 | } else { |
| 608 | list_add_tail(&cb->list, &dev->ctrl_wr_list.list); |
| 609 | } |
| 610 | |
| 611 | mutex_unlock(&dev->device_lock); |
Alexander Usyskin | 285e299 | 2014-02-17 15:13:20 +0200 | [diff] [blame] | 612 | wait_event_timeout(dev->wait_recvd_msg, |
| 613 | (cl->state == MEI_FILE_CONNECTED || |
| 614 | cl->state == MEI_FILE_DISCONNECTED), |
| 615 | mei_secs_to_jiffies(MEI_CL_CONNECT_TIMEOUT)); |
Tomas Winkler | 9f81abda | 2013-01-08 23:07:15 +0200 | [diff] [blame] | 616 | mutex_lock(&dev->device_lock); |
| 617 | |
| 618 | if (cl->state != MEI_FILE_CONNECTED) { |
Alexander Usyskin | 285e299 | 2014-02-17 15:13:20 +0200 | [diff] [blame] | 619 | /* something went really wrong */ |
| 620 | if (!cl->status) |
| 621 | cl->status = -EFAULT; |
Tomas Winkler | 9f81abda | 2013-01-08 23:07:15 +0200 | [diff] [blame] | 622 | |
| 623 | mei_io_list_flush(&dev->ctrl_rd_list, cl); |
| 624 | mei_io_list_flush(&dev->ctrl_wr_list, cl); |
Tomas Winkler | 9f81abda | 2013-01-08 23:07:15 +0200 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | rets = cl->status; |
| 628 | |
| 629 | out: |
Tomas Winkler | 04bb139 | 2014-03-18 22:52:04 +0200 | [diff] [blame] | 630 | cl_dbg(dev, cl, "rpm: autosuspend\n"); |
| 631 | pm_runtime_mark_last_busy(&dev->pdev->dev); |
| 632 | pm_runtime_put_autosuspend(&dev->pdev->dev); |
| 633 | |
Tomas Winkler | 9f81abda | 2013-01-08 23:07:15 +0200 | [diff] [blame] | 634 | mei_io_cb_free(cb); |
| 635 | return rets; |
| 636 | } |
| 637 | |
| 638 | /** |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 639 | * mei_cl_flow_ctrl_creds - checks flow_control credits for cl. |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 640 | * |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 641 | * @cl: private data of the file object |
| 642 | * |
| 643 | * returns 1 if mei_flow_ctrl_creds >0, 0 - otherwise. |
| 644 | * -ENOENT if mei_cl is not present |
| 645 | * -EINVAL if single_recv_buf == 0 |
| 646 | */ |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 647 | int mei_cl_flow_ctrl_creds(struct mei_cl *cl) |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 648 | { |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 649 | struct mei_device *dev; |
Alexander Usyskin | 12d0066 | 2014-02-17 15:13:23 +0200 | [diff] [blame] | 650 | struct mei_me_client *me_cl; |
| 651 | int id; |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 652 | |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 653 | if (WARN_ON(!cl || !cl->dev)) |
| 654 | return -EINVAL; |
| 655 | |
| 656 | dev = cl->dev; |
| 657 | |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 658 | if (!dev->me_clients_num) |
| 659 | return 0; |
| 660 | |
| 661 | if (cl->mei_flow_ctrl_creds > 0) |
| 662 | return 1; |
| 663 | |
Alexander Usyskin | 12d0066 | 2014-02-17 15:13:23 +0200 | [diff] [blame] | 664 | id = mei_me_cl_by_id(dev, cl->me_client_id); |
| 665 | if (id < 0) { |
| 666 | cl_err(dev, cl, "no such me client %d\n", cl->me_client_id); |
| 667 | return id; |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 668 | } |
Alexander Usyskin | 12d0066 | 2014-02-17 15:13:23 +0200 | [diff] [blame] | 669 | |
| 670 | me_cl = &dev->me_clients[id]; |
| 671 | if (me_cl->mei_flow_ctrl_creds) { |
| 672 | if (WARN_ON(me_cl->props.single_recv_buf == 0)) |
| 673 | return -EINVAL; |
| 674 | return 1; |
| 675 | } |
| 676 | return 0; |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | /** |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 680 | * mei_cl_flow_ctrl_reduce - reduces flow_control. |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 681 | * |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 682 | * @cl: private data of the file object |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 683 | * |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 684 | * @returns |
| 685 | * 0 on success |
| 686 | * -ENOENT when me client is not found |
| 687 | * -EINVAL when ctrl credits are <= 0 |
| 688 | */ |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 689 | int mei_cl_flow_ctrl_reduce(struct mei_cl *cl) |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 690 | { |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 691 | struct mei_device *dev; |
Alexander Usyskin | 12d0066 | 2014-02-17 15:13:23 +0200 | [diff] [blame] | 692 | struct mei_me_client *me_cl; |
| 693 | int id; |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 694 | |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 695 | if (WARN_ON(!cl || !cl->dev)) |
| 696 | return -EINVAL; |
| 697 | |
| 698 | dev = cl->dev; |
| 699 | |
Alexander Usyskin | 12d0066 | 2014-02-17 15:13:23 +0200 | [diff] [blame] | 700 | id = mei_me_cl_by_id(dev, cl->me_client_id); |
| 701 | if (id < 0) { |
| 702 | cl_err(dev, cl, "no such me client %d\n", cl->me_client_id); |
| 703 | return id; |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 704 | } |
Alexander Usyskin | 12d0066 | 2014-02-17 15:13:23 +0200 | [diff] [blame] | 705 | |
| 706 | me_cl = &dev->me_clients[id]; |
| 707 | if (me_cl->props.single_recv_buf != 0) { |
| 708 | if (WARN_ON(me_cl->mei_flow_ctrl_creds <= 0)) |
| 709 | return -EINVAL; |
| 710 | me_cl->mei_flow_ctrl_creds--; |
| 711 | } else { |
| 712 | if (WARN_ON(cl->mei_flow_ctrl_creds <= 0)) |
| 713 | return -EINVAL; |
| 714 | cl->mei_flow_ctrl_creds--; |
| 715 | } |
| 716 | return 0; |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 717 | } |
| 718 | |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 719 | /** |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 720 | * mei_cl_read_start - the start read client message function. |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 721 | * |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 722 | * @cl: host client |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 723 | * |
| 724 | * returns 0 on success, <0 on failure. |
| 725 | */ |
Tomas Winkler | fcb136e | 2013-04-19 22:01:35 +0300 | [diff] [blame] | 726 | int mei_cl_read_start(struct mei_cl *cl, size_t length) |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 727 | { |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 728 | struct mei_device *dev; |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 729 | struct mei_cl_cb *cb; |
| 730 | int rets; |
| 731 | int i; |
| 732 | |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 733 | if (WARN_ON(!cl || !cl->dev)) |
| 734 | return -ENODEV; |
| 735 | |
| 736 | dev = cl->dev; |
| 737 | |
Tomas Winkler | b950ac1 | 2013-07-25 20:15:53 +0300 | [diff] [blame] | 738 | if (!mei_cl_is_connected(cl)) |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 739 | return -ENODEV; |
| 740 | |
Tomas Winkler | d91aaed | 2013-01-08 23:07:18 +0200 | [diff] [blame] | 741 | if (cl->read_cb) { |
Alexander Usyskin | c0abffb | 2013-09-15 18:11:07 +0300 | [diff] [blame] | 742 | cl_dbg(dev, cl, "read is pending.\n"); |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 743 | return -EBUSY; |
| 744 | } |
| 745 | i = mei_me_cl_by_id(dev, cl->me_client_id); |
| 746 | if (i < 0) { |
Alexander Usyskin | c0abffb | 2013-09-15 18:11:07 +0300 | [diff] [blame] | 747 | cl_err(dev, cl, "no such me client %d\n", cl->me_client_id); |
Alexander Usyskin | 7ca96aa | 2014-02-19 17:35:49 +0200 | [diff] [blame] | 748 | return -ENOTTY; |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 749 | } |
| 750 | |
Tomas Winkler | 04bb139 | 2014-03-18 22:52:04 +0200 | [diff] [blame] | 751 | rets = pm_runtime_get(&dev->pdev->dev); |
| 752 | if (rets < 0 && rets != -EINPROGRESS) { |
| 753 | pm_runtime_put_noidle(&dev->pdev->dev); |
| 754 | cl_err(dev, cl, "rpm: get failed %d\n", rets); |
| 755 | return rets; |
| 756 | } |
| 757 | |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 758 | cb = mei_io_cb_init(cl, NULL); |
Tomas Winkler | 04bb139 | 2014-03-18 22:52:04 +0200 | [diff] [blame] | 759 | if (!cb) { |
| 760 | rets = -ENOMEM; |
| 761 | goto out; |
| 762 | } |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 763 | |
Tomas Winkler | fcb136e | 2013-04-19 22:01:35 +0300 | [diff] [blame] | 764 | /* always allocate at least client max message */ |
| 765 | length = max_t(size_t, length, dev->me_clients[i].props.max_msg_length); |
| 766 | rets = mei_io_cb_alloc_resp_buf(cb, length); |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 767 | if (rets) |
Tomas Winkler | 04bb139 | 2014-03-18 22:52:04 +0200 | [diff] [blame] | 768 | goto out; |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 769 | |
| 770 | cb->fop_type = MEI_FOP_READ; |
Tomas Winkler | 6aae48f | 2014-02-19 17:35:47 +0200 | [diff] [blame] | 771 | if (mei_hbuf_acquire(dev)) { |
Alexander Usyskin | 8611350 | 2014-03-31 17:59:24 +0300 | [diff] [blame] | 772 | rets = mei_hbm_cl_flow_control_req(dev, cl); |
| 773 | if (rets < 0) |
Tomas Winkler | 04bb139 | 2014-03-18 22:52:04 +0200 | [diff] [blame] | 774 | goto out; |
Tomas Winkler | 04bb139 | 2014-03-18 22:52:04 +0200 | [diff] [blame] | 775 | |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 776 | list_add_tail(&cb->list, &dev->read_list.list); |
| 777 | } else { |
| 778 | list_add_tail(&cb->list, &dev->ctrl_wr_list.list); |
| 779 | } |
Chao Bi | accb884 | 2014-02-12 21:27:25 +0200 | [diff] [blame] | 780 | |
| 781 | cl->read_cb = cb; |
| 782 | |
Tomas Winkler | 04bb139 | 2014-03-18 22:52:04 +0200 | [diff] [blame] | 783 | out: |
| 784 | cl_dbg(dev, cl, "rpm: autosuspend\n"); |
| 785 | pm_runtime_mark_last_busy(&dev->pdev->dev); |
| 786 | pm_runtime_put_autosuspend(&dev->pdev->dev); |
| 787 | |
| 788 | if (rets) |
| 789 | mei_io_cb_free(cb); |
| 790 | |
Tomas Winkler | 9ca9050 | 2013-01-08 23:07:13 +0200 | [diff] [blame] | 791 | return rets; |
| 792 | } |
| 793 | |
Tomas Winkler | 074b4c0 | 2013-02-06 14:06:44 +0200 | [diff] [blame] | 794 | /** |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 795 | * mei_cl_irq_write - write a message to device |
Tomas Winkler | 2176754 | 2013-06-23 09:36:59 +0300 | [diff] [blame] | 796 | * from the interrupt thread context |
| 797 | * |
| 798 | * @cl: client |
| 799 | * @cb: callback block. |
Tomas Winkler | 2176754 | 2013-06-23 09:36:59 +0300 | [diff] [blame] | 800 | * @cmpl_list: complete list. |
| 801 | * |
| 802 | * returns 0, OK; otherwise error. |
| 803 | */ |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 804 | int mei_cl_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb, |
| 805 | struct mei_cl_cb *cmpl_list) |
Tomas Winkler | 2176754 | 2013-06-23 09:36:59 +0300 | [diff] [blame] | 806 | { |
Tomas Winkler | 136698e | 2013-09-16 23:44:44 +0300 | [diff] [blame] | 807 | struct mei_device *dev; |
| 808 | struct mei_msg_data *buf; |
Tomas Winkler | 2176754 | 2013-06-23 09:36:59 +0300 | [diff] [blame] | 809 | struct mei_msg_hdr mei_hdr; |
Tomas Winkler | 136698e | 2013-09-16 23:44:44 +0300 | [diff] [blame] | 810 | size_t len; |
| 811 | u32 msg_slots; |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 812 | int slots; |
Tomas Winkler | 2ebf8c9 | 2013-09-16 23:44:43 +0300 | [diff] [blame] | 813 | int rets; |
Tomas Winkler | 2176754 | 2013-06-23 09:36:59 +0300 | [diff] [blame] | 814 | |
Tomas Winkler | 136698e | 2013-09-16 23:44:44 +0300 | [diff] [blame] | 815 | if (WARN_ON(!cl || !cl->dev)) |
| 816 | return -ENODEV; |
| 817 | |
| 818 | dev = cl->dev; |
| 819 | |
| 820 | buf = &cb->request_buffer; |
| 821 | |
| 822 | rets = mei_cl_flow_ctrl_creds(cl); |
| 823 | if (rets < 0) |
| 824 | return rets; |
| 825 | |
| 826 | if (rets == 0) { |
Tomas Winkler | 04bb139 | 2014-03-18 22:52:04 +0200 | [diff] [blame] | 827 | cl_dbg(dev, cl, "No flow control credentials: not sending.\n"); |
Tomas Winkler | 136698e | 2013-09-16 23:44:44 +0300 | [diff] [blame] | 828 | return 0; |
| 829 | } |
| 830 | |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 831 | slots = mei_hbuf_empty_slots(dev); |
Tomas Winkler | 136698e | 2013-09-16 23:44:44 +0300 | [diff] [blame] | 832 | len = buf->size - cb->buf_idx; |
| 833 | msg_slots = mei_data2slots(len); |
| 834 | |
Tomas Winkler | 2176754 | 2013-06-23 09:36:59 +0300 | [diff] [blame] | 835 | mei_hdr.host_addr = cl->host_client_id; |
| 836 | mei_hdr.me_addr = cl->me_client_id; |
| 837 | mei_hdr.reserved = 0; |
Tomas Winkler | 479327f | 2013-12-17 15:56:56 +0200 | [diff] [blame] | 838 | mei_hdr.internal = cb->internal; |
Tomas Winkler | 2176754 | 2013-06-23 09:36:59 +0300 | [diff] [blame] | 839 | |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 840 | if (slots >= msg_slots) { |
Tomas Winkler | 2176754 | 2013-06-23 09:36:59 +0300 | [diff] [blame] | 841 | mei_hdr.length = len; |
| 842 | mei_hdr.msg_complete = 1; |
| 843 | /* Split the message only if we can write the whole host buffer */ |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 844 | } else if (slots == dev->hbuf_depth) { |
| 845 | msg_slots = slots; |
| 846 | len = (slots * sizeof(u32)) - sizeof(struct mei_msg_hdr); |
Tomas Winkler | 2176754 | 2013-06-23 09:36:59 +0300 | [diff] [blame] | 847 | mei_hdr.length = len; |
| 848 | mei_hdr.msg_complete = 0; |
| 849 | } else { |
| 850 | /* wait for next time the host buffer is empty */ |
| 851 | return 0; |
| 852 | } |
| 853 | |
Alexander Usyskin | c0abffb | 2013-09-15 18:11:07 +0300 | [diff] [blame] | 854 | cl_dbg(dev, cl, "buf: size = %d idx = %lu\n", |
Tomas Winkler | 2176754 | 2013-06-23 09:36:59 +0300 | [diff] [blame] | 855 | cb->request_buffer.size, cb->buf_idx); |
Tomas Winkler | 2176754 | 2013-06-23 09:36:59 +0300 | [diff] [blame] | 856 | |
Tomas Winkler | 136698e | 2013-09-16 23:44:44 +0300 | [diff] [blame] | 857 | rets = mei_write_message(dev, &mei_hdr, buf->data + cb->buf_idx); |
Tomas Winkler | 2ebf8c9 | 2013-09-16 23:44:43 +0300 | [diff] [blame] | 858 | if (rets) { |
| 859 | cl->status = rets; |
Tomas Winkler | 2176754 | 2013-06-23 09:36:59 +0300 | [diff] [blame] | 860 | list_move_tail(&cb->list, &cmpl_list->list); |
Tomas Winkler | 2ebf8c9 | 2013-09-16 23:44:43 +0300 | [diff] [blame] | 861 | return rets; |
Tomas Winkler | 2176754 | 2013-06-23 09:36:59 +0300 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | cl->status = 0; |
Tomas Winkler | 4dfaa9f | 2013-06-23 09:37:00 +0300 | [diff] [blame] | 865 | cl->writing_state = MEI_WRITING; |
Tomas Winkler | 2176754 | 2013-06-23 09:36:59 +0300 | [diff] [blame] | 866 | cb->buf_idx += mei_hdr.length; |
Tomas Winkler | 4dfaa9f | 2013-06-23 09:37:00 +0300 | [diff] [blame] | 867 | |
Tomas Winkler | 2176754 | 2013-06-23 09:36:59 +0300 | [diff] [blame] | 868 | if (mei_hdr.msg_complete) { |
| 869 | if (mei_cl_flow_ctrl_reduce(cl)) |
Tomas Winkler | 2ebf8c9 | 2013-09-16 23:44:43 +0300 | [diff] [blame] | 870 | return -EIO; |
Tomas Winkler | 2176754 | 2013-06-23 09:36:59 +0300 | [diff] [blame] | 871 | list_move_tail(&cb->list, &dev->write_waiting_list.list); |
| 872 | } |
| 873 | |
| 874 | return 0; |
| 875 | } |
| 876 | |
| 877 | /** |
Tomas Winkler | 4234a6d | 2013-04-08 21:56:37 +0300 | [diff] [blame] | 878 | * mei_cl_write - submit a write cb to mei device |
| 879 | assumes device_lock is locked |
| 880 | * |
| 881 | * @cl: host client |
| 882 | * @cl: write callback with filled data |
| 883 | * |
Alexander Usyskin | 83ce074 | 2014-01-08 22:31:46 +0200 | [diff] [blame] | 884 | * returns number of bytes sent on success, <0 on failure. |
Tomas Winkler | 4234a6d | 2013-04-08 21:56:37 +0300 | [diff] [blame] | 885 | */ |
| 886 | int mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb, bool blocking) |
| 887 | { |
| 888 | struct mei_device *dev; |
| 889 | struct mei_msg_data *buf; |
| 890 | struct mei_msg_hdr mei_hdr; |
| 891 | int rets; |
| 892 | |
| 893 | |
| 894 | if (WARN_ON(!cl || !cl->dev)) |
| 895 | return -ENODEV; |
| 896 | |
| 897 | if (WARN_ON(!cb)) |
| 898 | return -EINVAL; |
| 899 | |
| 900 | dev = cl->dev; |
| 901 | |
| 902 | |
| 903 | buf = &cb->request_buffer; |
| 904 | |
Alexander Usyskin | c0abffb | 2013-09-15 18:11:07 +0300 | [diff] [blame] | 905 | cl_dbg(dev, cl, "mei_cl_write %d\n", buf->size); |
Tomas Winkler | 4234a6d | 2013-04-08 21:56:37 +0300 | [diff] [blame] | 906 | |
Tomas Winkler | 04bb139 | 2014-03-18 22:52:04 +0200 | [diff] [blame] | 907 | rets = pm_runtime_get(&dev->pdev->dev); |
| 908 | if (rets < 0 && rets != -EINPROGRESS) { |
| 909 | pm_runtime_put_noidle(&dev->pdev->dev); |
| 910 | cl_err(dev, cl, "rpm: get failed %d\n", rets); |
| 911 | return rets; |
| 912 | } |
Tomas Winkler | 4234a6d | 2013-04-08 21:56:37 +0300 | [diff] [blame] | 913 | |
| 914 | cb->fop_type = MEI_FOP_WRITE; |
Tomas Winkler | 6aae48f | 2014-02-19 17:35:47 +0200 | [diff] [blame] | 915 | cb->buf_idx = 0; |
| 916 | cl->writing_state = MEI_IDLE; |
| 917 | |
| 918 | mei_hdr.host_addr = cl->host_client_id; |
| 919 | mei_hdr.me_addr = cl->me_client_id; |
| 920 | mei_hdr.reserved = 0; |
| 921 | mei_hdr.msg_complete = 0; |
| 922 | mei_hdr.internal = cb->internal; |
Tomas Winkler | 4234a6d | 2013-04-08 21:56:37 +0300 | [diff] [blame] | 923 | |
| 924 | rets = mei_cl_flow_ctrl_creds(cl); |
| 925 | if (rets < 0) |
| 926 | goto err; |
| 927 | |
Tomas Winkler | 6aae48f | 2014-02-19 17:35:47 +0200 | [diff] [blame] | 928 | if (rets == 0) { |
| 929 | cl_dbg(dev, cl, "No flow control credentials: not sending.\n"); |
Tomas Winkler | 4234a6d | 2013-04-08 21:56:37 +0300 | [diff] [blame] | 930 | rets = buf->size; |
| 931 | goto out; |
| 932 | } |
Tomas Winkler | 6aae48f | 2014-02-19 17:35:47 +0200 | [diff] [blame] | 933 | if (!mei_hbuf_acquire(dev)) { |
| 934 | cl_dbg(dev, cl, "Cannot acquire the host buffer: not sending.\n"); |
| 935 | rets = buf->size; |
| 936 | goto out; |
| 937 | } |
Tomas Winkler | 4234a6d | 2013-04-08 21:56:37 +0300 | [diff] [blame] | 938 | |
| 939 | /* Check for a maximum length */ |
| 940 | if (buf->size > mei_hbuf_max_len(dev)) { |
| 941 | mei_hdr.length = mei_hbuf_max_len(dev); |
| 942 | mei_hdr.msg_complete = 0; |
| 943 | } else { |
| 944 | mei_hdr.length = buf->size; |
| 945 | mei_hdr.msg_complete = 1; |
| 946 | } |
| 947 | |
Tomas Winkler | 2ebf8c9 | 2013-09-16 23:44:43 +0300 | [diff] [blame] | 948 | rets = mei_write_message(dev, &mei_hdr, buf->data); |
| 949 | if (rets) |
Tomas Winkler | 4234a6d | 2013-04-08 21:56:37 +0300 | [diff] [blame] | 950 | goto err; |
Tomas Winkler | 4234a6d | 2013-04-08 21:56:37 +0300 | [diff] [blame] | 951 | |
| 952 | cl->writing_state = MEI_WRITING; |
| 953 | cb->buf_idx = mei_hdr.length; |
| 954 | |
Tomas Winkler | 4234a6d | 2013-04-08 21:56:37 +0300 | [diff] [blame] | 955 | out: |
| 956 | if (mei_hdr.msg_complete) { |
Alexander Usyskin | 7ca96aa | 2014-02-19 17:35:49 +0200 | [diff] [blame] | 957 | rets = mei_cl_flow_ctrl_reduce(cl); |
| 958 | if (rets < 0) |
Tomas Winkler | 4234a6d | 2013-04-08 21:56:37 +0300 | [diff] [blame] | 959 | goto err; |
Alexander Usyskin | 7ca96aa | 2014-02-19 17:35:49 +0200 | [diff] [blame] | 960 | |
Tomas Winkler | 4234a6d | 2013-04-08 21:56:37 +0300 | [diff] [blame] | 961 | list_add_tail(&cb->list, &dev->write_waiting_list.list); |
| 962 | } else { |
| 963 | list_add_tail(&cb->list, &dev->write_list.list); |
| 964 | } |
| 965 | |
| 966 | |
| 967 | if (blocking && cl->writing_state != MEI_WRITE_COMPLETE) { |
| 968 | |
| 969 | mutex_unlock(&dev->device_lock); |
Alexander Usyskin | 7ca96aa | 2014-02-19 17:35:49 +0200 | [diff] [blame] | 970 | rets = wait_event_interruptible(cl->tx_wait, |
| 971 | cl->writing_state == MEI_WRITE_COMPLETE); |
Tomas Winkler | 4234a6d | 2013-04-08 21:56:37 +0300 | [diff] [blame] | 972 | mutex_lock(&dev->device_lock); |
Alexander Usyskin | 7ca96aa | 2014-02-19 17:35:49 +0200 | [diff] [blame] | 973 | /* wait_event_interruptible returns -ERESTARTSYS */ |
| 974 | if (rets) { |
| 975 | if (signal_pending(current)) |
| 976 | rets = -EINTR; |
| 977 | goto err; |
| 978 | } |
Tomas Winkler | 4234a6d | 2013-04-08 21:56:37 +0300 | [diff] [blame] | 979 | } |
Alexander Usyskin | 7ca96aa | 2014-02-19 17:35:49 +0200 | [diff] [blame] | 980 | |
| 981 | rets = buf->size; |
Tomas Winkler | 4234a6d | 2013-04-08 21:56:37 +0300 | [diff] [blame] | 982 | err: |
Tomas Winkler | 04bb139 | 2014-03-18 22:52:04 +0200 | [diff] [blame] | 983 | cl_dbg(dev, cl, "rpm: autosuspend\n"); |
| 984 | pm_runtime_mark_last_busy(&dev->pdev->dev); |
| 985 | pm_runtime_put_autosuspend(&dev->pdev->dev); |
| 986 | |
Tomas Winkler | 4234a6d | 2013-04-08 21:56:37 +0300 | [diff] [blame] | 987 | return rets; |
| 988 | } |
| 989 | |
| 990 | |
Tomas Winkler | db086fa | 2013-05-12 15:34:45 +0300 | [diff] [blame] | 991 | /** |
| 992 | * mei_cl_complete - processes completed operation for a client |
| 993 | * |
| 994 | * @cl: private data of the file object. |
| 995 | * @cb: callback block. |
| 996 | */ |
| 997 | void mei_cl_complete(struct mei_cl *cl, struct mei_cl_cb *cb) |
| 998 | { |
| 999 | if (cb->fop_type == MEI_FOP_WRITE) { |
| 1000 | mei_io_cb_free(cb); |
| 1001 | cb = NULL; |
| 1002 | cl->writing_state = MEI_WRITE_COMPLETE; |
| 1003 | if (waitqueue_active(&cl->tx_wait)) |
| 1004 | wake_up_interruptible(&cl->tx_wait); |
| 1005 | |
| 1006 | } else if (cb->fop_type == MEI_FOP_READ && |
| 1007 | MEI_READING == cl->reading_state) { |
| 1008 | cl->reading_state = MEI_READ_COMPLETE; |
| 1009 | if (waitqueue_active(&cl->rx_wait)) |
| 1010 | wake_up_interruptible(&cl->rx_wait); |
| 1011 | else |
| 1012 | mei_cl_bus_rx_event(cl); |
| 1013 | |
| 1014 | } |
| 1015 | } |
| 1016 | |
Tomas Winkler | 4234a6d | 2013-04-08 21:56:37 +0300 | [diff] [blame] | 1017 | |
| 1018 | /** |
Tomas Winkler | 074b4c0 | 2013-02-06 14:06:44 +0200 | [diff] [blame] | 1019 | * mei_cl_all_disconnect - disconnect forcefully all connected clients |
| 1020 | * |
| 1021 | * @dev - mei device |
| 1022 | */ |
| 1023 | |
| 1024 | void mei_cl_all_disconnect(struct mei_device *dev) |
| 1025 | { |
Tomas Winkler | 31f88f5 | 2014-02-17 15:13:25 +0200 | [diff] [blame] | 1026 | struct mei_cl *cl; |
Tomas Winkler | 074b4c0 | 2013-02-06 14:06:44 +0200 | [diff] [blame] | 1027 | |
Tomas Winkler | 31f88f5 | 2014-02-17 15:13:25 +0200 | [diff] [blame] | 1028 | list_for_each_entry(cl, &dev->file_list, link) { |
Tomas Winkler | 074b4c0 | 2013-02-06 14:06:44 +0200 | [diff] [blame] | 1029 | cl->state = MEI_FILE_DISCONNECTED; |
| 1030 | cl->mei_flow_ctrl_creds = 0; |
Tomas Winkler | 074b4c0 | 2013-02-06 14:06:44 +0200 | [diff] [blame] | 1031 | cl->timer_count = 0; |
| 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | |
| 1036 | /** |
Tomas Winkler | 5290801 | 2013-07-24 16:22:57 +0300 | [diff] [blame] | 1037 | * mei_cl_all_wakeup - wake up all readers and writers they can be interrupted |
Tomas Winkler | 074b4c0 | 2013-02-06 14:06:44 +0200 | [diff] [blame] | 1038 | * |
| 1039 | * @dev - mei device |
| 1040 | */ |
Tomas Winkler | 5290801 | 2013-07-24 16:22:57 +0300 | [diff] [blame] | 1041 | void mei_cl_all_wakeup(struct mei_device *dev) |
Tomas Winkler | 074b4c0 | 2013-02-06 14:06:44 +0200 | [diff] [blame] | 1042 | { |
Tomas Winkler | 31f88f5 | 2014-02-17 15:13:25 +0200 | [diff] [blame] | 1043 | struct mei_cl *cl; |
| 1044 | list_for_each_entry(cl, &dev->file_list, link) { |
Tomas Winkler | 074b4c0 | 2013-02-06 14:06:44 +0200 | [diff] [blame] | 1045 | if (waitqueue_active(&cl->rx_wait)) { |
Alexander Usyskin | c0abffb | 2013-09-15 18:11:07 +0300 | [diff] [blame] | 1046 | cl_dbg(dev, cl, "Waking up reading client!\n"); |
Tomas Winkler | 074b4c0 | 2013-02-06 14:06:44 +0200 | [diff] [blame] | 1047 | wake_up_interruptible(&cl->rx_wait); |
| 1048 | } |
Tomas Winkler | 5290801 | 2013-07-24 16:22:57 +0300 | [diff] [blame] | 1049 | if (waitqueue_active(&cl->tx_wait)) { |
Alexander Usyskin | c0abffb | 2013-09-15 18:11:07 +0300 | [diff] [blame] | 1050 | cl_dbg(dev, cl, "Waking up writing client!\n"); |
Tomas Winkler | 5290801 | 2013-07-24 16:22:57 +0300 | [diff] [blame] | 1051 | wake_up_interruptible(&cl->tx_wait); |
| 1052 | } |
Tomas Winkler | 074b4c0 | 2013-02-06 14:06:44 +0200 | [diff] [blame] | 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | /** |
| 1057 | * mei_cl_all_write_clear - clear all pending writes |
| 1058 | |
| 1059 | * @dev - mei device |
| 1060 | */ |
| 1061 | void mei_cl_all_write_clear(struct mei_device *dev) |
| 1062 | { |
Tomas Winkler | cc99ecf | 2014-03-10 15:10:40 +0200 | [diff] [blame] | 1063 | mei_io_list_free(&dev->write_list, NULL); |
| 1064 | mei_io_list_free(&dev->write_waiting_list, NULL); |
Tomas Winkler | 074b4c0 | 2013-02-06 14:06:44 +0200 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | |