3 * Intel Management Engine Interface (Intel MEI) Linux driver
4 * Copyright (c) 2003-2012, Intel Corporation.
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.
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
17 #include <linux/sched.h>
18 #include <linux/wait.h>
19 #include <linux/delay.h>
20 #include <linux/slab.h>
21 #include <linux/pm_runtime.h>
23 #include <linux/mei.h>
30 * mei_me_cl_by_uuid - locate index of me client
34 * Locking: called under "dev->device_lock" lock
36 * returns me client or NULL if not found
38 struct mei_me_client *mei_me_cl_by_uuid(const struct mei_device *dev,
41 struct mei_me_client *me_cl;
43 list_for_each_entry(me_cl, &dev->me_clients, list)
44 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0)
51 * mei_me_cl_by_id return index to me_clients for client_id
53 * @dev: the device structure
54 * @client_id: me client id
56 * Locking: called under "dev->device_lock" lock
58 * returns me client or NULL if not found
61 struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id)
64 struct mei_me_client *me_cl;
66 list_for_each_entry(me_cl, &dev->me_clients, list)
67 if (me_cl->client_id == client_id)
72 struct mei_me_client *mei_me_cl_by_uuid_id(struct mei_device *dev,
73 const uuid_le *uuid, u8 client_id)
75 struct mei_me_client *me_cl;
77 list_for_each_entry(me_cl, &dev->me_clients, list)
78 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0 &&
79 me_cl->client_id == client_id)
85 * mei_me_cl_remove - remove me client matching uuid and client_id
87 * @dev: the device structure
88 * @uuid: me client uuid
89 * @client_id: me client address
91 void mei_me_cl_remove(struct mei_device *dev, const uuid_le *uuid, u8 client_id)
93 struct mei_me_client *me_cl, *next;
95 list_for_each_entry_safe(me_cl, next, &dev->me_clients, list) {
96 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0 &&
97 me_cl->client_id == client_id) {
98 list_del(&me_cl->list);
107 * mei_cl_cmp_id - tells if the clients are the same
109 * @cl1: host client 1
110 * @cl2: host client 2
112 * returns true - if the clients has same host and me ids
115 static inline bool mei_cl_cmp_id(const struct mei_cl *cl1,
116 const struct mei_cl *cl2)
119 (cl1->host_client_id == cl2->host_client_id) &&
120 (cl1->me_client_id == cl2->me_client_id);
124 * mei_io_list_flush - removes cbs belonging to cl.
126 * @list: an instance of our list structure
127 * @cl: host client, can be NULL for flushing the whole list
128 * @free: whether to free the cbs
130 static void __mei_io_list_flush(struct mei_cl_cb *list,
131 struct mei_cl *cl, bool free)
133 struct mei_cl_cb *cb;
134 struct mei_cl_cb *next;
136 /* enable removing everything if no cl is specified */
137 list_for_each_entry_safe(cb, next, &list->list, list) {
138 if (!cl || (cb->cl && mei_cl_cmp_id(cl, cb->cl))) {
147 * mei_io_list_flush - removes list entry belonging to cl.
149 * @list: An instance of our list structure
152 void mei_io_list_flush(struct mei_cl_cb *list, struct mei_cl *cl)
154 __mei_io_list_flush(list, cl, false);
159 * mei_io_list_free - removes cb belonging to cl and free them
161 * @list: An instance of our list structure
164 static inline void mei_io_list_free(struct mei_cl_cb *list, struct mei_cl *cl)
166 __mei_io_list_flush(list, cl, true);
170 * mei_io_cb_free - free mei_cb_private related memory
172 * @cb: mei callback struct
174 void mei_io_cb_free(struct mei_cl_cb *cb)
179 kfree(cb->request_buffer.data);
180 kfree(cb->response_buffer.data);
185 * mei_io_cb_init - allocate and initialize io callback
188 * @fp: pointer to file structure
190 * returns mei_cl_cb pointer or NULL;
192 struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, struct file *fp)
194 struct mei_cl_cb *cb;
196 cb = kzalloc(sizeof(struct mei_cl_cb), GFP_KERNEL);
200 mei_io_list_init(cb);
202 cb->file_object = fp;
209 * mei_io_cb_alloc_req_buf - allocate request buffer
211 * @cb: io callback structure
212 * @length: size of the buffer
214 * returns 0 on success
215 * -EINVAL if cb is NULL
216 * -ENOMEM if allocation failed
218 int mei_io_cb_alloc_req_buf(struct mei_cl_cb *cb, size_t length)
226 cb->request_buffer.data = kmalloc(length, GFP_KERNEL);
227 if (!cb->request_buffer.data)
229 cb->request_buffer.size = length;
233 * mei_io_cb_alloc_resp_buf - allocate response buffer
235 * @cb: io callback structure
236 * @length: size of the buffer
238 * returns 0 on success
239 * -EINVAL if cb is NULL
240 * -ENOMEM if allocation failed
242 int mei_io_cb_alloc_resp_buf(struct mei_cl_cb *cb, size_t length)
250 cb->response_buffer.data = kmalloc(length, GFP_KERNEL);
251 if (!cb->response_buffer.data)
253 cb->response_buffer.size = length;
260 * mei_cl_flush_queues - flushes queue lists belonging to cl.
264 int mei_cl_flush_queues(struct mei_cl *cl)
266 struct mei_device *dev;
268 if (WARN_ON(!cl || !cl->dev))
273 cl_dbg(dev, cl, "remove list entry belonging to cl\n");
274 mei_io_list_flush(&cl->dev->read_list, cl);
275 mei_io_list_free(&cl->dev->write_list, cl);
276 mei_io_list_free(&cl->dev->write_waiting_list, cl);
277 mei_io_list_flush(&cl->dev->ctrl_wr_list, cl);
278 mei_io_list_flush(&cl->dev->ctrl_rd_list, cl);
279 mei_io_list_flush(&cl->dev->amthif_cmd_list, cl);
280 mei_io_list_flush(&cl->dev->amthif_rd_complete_list, cl);
286 * mei_cl_init - initializes cl.
288 * @cl: host client to be initialized
291 void mei_cl_init(struct mei_cl *cl, struct mei_device *dev)
293 memset(cl, 0, sizeof(struct mei_cl));
294 init_waitqueue_head(&cl->wait);
295 init_waitqueue_head(&cl->rx_wait);
296 init_waitqueue_head(&cl->tx_wait);
297 INIT_LIST_HEAD(&cl->link);
298 INIT_LIST_HEAD(&cl->device_link);
299 cl->reading_state = MEI_IDLE;
300 cl->writing_state = MEI_IDLE;
305 * mei_cl_allocate - allocates cl structure and sets it up.
308 * returns The allocated file or NULL on failure
310 struct mei_cl *mei_cl_allocate(struct mei_device *dev)
314 cl = kmalloc(sizeof(struct mei_cl), GFP_KERNEL);
318 mei_cl_init(cl, dev);
324 * mei_cl_find_read_cb - find this cl's callback in the read list
328 * returns cb on success, NULL on error
330 struct mei_cl_cb *mei_cl_find_read_cb(struct mei_cl *cl)
332 struct mei_device *dev = cl->dev;
333 struct mei_cl_cb *cb;
335 list_for_each_entry(cb, &dev->read_list.list, list)
336 if (mei_cl_cmp_id(cl, cb->cl))
341 /** mei_cl_link: allocate host id in the host map
344 * @id - fixed host id or -1 for generic one
346 * returns 0 on success
347 * -EINVAL on incorrect values
348 * -ENONET if client not found
350 int mei_cl_link(struct mei_cl *cl, int id)
352 struct mei_device *dev;
353 long open_handle_count;
355 if (WARN_ON(!cl || !cl->dev))
360 /* If Id is not assigned get one*/
361 if (id == MEI_HOST_CLIENT_ID_ANY)
362 id = find_first_zero_bit(dev->host_clients_map,
365 if (id >= MEI_CLIENTS_MAX) {
366 dev_err(dev->dev, "id exceeded %d", MEI_CLIENTS_MAX);
370 open_handle_count = dev->open_handle_count + dev->iamthif_open_count;
371 if (open_handle_count >= MEI_MAX_OPEN_HANDLE_COUNT) {
372 dev_err(dev->dev, "open_handle_count exceeded %d",
373 MEI_MAX_OPEN_HANDLE_COUNT);
377 dev->open_handle_count++;
379 cl->host_client_id = id;
380 list_add_tail(&cl->link, &dev->file_list);
382 set_bit(id, dev->host_clients_map);
384 cl->state = MEI_FILE_INITIALIZING;
386 cl_dbg(dev, cl, "link cl\n");
391 * mei_cl_unlink - remove me_cl from the list
395 int mei_cl_unlink(struct mei_cl *cl)
397 struct mei_device *dev;
399 /* don't shout on error exit path */
403 /* wd and amthif might not be initialized */
409 cl_dbg(dev, cl, "unlink client");
411 if (dev->open_handle_count > 0)
412 dev->open_handle_count--;
414 /* never clear the 0 bit */
415 if (cl->host_client_id)
416 clear_bit(cl->host_client_id, dev->host_clients_map);
418 list_del_init(&cl->link);
420 cl->state = MEI_FILE_INITIALIZING;
426 void mei_host_client_init(struct work_struct *work)
428 struct mei_device *dev = container_of(work,
429 struct mei_device, init_work);
430 struct mei_me_client *me_cl;
431 struct mei_client_properties *props;
433 mutex_lock(&dev->device_lock);
435 list_for_each_entry(me_cl, &dev->me_clients, list) {
436 props = &me_cl->props;
438 if (!uuid_le_cmp(props->protocol_name, mei_amthif_guid))
439 mei_amthif_host_init(dev);
440 else if (!uuid_le_cmp(props->protocol_name, mei_wd_guid))
441 mei_wd_host_init(dev);
442 else if (!uuid_le_cmp(props->protocol_name, mei_nfc_guid))
443 mei_nfc_host_init(dev);
447 dev->dev_state = MEI_DEV_ENABLED;
448 dev->reset_count = 0;
450 mutex_unlock(&dev->device_lock);
452 pm_runtime_mark_last_busy(dev->dev);
453 dev_dbg(dev->dev, "rpm: autosuspend\n");
454 pm_runtime_autosuspend(dev->dev);
458 * mei_hbuf_acquire: try to acquire host buffer
460 * @dev: the device structure
461 * returns true if host buffer was acquired
463 bool mei_hbuf_acquire(struct mei_device *dev)
465 if (mei_pg_state(dev) == MEI_PG_ON ||
466 dev->pg_event == MEI_PG_EVENT_WAIT) {
467 dev_dbg(dev->dev, "device is in pg\n");
471 if (!dev->hbuf_is_ready) {
472 dev_dbg(dev->dev, "hbuf is not ready\n");
476 dev->hbuf_is_ready = false;
482 * mei_cl_disconnect - disconnect host client from the me one
486 * Locking: called under "dev->device_lock" lock
488 * returns 0 on success, <0 on failure.
490 int mei_cl_disconnect(struct mei_cl *cl)
492 struct mei_device *dev;
493 struct mei_cl_cb *cb;
496 if (WARN_ON(!cl || !cl->dev))
501 cl_dbg(dev, cl, "disconnecting");
503 if (cl->state != MEI_FILE_DISCONNECTING)
506 rets = pm_runtime_get(dev->dev);
507 if (rets < 0 && rets != -EINPROGRESS) {
508 pm_runtime_put_noidle(dev->dev);
509 cl_err(dev, cl, "rpm: get failed %d\n", rets);
513 cb = mei_io_cb_init(cl, NULL);
519 cb->fop_type = MEI_FOP_DISCONNECT;
521 if (mei_hbuf_acquire(dev)) {
522 if (mei_hbm_cl_disconnect_req(dev, cl)) {
524 cl_err(dev, cl, "failed to disconnect.\n");
527 cl->timer_count = MEI_CONNECT_TIMEOUT;
528 mdelay(10); /* Wait for hardware disconnection ready */
529 list_add_tail(&cb->list, &dev->ctrl_rd_list.list);
531 cl_dbg(dev, cl, "add disconnect cb to control write list\n");
532 list_add_tail(&cb->list, &dev->ctrl_wr_list.list);
535 mutex_unlock(&dev->device_lock);
537 wait_event_timeout(cl->wait,
538 MEI_FILE_DISCONNECTED == cl->state,
539 mei_secs_to_jiffies(MEI_CL_CONNECT_TIMEOUT));
541 mutex_lock(&dev->device_lock);
543 if (MEI_FILE_DISCONNECTED == cl->state) {
545 cl_dbg(dev, cl, "successfully disconnected from FW client.\n");
547 cl_dbg(dev, cl, "timeout on disconnect from FW client.\n");
551 mei_io_list_flush(&dev->ctrl_rd_list, cl);
552 mei_io_list_flush(&dev->ctrl_wr_list, cl);
554 cl_dbg(dev, cl, "rpm: autosuspend\n");
555 pm_runtime_mark_last_busy(dev->dev);
556 pm_runtime_put_autosuspend(dev->dev);
564 * mei_cl_is_other_connecting - checks if other
565 * client with the same me client id is connecting
567 * @cl: private data of the file object
569 * returns true if other client is connected, false - otherwise.
571 bool mei_cl_is_other_connecting(struct mei_cl *cl)
573 struct mei_device *dev;
574 struct mei_cl *ocl; /* the other client */
576 if (WARN_ON(!cl || !cl->dev))
581 list_for_each_entry(ocl, &dev->file_list, link) {
582 if (ocl->state == MEI_FILE_CONNECTING &&
584 cl->me_client_id == ocl->me_client_id)
593 * mei_cl_connect - connect host client to the me one
597 * Locking: called under "dev->device_lock" lock
599 * returns 0 on success, <0 on failure.
601 int mei_cl_connect(struct mei_cl *cl, struct file *file)
603 struct mei_device *dev;
604 struct mei_cl_cb *cb;
607 if (WARN_ON(!cl || !cl->dev))
612 rets = pm_runtime_get(dev->dev);
613 if (rets < 0 && rets != -EINPROGRESS) {
614 pm_runtime_put_noidle(dev->dev);
615 cl_err(dev, cl, "rpm: get failed %d\n", rets);
619 cb = mei_io_cb_init(cl, file);
625 cb->fop_type = MEI_FOP_CONNECT;
627 /* run hbuf acquire last so we don't have to undo */
628 if (!mei_cl_is_other_connecting(cl) && mei_hbuf_acquire(dev)) {
629 cl->state = MEI_FILE_CONNECTING;
630 if (mei_hbm_cl_connect_req(dev, cl)) {
634 cl->timer_count = MEI_CONNECT_TIMEOUT;
635 list_add_tail(&cb->list, &dev->ctrl_rd_list.list);
637 cl->state = MEI_FILE_INITIALIZING;
638 list_add_tail(&cb->list, &dev->ctrl_wr_list.list);
641 mutex_unlock(&dev->device_lock);
642 wait_event_timeout(cl->wait,
643 (cl->state == MEI_FILE_CONNECTED ||
644 cl->state == MEI_FILE_DISCONNECTED),
645 mei_secs_to_jiffies(MEI_CL_CONNECT_TIMEOUT));
646 mutex_lock(&dev->device_lock);
648 if (cl->state != MEI_FILE_CONNECTED) {
649 cl->state = MEI_FILE_DISCONNECTED;
650 /* something went really wrong */
652 cl->status = -EFAULT;
654 mei_io_list_flush(&dev->ctrl_rd_list, cl);
655 mei_io_list_flush(&dev->ctrl_wr_list, cl);
661 cl_dbg(dev, cl, "rpm: autosuspend\n");
662 pm_runtime_mark_last_busy(dev->dev);
663 pm_runtime_put_autosuspend(dev->dev);
670 * mei_cl_flow_ctrl_creds - checks flow_control credits for cl.
672 * @cl: private data of the file object
674 * returns 1 if mei_flow_ctrl_creds >0, 0 - otherwise.
675 * -ENOENT if mei_cl is not present
676 * -EINVAL if single_recv_buf == 0
678 int mei_cl_flow_ctrl_creds(struct mei_cl *cl)
680 struct mei_device *dev;
681 struct mei_me_client *me_cl;
683 if (WARN_ON(!cl || !cl->dev))
688 if (cl->mei_flow_ctrl_creds > 0)
691 me_cl = mei_me_cl_by_id(dev, cl->me_client_id);
693 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id);
697 if (me_cl->mei_flow_ctrl_creds) {
698 if (WARN_ON(me_cl->props.single_recv_buf == 0))
706 * mei_cl_flow_ctrl_reduce - reduces flow_control.
708 * @cl: private data of the file object
712 * -ENOENT when me client is not found
713 * -EINVAL when ctrl credits are <= 0
715 int mei_cl_flow_ctrl_reduce(struct mei_cl *cl)
717 struct mei_device *dev;
718 struct mei_me_client *me_cl;
720 if (WARN_ON(!cl || !cl->dev))
725 me_cl = mei_me_cl_by_id(dev, cl->me_client_id);
727 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id);
731 if (me_cl->props.single_recv_buf) {
732 if (WARN_ON(me_cl->mei_flow_ctrl_creds <= 0))
734 me_cl->mei_flow_ctrl_creds--;
736 if (WARN_ON(cl->mei_flow_ctrl_creds <= 0))
738 cl->mei_flow_ctrl_creds--;
744 * mei_cl_read_start - the start read client message function.
748 * returns 0 on success, <0 on failure.
750 int mei_cl_read_start(struct mei_cl *cl, size_t length)
752 struct mei_device *dev;
753 struct mei_cl_cb *cb;
754 struct mei_me_client *me_cl;
757 if (WARN_ON(!cl || !cl->dev))
762 if (!mei_cl_is_connected(cl))
766 cl_dbg(dev, cl, "read is pending.\n");
769 me_cl = mei_me_cl_by_uuid_id(dev, &cl->cl_uuid, cl->me_client_id);
771 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id);
775 rets = pm_runtime_get(dev->dev);
776 if (rets < 0 && rets != -EINPROGRESS) {
777 pm_runtime_put_noidle(dev->dev);
778 cl_err(dev, cl, "rpm: get failed %d\n", rets);
782 cb = mei_io_cb_init(cl, NULL);
788 /* always allocate at least client max message */
789 length = max_t(size_t, length, me_cl->props.max_msg_length);
790 rets = mei_io_cb_alloc_resp_buf(cb, length);
794 cb->fop_type = MEI_FOP_READ;
795 if (mei_hbuf_acquire(dev)) {
796 rets = mei_hbm_cl_flow_control_req(dev, cl);
800 list_add_tail(&cb->list, &dev->read_list.list);
802 list_add_tail(&cb->list, &dev->ctrl_wr_list.list);
808 cl_dbg(dev, cl, "rpm: autosuspend\n");
809 pm_runtime_mark_last_busy(dev->dev);
810 pm_runtime_put_autosuspend(dev->dev);
819 * mei_cl_irq_write - write a message to device
820 * from the interrupt thread context
823 * @cb: callback block.
824 * @cmpl_list: complete list.
826 * returns 0, OK; otherwise error.
828 int mei_cl_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb,
829 struct mei_cl_cb *cmpl_list)
831 struct mei_device *dev;
832 struct mei_msg_data *buf;
833 struct mei_msg_hdr mei_hdr;
839 if (WARN_ON(!cl || !cl->dev))
844 buf = &cb->request_buffer;
846 rets = mei_cl_flow_ctrl_creds(cl);
851 cl_dbg(dev, cl, "No flow control credentials: not sending.\n");
855 slots = mei_hbuf_empty_slots(dev);
856 len = buf->size - cb->buf_idx;
857 msg_slots = mei_data2slots(len);
859 mei_hdr.host_addr = cl->host_client_id;
860 mei_hdr.me_addr = cl->me_client_id;
861 mei_hdr.reserved = 0;
862 mei_hdr.internal = cb->internal;
864 if (slots >= msg_slots) {
865 mei_hdr.length = len;
866 mei_hdr.msg_complete = 1;
867 /* Split the message only if we can write the whole host buffer */
868 } else if (slots == dev->hbuf_depth) {
870 len = (slots * sizeof(u32)) - sizeof(struct mei_msg_hdr);
871 mei_hdr.length = len;
872 mei_hdr.msg_complete = 0;
874 /* wait for next time the host buffer is empty */
878 cl_dbg(dev, cl, "buf: size = %d idx = %lu\n",
879 cb->request_buffer.size, cb->buf_idx);
881 rets = mei_write_message(dev, &mei_hdr, buf->data + cb->buf_idx);
884 list_move_tail(&cb->list, &cmpl_list->list);
889 cl->writing_state = MEI_WRITING;
890 cb->buf_idx += mei_hdr.length;
892 if (mei_hdr.msg_complete) {
893 if (mei_cl_flow_ctrl_reduce(cl))
895 list_move_tail(&cb->list, &dev->write_waiting_list.list);
902 * mei_cl_write - submit a write cb to mei device
903 assumes device_lock is locked
906 * @cl: write callback with filled data
908 * returns number of bytes sent on success, <0 on failure.
910 int mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb, bool blocking)
912 struct mei_device *dev;
913 struct mei_msg_data *buf;
914 struct mei_msg_hdr mei_hdr;
918 if (WARN_ON(!cl || !cl->dev))
927 buf = &cb->request_buffer;
929 cl_dbg(dev, cl, "mei_cl_write %d\n", buf->size);
931 rets = pm_runtime_get(dev->dev);
932 if (rets < 0 && rets != -EINPROGRESS) {
933 pm_runtime_put_noidle(dev->dev);
934 cl_err(dev, cl, "rpm: get failed %d\n", rets);
938 cb->fop_type = MEI_FOP_WRITE;
940 cl->writing_state = MEI_IDLE;
942 mei_hdr.host_addr = cl->host_client_id;
943 mei_hdr.me_addr = cl->me_client_id;
944 mei_hdr.reserved = 0;
945 mei_hdr.msg_complete = 0;
946 mei_hdr.internal = cb->internal;
948 rets = mei_cl_flow_ctrl_creds(cl);
953 cl_dbg(dev, cl, "No flow control credentials: not sending.\n");
957 if (!mei_hbuf_acquire(dev)) {
958 cl_dbg(dev, cl, "Cannot acquire the host buffer: not sending.\n");
963 /* Check for a maximum length */
964 if (buf->size > mei_hbuf_max_len(dev)) {
965 mei_hdr.length = mei_hbuf_max_len(dev);
966 mei_hdr.msg_complete = 0;
968 mei_hdr.length = buf->size;
969 mei_hdr.msg_complete = 1;
972 rets = mei_write_message(dev, &mei_hdr, buf->data);
976 cl->writing_state = MEI_WRITING;
977 cb->buf_idx = mei_hdr.length;
980 if (mei_hdr.msg_complete) {
981 rets = mei_cl_flow_ctrl_reduce(cl);
985 list_add_tail(&cb->list, &dev->write_waiting_list.list);
987 list_add_tail(&cb->list, &dev->write_list.list);
991 if (blocking && cl->writing_state != MEI_WRITE_COMPLETE) {
993 mutex_unlock(&dev->device_lock);
994 rets = wait_event_interruptible(cl->tx_wait,
995 cl->writing_state == MEI_WRITE_COMPLETE);
996 mutex_lock(&dev->device_lock);
997 /* wait_event_interruptible returns -ERESTARTSYS */
999 if (signal_pending(current))
1007 cl_dbg(dev, cl, "rpm: autosuspend\n");
1008 pm_runtime_mark_last_busy(dev->dev);
1009 pm_runtime_put_autosuspend(dev->dev);
1016 * mei_cl_complete - processes completed operation for a client
1018 * @cl: private data of the file object.
1019 * @cb: callback block.
1021 void mei_cl_complete(struct mei_cl *cl, struct mei_cl_cb *cb)
1023 if (cb->fop_type == MEI_FOP_WRITE) {
1026 cl->writing_state = MEI_WRITE_COMPLETE;
1027 if (waitqueue_active(&cl->tx_wait))
1028 wake_up_interruptible(&cl->tx_wait);
1030 } else if (cb->fop_type == MEI_FOP_READ &&
1031 MEI_READING == cl->reading_state) {
1032 cl->reading_state = MEI_READ_COMPLETE;
1033 if (waitqueue_active(&cl->rx_wait))
1034 wake_up_interruptible(&cl->rx_wait);
1036 mei_cl_bus_rx_event(cl);
1043 * mei_cl_all_disconnect - disconnect forcefully all connected clients
1048 void mei_cl_all_disconnect(struct mei_device *dev)
1052 list_for_each_entry(cl, &dev->file_list, link) {
1053 cl->state = MEI_FILE_DISCONNECTED;
1054 cl->mei_flow_ctrl_creds = 0;
1055 cl->timer_count = 0;
1061 * mei_cl_all_wakeup - wake up all readers and writers they can be interrupted
1065 void mei_cl_all_wakeup(struct mei_device *dev)
1069 list_for_each_entry(cl, &dev->file_list, link) {
1070 if (waitqueue_active(&cl->rx_wait)) {
1071 cl_dbg(dev, cl, "Waking up reading client!\n");
1072 wake_up_interruptible(&cl->rx_wait);
1074 if (waitqueue_active(&cl->tx_wait)) {
1075 cl_dbg(dev, cl, "Waking up writing client!\n");
1076 wake_up_interruptible(&cl->tx_wait);
1082 * mei_cl_all_write_clear - clear all pending writes
1086 void mei_cl_all_write_clear(struct mei_device *dev)
1088 mei_io_list_free(&dev->write_list, NULL);
1089 mei_io_list_free(&dev->write_waiting_list, NULL);