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