This source file includes following definitions.
- mei_me_cl_init
- mei_me_cl_get
- mei_me_cl_release
- mei_me_cl_put
- __mei_me_cl_del
- mei_me_cl_del
- mei_me_cl_add
- __mei_me_cl_by_uuid
- mei_me_cl_by_uuid
- mei_me_cl_by_id
- __mei_me_cl_by_uuid_id
- mei_me_cl_by_uuid_id
- mei_me_cl_rm_by_uuid
- mei_me_cl_rm_by_uuid_id
- mei_me_cl_rm_all
- mei_io_cb_free
- mei_tx_cb_enqueue
- mei_tx_cb_dequeue
- mei_io_cb_init
- mei_io_list_flush_cl
- mei_io_tx_list_free_cl
- mei_io_list_free_fp
- mei_cl_alloc_cb
- mei_cl_enqueue_ctrl_wr_cb
- mei_cl_read_cb
- mei_cl_flush_queues
- mei_cl_init
- mei_cl_allocate
- mei_cl_link
- mei_cl_unlink
- mei_host_client_init
- mei_hbuf_acquire
- mei_cl_wake_all
- mei_cl_set_disconnected
- mei_cl_set_connecting
- mei_cl_send_disconnect
- mei_cl_irq_disconnect
- __mei_cl_disconnect
- mei_cl_disconnect
- mei_cl_is_other_connecting
- mei_cl_send_connect
- mei_cl_irq_connect
- mei_cl_connect
- mei_cl_alloc_linked
- mei_cl_tx_flow_ctrl_creds
- mei_cl_tx_flow_ctrl_creds_reduce
- mei_cl_notify_fop2req
- mei_cl_notify_req2fop
- mei_cl_irq_notify
- mei_cl_notify_request
- mei_cl_notify
- mei_cl_notify_get
- mei_cl_read_start
- mei_msg_hdr_init
- mei_cl_irq_write
- mei_cl_write
- mei_cl_complete
- mei_cl_all_disconnect
1
2
3
4
5
6
7 #include <linux/sched/signal.h>
8 #include <linux/wait.h>
9 #include <linux/delay.h>
10 #include <linux/slab.h>
11 #include <linux/pm_runtime.h>
12
13 #include <linux/mei.h>
14
15 #include "mei_dev.h"
16 #include "hbm.h"
17 #include "client.h"
18
19
20
21
22
23
24 void mei_me_cl_init(struct mei_me_client *me_cl)
25 {
26 INIT_LIST_HEAD(&me_cl->list);
27 kref_init(&me_cl->refcnt);
28 }
29
30
31
32
33
34
35
36
37
38
39 struct mei_me_client *mei_me_cl_get(struct mei_me_client *me_cl)
40 {
41 if (me_cl && kref_get_unless_zero(&me_cl->refcnt))
42 return me_cl;
43
44 return NULL;
45 }
46
47
48
49
50
51
52
53
54 static void mei_me_cl_release(struct kref *ref)
55 {
56 struct mei_me_client *me_cl =
57 container_of(ref, struct mei_me_client, refcnt);
58
59 kfree(me_cl);
60 }
61
62
63
64
65
66
67
68
69 void mei_me_cl_put(struct mei_me_client *me_cl)
70 {
71 if (me_cl)
72 kref_put(&me_cl->refcnt, mei_me_cl_release);
73 }
74
75
76
77
78
79
80
81
82
83
84 static void __mei_me_cl_del(struct mei_device *dev, struct mei_me_client *me_cl)
85 {
86 if (!me_cl)
87 return;
88
89 list_del_init(&me_cl->list);
90 mei_me_cl_put(me_cl);
91 }
92
93
94
95
96
97
98
99
100 void mei_me_cl_del(struct mei_device *dev, struct mei_me_client *me_cl)
101 {
102 down_write(&dev->me_clients_rwsem);
103 __mei_me_cl_del(dev, me_cl);
104 up_write(&dev->me_clients_rwsem);
105 }
106
107
108
109
110
111
112
113 void mei_me_cl_add(struct mei_device *dev, struct mei_me_client *me_cl)
114 {
115 down_write(&dev->me_clients_rwsem);
116 list_add(&me_cl->list, &dev->me_clients);
117 up_write(&dev->me_clients_rwsem);
118 }
119
120
121
122
123
124
125
126
127
128
129
130
131 static struct mei_me_client *__mei_me_cl_by_uuid(struct mei_device *dev,
132 const uuid_le *uuid)
133 {
134 struct mei_me_client *me_cl;
135 const uuid_le *pn;
136
137 WARN_ON(!rwsem_is_locked(&dev->me_clients_rwsem));
138
139 list_for_each_entry(me_cl, &dev->me_clients, list) {
140 pn = &me_cl->props.protocol_name;
141 if (uuid_le_cmp(*uuid, *pn) == 0)
142 return mei_me_cl_get(me_cl);
143 }
144
145 return NULL;
146 }
147
148
149
150
151
152
153
154
155
156
157
158
159 struct mei_me_client *mei_me_cl_by_uuid(struct mei_device *dev,
160 const uuid_le *uuid)
161 {
162 struct mei_me_client *me_cl;
163
164 down_read(&dev->me_clients_rwsem);
165 me_cl = __mei_me_cl_by_uuid(dev, uuid);
166 up_read(&dev->me_clients_rwsem);
167
168 return me_cl;
169 }
170
171
172
173
174
175
176
177
178
179
180
181
182 struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id)
183 {
184
185 struct mei_me_client *__me_cl, *me_cl = NULL;
186
187 down_read(&dev->me_clients_rwsem);
188 list_for_each_entry(__me_cl, &dev->me_clients, list) {
189 if (__me_cl->client_id == client_id) {
190 me_cl = mei_me_cl_get(__me_cl);
191 break;
192 }
193 }
194 up_read(&dev->me_clients_rwsem);
195
196 return me_cl;
197 }
198
199
200
201
202
203
204
205
206
207
208
209
210
211 static struct mei_me_client *__mei_me_cl_by_uuid_id(struct mei_device *dev,
212 const uuid_le *uuid, u8 client_id)
213 {
214 struct mei_me_client *me_cl;
215 const uuid_le *pn;
216
217 WARN_ON(!rwsem_is_locked(&dev->me_clients_rwsem));
218
219 list_for_each_entry(me_cl, &dev->me_clients, list) {
220 pn = &me_cl->props.protocol_name;
221 if (uuid_le_cmp(*uuid, *pn) == 0 &&
222 me_cl->client_id == client_id)
223 return mei_me_cl_get(me_cl);
224 }
225
226 return NULL;
227 }
228
229
230
231
232
233
234
235
236
237
238
239
240 struct mei_me_client *mei_me_cl_by_uuid_id(struct mei_device *dev,
241 const uuid_le *uuid, u8 client_id)
242 {
243 struct mei_me_client *me_cl;
244
245 down_read(&dev->me_clients_rwsem);
246 me_cl = __mei_me_cl_by_uuid_id(dev, uuid, client_id);
247 up_read(&dev->me_clients_rwsem);
248
249 return me_cl;
250 }
251
252
253
254
255
256
257
258
259
260 void mei_me_cl_rm_by_uuid(struct mei_device *dev, const uuid_le *uuid)
261 {
262 struct mei_me_client *me_cl;
263
264 dev_dbg(dev->dev, "remove %pUl\n", uuid);
265
266 down_write(&dev->me_clients_rwsem);
267 me_cl = __mei_me_cl_by_uuid(dev, uuid);
268 __mei_me_cl_del(dev, me_cl);
269 mei_me_cl_put(me_cl);
270 up_write(&dev->me_clients_rwsem);
271 }
272
273
274
275
276
277
278
279
280
281
282 void mei_me_cl_rm_by_uuid_id(struct mei_device *dev, const uuid_le *uuid, u8 id)
283 {
284 struct mei_me_client *me_cl;
285
286 dev_dbg(dev->dev, "remove %pUl %d\n", uuid, id);
287
288 down_write(&dev->me_clients_rwsem);
289 me_cl = __mei_me_cl_by_uuid_id(dev, uuid, id);
290 __mei_me_cl_del(dev, me_cl);
291 mei_me_cl_put(me_cl);
292 up_write(&dev->me_clients_rwsem);
293 }
294
295
296
297
298
299
300
301
302 void mei_me_cl_rm_all(struct mei_device *dev)
303 {
304 struct mei_me_client *me_cl, *next;
305
306 down_write(&dev->me_clients_rwsem);
307 list_for_each_entry_safe(me_cl, next, &dev->me_clients, list)
308 __mei_me_cl_del(dev, me_cl);
309 up_write(&dev->me_clients_rwsem);
310 }
311
312
313
314
315
316
317 void mei_io_cb_free(struct mei_cl_cb *cb)
318 {
319 if (cb == NULL)
320 return;
321
322 list_del(&cb->list);
323 kfree(cb->buf.data);
324 kfree(cb);
325 }
326
327
328
329
330
331
332
333
334
335 static inline void mei_tx_cb_enqueue(struct mei_cl_cb *cb,
336 struct list_head *head)
337 {
338 list_add_tail(&cb->list, head);
339 cb->cl->tx_cb_queued++;
340 }
341
342
343
344
345
346
347
348
349 static inline void mei_tx_cb_dequeue(struct mei_cl_cb *cb)
350 {
351 if (!WARN_ON(cb->cl->tx_cb_queued == 0))
352 cb->cl->tx_cb_queued--;
353
354 mei_io_cb_free(cb);
355 }
356
357
358
359
360
361
362
363
364
365
366 static struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl,
367 enum mei_cb_file_ops type,
368 const struct file *fp)
369 {
370 struct mei_cl_cb *cb;
371
372 cb = kzalloc(sizeof(struct mei_cl_cb), GFP_KERNEL);
373 if (!cb)
374 return NULL;
375
376 INIT_LIST_HEAD(&cb->list);
377 cb->fp = fp;
378 cb->cl = cl;
379 cb->buf_idx = 0;
380 cb->fop_type = type;
381 return cb;
382 }
383
384
385
386
387
388
389
390 static void mei_io_list_flush_cl(struct list_head *head,
391 const struct mei_cl *cl)
392 {
393 struct mei_cl_cb *cb, *next;
394
395 list_for_each_entry_safe(cb, next, head, list) {
396 if (cl == cb->cl) {
397 list_del_init(&cb->list);
398 if (cb->fop_type == MEI_FOP_READ)
399 mei_io_cb_free(cb);
400 }
401 }
402 }
403
404
405
406
407
408
409
410 static void mei_io_tx_list_free_cl(struct list_head *head,
411 const struct mei_cl *cl)
412 {
413 struct mei_cl_cb *cb, *next;
414
415 list_for_each_entry_safe(cb, next, head, list) {
416 if (cl == cb->cl)
417 mei_tx_cb_dequeue(cb);
418 }
419 }
420
421
422
423
424
425
426
427 static void mei_io_list_free_fp(struct list_head *head, const struct file *fp)
428 {
429 struct mei_cl_cb *cb, *next;
430
431 list_for_each_entry_safe(cb, next, head, list)
432 if (!fp || fp == cb->fp)
433 mei_io_cb_free(cb);
434 }
435
436
437
438
439
440
441
442
443
444
445
446 struct mei_cl_cb *mei_cl_alloc_cb(struct mei_cl *cl, size_t length,
447 enum mei_cb_file_ops fop_type,
448 const struct file *fp)
449 {
450 struct mei_cl_cb *cb;
451
452 cb = mei_io_cb_init(cl, fop_type, fp);
453 if (!cb)
454 return NULL;
455
456 if (length == 0)
457 return cb;
458
459 cb->buf.data = kmalloc(roundup(length, MEI_SLOT_SIZE), GFP_KERNEL);
460 if (!cb->buf.data) {
461 mei_io_cb_free(cb);
462 return NULL;
463 }
464 cb->buf.size = length;
465
466 return cb;
467 }
468
469
470
471
472
473
474
475
476
477
478
479
480
481 struct mei_cl_cb *mei_cl_enqueue_ctrl_wr_cb(struct mei_cl *cl, size_t length,
482 enum mei_cb_file_ops fop_type,
483 const struct file *fp)
484 {
485 struct mei_cl_cb *cb;
486
487
488 if (length)
489 length = max_t(size_t, length, mei_cl_mtu(cl));
490
491 cb = mei_cl_alloc_cb(cl, length, fop_type, fp);
492 if (!cb)
493 return NULL;
494
495 list_add_tail(&cb->list, &cl->dev->ctrl_wr_list);
496 return cb;
497 }
498
499
500
501
502
503
504
505
506
507
508 struct mei_cl_cb *mei_cl_read_cb(const struct mei_cl *cl, const struct file *fp)
509 {
510 struct mei_cl_cb *cb;
511
512 list_for_each_entry(cb, &cl->rd_completed, list)
513 if (!fp || fp == cb->fp)
514 return cb;
515
516 return NULL;
517 }
518
519
520
521
522
523
524
525
526
527 int mei_cl_flush_queues(struct mei_cl *cl, const struct file *fp)
528 {
529 struct mei_device *dev;
530
531 if (WARN_ON(!cl || !cl->dev))
532 return -EINVAL;
533
534 dev = cl->dev;
535
536 cl_dbg(dev, cl, "remove list entry belonging to cl\n");
537 mei_io_tx_list_free_cl(&cl->dev->write_list, cl);
538 mei_io_tx_list_free_cl(&cl->dev->write_waiting_list, cl);
539 mei_io_list_flush_cl(&cl->dev->ctrl_wr_list, cl);
540 mei_io_list_flush_cl(&cl->dev->ctrl_rd_list, cl);
541 mei_io_list_free_fp(&cl->rd_pending, fp);
542 mei_io_list_free_fp(&cl->rd_completed, fp);
543
544 return 0;
545 }
546
547
548
549
550
551
552
553 static void mei_cl_init(struct mei_cl *cl, struct mei_device *dev)
554 {
555 memset(cl, 0, sizeof(struct mei_cl));
556 init_waitqueue_head(&cl->wait);
557 init_waitqueue_head(&cl->rx_wait);
558 init_waitqueue_head(&cl->tx_wait);
559 init_waitqueue_head(&cl->ev_wait);
560 INIT_LIST_HEAD(&cl->rd_completed);
561 INIT_LIST_HEAD(&cl->rd_pending);
562 INIT_LIST_HEAD(&cl->link);
563 cl->writing_state = MEI_IDLE;
564 cl->state = MEI_FILE_UNINITIALIZED;
565 cl->dev = dev;
566 }
567
568
569
570
571
572
573
574 struct mei_cl *mei_cl_allocate(struct mei_device *dev)
575 {
576 struct mei_cl *cl;
577
578 cl = kmalloc(sizeof(struct mei_cl), GFP_KERNEL);
579 if (!cl)
580 return NULL;
581
582 mei_cl_init(cl, dev);
583
584 return cl;
585 }
586
587
588
589
590
591
592
593
594
595
596 int mei_cl_link(struct mei_cl *cl)
597 {
598 struct mei_device *dev;
599 int id;
600
601 if (WARN_ON(!cl || !cl->dev))
602 return -EINVAL;
603
604 dev = cl->dev;
605
606 id = find_first_zero_bit(dev->host_clients_map, MEI_CLIENTS_MAX);
607 if (id >= MEI_CLIENTS_MAX) {
608 dev_err(dev->dev, "id exceeded %d", MEI_CLIENTS_MAX);
609 return -EMFILE;
610 }
611
612 if (dev->open_handle_count >= MEI_MAX_OPEN_HANDLE_COUNT) {
613 dev_err(dev->dev, "open_handle_count exceeded %d",
614 MEI_MAX_OPEN_HANDLE_COUNT);
615 return -EMFILE;
616 }
617
618 dev->open_handle_count++;
619
620 cl->host_client_id = id;
621 list_add_tail(&cl->link, &dev->file_list);
622
623 set_bit(id, dev->host_clients_map);
624
625 cl->state = MEI_FILE_INITIALIZING;
626
627 cl_dbg(dev, cl, "link cl\n");
628 return 0;
629 }
630
631
632
633
634
635
636
637
638 int mei_cl_unlink(struct mei_cl *cl)
639 {
640 struct mei_device *dev;
641
642
643 if (!cl)
644 return 0;
645
646 if (WARN_ON(!cl->dev))
647 return 0;
648
649 dev = cl->dev;
650
651 cl_dbg(dev, cl, "unlink client");
652
653 if (dev->open_handle_count > 0)
654 dev->open_handle_count--;
655
656
657 if (cl->host_client_id)
658 clear_bit(cl->host_client_id, dev->host_clients_map);
659
660 list_del_init(&cl->link);
661
662 cl->state = MEI_FILE_UNINITIALIZED;
663 cl->writing_state = MEI_IDLE;
664
665 WARN_ON(!list_empty(&cl->rd_completed) ||
666 !list_empty(&cl->rd_pending) ||
667 !list_empty(&cl->link));
668
669 return 0;
670 }
671
672 void mei_host_client_init(struct mei_device *dev)
673 {
674 mei_set_devstate(dev, MEI_DEV_ENABLED);
675 dev->reset_count = 0;
676
677 schedule_work(&dev->bus_rescan_work);
678
679 pm_runtime_mark_last_busy(dev->dev);
680 dev_dbg(dev->dev, "rpm: autosuspend\n");
681 pm_request_autosuspend(dev->dev);
682 }
683
684
685
686
687
688
689
690 bool mei_hbuf_acquire(struct mei_device *dev)
691 {
692 if (mei_pg_state(dev) == MEI_PG_ON ||
693 mei_pg_in_transition(dev)) {
694 dev_dbg(dev->dev, "device is in pg\n");
695 return false;
696 }
697
698 if (!dev->hbuf_is_ready) {
699 dev_dbg(dev->dev, "hbuf is not ready\n");
700 return false;
701 }
702
703 dev->hbuf_is_ready = false;
704
705 return true;
706 }
707
708
709
710
711
712
713
714 static void mei_cl_wake_all(struct mei_cl *cl)
715 {
716 struct mei_device *dev = cl->dev;
717
718
719 if (waitqueue_active(&cl->rx_wait)) {
720 cl_dbg(dev, cl, "Waking up reading client!\n");
721 wake_up_interruptible(&cl->rx_wait);
722 }
723
724 if (waitqueue_active(&cl->tx_wait)) {
725 cl_dbg(dev, cl, "Waking up writing client!\n");
726 wake_up_interruptible(&cl->tx_wait);
727 }
728
729 if (waitqueue_active(&cl->ev_wait)) {
730 cl_dbg(dev, cl, "Waking up waiting for event clients!\n");
731 wake_up_interruptible(&cl->ev_wait);
732 }
733
734 if (waitqueue_active(&cl->wait)) {
735 cl_dbg(dev, cl, "Waking up ctrl write clients!\n");
736 wake_up(&cl->wait);
737 }
738 }
739
740
741
742
743
744
745
746 static void mei_cl_set_disconnected(struct mei_cl *cl)
747 {
748 struct mei_device *dev = cl->dev;
749
750 if (cl->state == MEI_FILE_DISCONNECTED ||
751 cl->state <= MEI_FILE_INITIALIZING)
752 return;
753
754 cl->state = MEI_FILE_DISCONNECTED;
755 mei_io_tx_list_free_cl(&dev->write_list, cl);
756 mei_io_tx_list_free_cl(&dev->write_waiting_list, cl);
757 mei_io_list_flush_cl(&dev->ctrl_rd_list, cl);
758 mei_io_list_flush_cl(&dev->ctrl_wr_list, cl);
759 mei_cl_wake_all(cl);
760 cl->rx_flow_ctrl_creds = 0;
761 cl->tx_flow_ctrl_creds = 0;
762 cl->timer_count = 0;
763
764 if (!cl->me_cl)
765 return;
766
767 if (!WARN_ON(cl->me_cl->connect_count == 0))
768 cl->me_cl->connect_count--;
769
770 if (cl->me_cl->connect_count == 0)
771 cl->me_cl->tx_flow_ctrl_creds = 0;
772
773 mei_me_cl_put(cl->me_cl);
774 cl->me_cl = NULL;
775 }
776
777 static int mei_cl_set_connecting(struct mei_cl *cl, struct mei_me_client *me_cl)
778 {
779 if (!mei_me_cl_get(me_cl))
780 return -ENOENT;
781
782
783 if (me_cl->props.fixed_address) {
784 if (me_cl->connect_count) {
785 mei_me_cl_put(me_cl);
786 return -EBUSY;
787 }
788 }
789
790 cl->me_cl = me_cl;
791 cl->state = MEI_FILE_CONNECTING;
792 cl->me_cl->connect_count++;
793
794 return 0;
795 }
796
797
798
799
800
801
802
803
804
805 static int mei_cl_send_disconnect(struct mei_cl *cl, struct mei_cl_cb *cb)
806 {
807 struct mei_device *dev;
808 int ret;
809
810 dev = cl->dev;
811
812 ret = mei_hbm_cl_disconnect_req(dev, cl);
813 cl->status = ret;
814 if (ret) {
815 cl->state = MEI_FILE_DISCONNECT_REPLY;
816 return ret;
817 }
818
819 list_move_tail(&cb->list, &dev->ctrl_rd_list);
820 cl->timer_count = MEI_CONNECT_TIMEOUT;
821 mei_schedule_stall_timer(dev);
822
823 return 0;
824 }
825
826
827
828
829
830
831
832
833
834
835
836 int mei_cl_irq_disconnect(struct mei_cl *cl, struct mei_cl_cb *cb,
837 struct list_head *cmpl_list)
838 {
839 struct mei_device *dev = cl->dev;
840 u32 msg_slots;
841 int slots;
842 int ret;
843
844 msg_slots = mei_hbm2slots(sizeof(struct hbm_client_connect_request));
845 slots = mei_hbuf_empty_slots(dev);
846 if (slots < 0)
847 return -EOVERFLOW;
848
849 if ((u32)slots < msg_slots)
850 return -EMSGSIZE;
851
852 ret = mei_cl_send_disconnect(cl, cb);
853 if (ret)
854 list_move_tail(&cb->list, cmpl_list);
855
856 return ret;
857 }
858
859
860
861
862
863
864
865
866
867 static int __mei_cl_disconnect(struct mei_cl *cl)
868 {
869 struct mei_device *dev;
870 struct mei_cl_cb *cb;
871 int rets;
872
873 dev = cl->dev;
874
875 cl->state = MEI_FILE_DISCONNECTING;
876
877 cb = mei_cl_enqueue_ctrl_wr_cb(cl, 0, MEI_FOP_DISCONNECT, NULL);
878 if (!cb) {
879 rets = -ENOMEM;
880 goto out;
881 }
882
883 if (mei_hbuf_acquire(dev)) {
884 rets = mei_cl_send_disconnect(cl, cb);
885 if (rets) {
886 cl_err(dev, cl, "failed to disconnect.\n");
887 goto out;
888 }
889 }
890
891 mutex_unlock(&dev->device_lock);
892 wait_event_timeout(cl->wait,
893 cl->state == MEI_FILE_DISCONNECT_REPLY ||
894 cl->state == MEI_FILE_DISCONNECTED,
895 mei_secs_to_jiffies(MEI_CL_CONNECT_TIMEOUT));
896 mutex_lock(&dev->device_lock);
897
898 rets = cl->status;
899 if (cl->state != MEI_FILE_DISCONNECT_REPLY &&
900 cl->state != MEI_FILE_DISCONNECTED) {
901 cl_dbg(dev, cl, "timeout on disconnect from FW client.\n");
902 rets = -ETIME;
903 }
904
905 out:
906
907 mei_cl_set_disconnected(cl);
908 if (!rets)
909 cl_dbg(dev, cl, "successfully disconnected from FW client.\n");
910
911 mei_io_cb_free(cb);
912 return rets;
913 }
914
915
916
917
918
919
920
921
922
923
924 int mei_cl_disconnect(struct mei_cl *cl)
925 {
926 struct mei_device *dev;
927 int rets;
928
929 if (WARN_ON(!cl || !cl->dev))
930 return -ENODEV;
931
932 dev = cl->dev;
933
934 cl_dbg(dev, cl, "disconnecting");
935
936 if (!mei_cl_is_connected(cl))
937 return 0;
938
939 if (mei_cl_is_fixed_address(cl)) {
940 mei_cl_set_disconnected(cl);
941 return 0;
942 }
943
944 if (dev->dev_state == MEI_DEV_POWER_DOWN) {
945 cl_dbg(dev, cl, "Device is powering down, don't bother with disconnection\n");
946 mei_cl_set_disconnected(cl);
947 return 0;
948 }
949
950 rets = pm_runtime_get(dev->dev);
951 if (rets < 0 && rets != -EINPROGRESS) {
952 pm_runtime_put_noidle(dev->dev);
953 cl_err(dev, cl, "rpm: get failed %d\n", rets);
954 return rets;
955 }
956
957 rets = __mei_cl_disconnect(cl);
958
959 cl_dbg(dev, cl, "rpm: autosuspend\n");
960 pm_runtime_mark_last_busy(dev->dev);
961 pm_runtime_put_autosuspend(dev->dev);
962
963 return rets;
964 }
965
966
967
968
969
970
971
972
973
974
975 static bool mei_cl_is_other_connecting(struct mei_cl *cl)
976 {
977 struct mei_device *dev;
978 struct mei_cl_cb *cb;
979
980 dev = cl->dev;
981
982 list_for_each_entry(cb, &dev->ctrl_rd_list, list) {
983 if (cb->fop_type == MEI_FOP_CONNECT &&
984 mei_cl_me_id(cl) == mei_cl_me_id(cb->cl))
985 return true;
986 }
987
988 return false;
989 }
990
991
992
993
994
995
996
997
998
999 static int mei_cl_send_connect(struct mei_cl *cl, struct mei_cl_cb *cb)
1000 {
1001 struct mei_device *dev;
1002 int ret;
1003
1004 dev = cl->dev;
1005
1006 ret = mei_hbm_cl_connect_req(dev, cl);
1007 cl->status = ret;
1008 if (ret) {
1009 cl->state = MEI_FILE_DISCONNECT_REPLY;
1010 return ret;
1011 }
1012
1013 list_move_tail(&cb->list, &dev->ctrl_rd_list);
1014 cl->timer_count = MEI_CONNECT_TIMEOUT;
1015 mei_schedule_stall_timer(dev);
1016 return 0;
1017 }
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028 int mei_cl_irq_connect(struct mei_cl *cl, struct mei_cl_cb *cb,
1029 struct list_head *cmpl_list)
1030 {
1031 struct mei_device *dev = cl->dev;
1032 u32 msg_slots;
1033 int slots;
1034 int rets;
1035
1036 if (mei_cl_is_other_connecting(cl))
1037 return 0;
1038
1039 msg_slots = mei_hbm2slots(sizeof(struct hbm_client_connect_request));
1040 slots = mei_hbuf_empty_slots(dev);
1041 if (slots < 0)
1042 return -EOVERFLOW;
1043
1044 if ((u32)slots < msg_slots)
1045 return -EMSGSIZE;
1046
1047 rets = mei_cl_send_connect(cl, cb);
1048 if (rets)
1049 list_move_tail(&cb->list, cmpl_list);
1050
1051 return rets;
1052 }
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065 int mei_cl_connect(struct mei_cl *cl, struct mei_me_client *me_cl,
1066 const struct file *fp)
1067 {
1068 struct mei_device *dev;
1069 struct mei_cl_cb *cb;
1070 int rets;
1071
1072 if (WARN_ON(!cl || !cl->dev || !me_cl))
1073 return -ENODEV;
1074
1075 dev = cl->dev;
1076
1077 rets = mei_cl_set_connecting(cl, me_cl);
1078 if (rets)
1079 goto nortpm;
1080
1081 if (mei_cl_is_fixed_address(cl)) {
1082 cl->state = MEI_FILE_CONNECTED;
1083 rets = 0;
1084 goto nortpm;
1085 }
1086
1087 rets = pm_runtime_get(dev->dev);
1088 if (rets < 0 && rets != -EINPROGRESS) {
1089 pm_runtime_put_noidle(dev->dev);
1090 cl_err(dev, cl, "rpm: get failed %d\n", rets);
1091 goto nortpm;
1092 }
1093
1094 cb = mei_cl_enqueue_ctrl_wr_cb(cl, 0, MEI_FOP_CONNECT, fp);
1095 if (!cb) {
1096 rets = -ENOMEM;
1097 goto out;
1098 }
1099
1100
1101 if (!mei_cl_is_other_connecting(cl) && mei_hbuf_acquire(dev)) {
1102 rets = mei_cl_send_connect(cl, cb);
1103 if (rets)
1104 goto out;
1105 }
1106
1107 mutex_unlock(&dev->device_lock);
1108 wait_event_timeout(cl->wait,
1109 (cl->state == MEI_FILE_CONNECTED ||
1110 cl->state == MEI_FILE_DISCONNECTED ||
1111 cl->state == MEI_FILE_DISCONNECT_REQUIRED ||
1112 cl->state == MEI_FILE_DISCONNECT_REPLY),
1113 mei_secs_to_jiffies(MEI_CL_CONNECT_TIMEOUT));
1114 mutex_lock(&dev->device_lock);
1115
1116 if (!mei_cl_is_connected(cl)) {
1117 if (cl->state == MEI_FILE_DISCONNECT_REQUIRED) {
1118 mei_io_list_flush_cl(&dev->ctrl_rd_list, cl);
1119 mei_io_list_flush_cl(&dev->ctrl_wr_list, cl);
1120
1121
1122
1123 __mei_cl_disconnect(cl);
1124 rets = -EFAULT;
1125 goto out;
1126 }
1127
1128
1129 if (!cl->status)
1130 cl->status = -EFAULT;
1131 }
1132
1133 rets = cl->status;
1134 out:
1135 cl_dbg(dev, cl, "rpm: autosuspend\n");
1136 pm_runtime_mark_last_busy(dev->dev);
1137 pm_runtime_put_autosuspend(dev->dev);
1138
1139 mei_io_cb_free(cb);
1140
1141 nortpm:
1142 if (!mei_cl_is_connected(cl))
1143 mei_cl_set_disconnected(cl);
1144
1145 return rets;
1146 }
1147
1148
1149
1150
1151
1152
1153
1154
1155 struct mei_cl *mei_cl_alloc_linked(struct mei_device *dev)
1156 {
1157 struct mei_cl *cl;
1158 int ret;
1159
1160 cl = mei_cl_allocate(dev);
1161 if (!cl) {
1162 ret = -ENOMEM;
1163 goto err;
1164 }
1165
1166 ret = mei_cl_link(cl);
1167 if (ret)
1168 goto err;
1169
1170 return cl;
1171 err:
1172 kfree(cl);
1173 return ERR_PTR(ret);
1174 }
1175
1176
1177
1178
1179
1180
1181
1182
1183 static int mei_cl_tx_flow_ctrl_creds(struct mei_cl *cl)
1184 {
1185 if (WARN_ON(!cl || !cl->me_cl))
1186 return -EINVAL;
1187
1188 if (cl->tx_flow_ctrl_creds > 0)
1189 return 1;
1190
1191 if (mei_cl_is_fixed_address(cl))
1192 return 1;
1193
1194 if (mei_cl_is_single_recv_buf(cl)) {
1195 if (cl->me_cl->tx_flow_ctrl_creds > 0)
1196 return 1;
1197 }
1198 return 0;
1199 }
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211 static int mei_cl_tx_flow_ctrl_creds_reduce(struct mei_cl *cl)
1212 {
1213 if (WARN_ON(!cl || !cl->me_cl))
1214 return -EINVAL;
1215
1216 if (mei_cl_is_fixed_address(cl))
1217 return 0;
1218
1219 if (mei_cl_is_single_recv_buf(cl)) {
1220 if (WARN_ON(cl->me_cl->tx_flow_ctrl_creds <= 0))
1221 return -EINVAL;
1222 cl->me_cl->tx_flow_ctrl_creds--;
1223 } else {
1224 if (WARN_ON(cl->tx_flow_ctrl_creds <= 0))
1225 return -EINVAL;
1226 cl->tx_flow_ctrl_creds--;
1227 }
1228 return 0;
1229 }
1230
1231
1232
1233
1234
1235
1236
1237
1238 u8 mei_cl_notify_fop2req(enum mei_cb_file_ops fop)
1239 {
1240 if (fop == MEI_FOP_NOTIFY_START)
1241 return MEI_HBM_NOTIFICATION_START;
1242 else
1243 return MEI_HBM_NOTIFICATION_STOP;
1244 }
1245
1246
1247
1248
1249
1250
1251
1252
1253 enum mei_cb_file_ops mei_cl_notify_req2fop(u8 req)
1254 {
1255 if (req == MEI_HBM_NOTIFICATION_START)
1256 return MEI_FOP_NOTIFY_START;
1257 else
1258 return MEI_FOP_NOTIFY_STOP;
1259 }
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270 int mei_cl_irq_notify(struct mei_cl *cl, struct mei_cl_cb *cb,
1271 struct list_head *cmpl_list)
1272 {
1273 struct mei_device *dev = cl->dev;
1274 u32 msg_slots;
1275 int slots;
1276 int ret;
1277 bool request;
1278
1279 msg_slots = mei_hbm2slots(sizeof(struct hbm_client_connect_request));
1280 slots = mei_hbuf_empty_slots(dev);
1281 if (slots < 0)
1282 return -EOVERFLOW;
1283
1284 if ((u32)slots < msg_slots)
1285 return -EMSGSIZE;
1286
1287 request = mei_cl_notify_fop2req(cb->fop_type);
1288 ret = mei_hbm_cl_notify_req(dev, cl, request);
1289 if (ret) {
1290 cl->status = ret;
1291 list_move_tail(&cb->list, cmpl_list);
1292 return ret;
1293 }
1294
1295 list_move_tail(&cb->list, &dev->ctrl_rd_list);
1296 return 0;
1297 }
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310 int mei_cl_notify_request(struct mei_cl *cl,
1311 const struct file *fp, u8 request)
1312 {
1313 struct mei_device *dev;
1314 struct mei_cl_cb *cb;
1315 enum mei_cb_file_ops fop_type;
1316 int rets;
1317
1318 if (WARN_ON(!cl || !cl->dev))
1319 return -ENODEV;
1320
1321 dev = cl->dev;
1322
1323 if (!dev->hbm_f_ev_supported) {
1324 cl_dbg(dev, cl, "notifications not supported\n");
1325 return -EOPNOTSUPP;
1326 }
1327
1328 if (!mei_cl_is_connected(cl))
1329 return -ENODEV;
1330
1331 rets = pm_runtime_get(dev->dev);
1332 if (rets < 0 && rets != -EINPROGRESS) {
1333 pm_runtime_put_noidle(dev->dev);
1334 cl_err(dev, cl, "rpm: get failed %d\n", rets);
1335 return rets;
1336 }
1337
1338 fop_type = mei_cl_notify_req2fop(request);
1339 cb = mei_cl_enqueue_ctrl_wr_cb(cl, 0, fop_type, fp);
1340 if (!cb) {
1341 rets = -ENOMEM;
1342 goto out;
1343 }
1344
1345 if (mei_hbuf_acquire(dev)) {
1346 if (mei_hbm_cl_notify_req(dev, cl, request)) {
1347 rets = -ENODEV;
1348 goto out;
1349 }
1350 list_move_tail(&cb->list, &dev->ctrl_rd_list);
1351 }
1352
1353 mutex_unlock(&dev->device_lock);
1354 wait_event_timeout(cl->wait,
1355 cl->notify_en == request ||
1356 cl->status ||
1357 !mei_cl_is_connected(cl),
1358 mei_secs_to_jiffies(MEI_CL_CONNECT_TIMEOUT));
1359 mutex_lock(&dev->device_lock);
1360
1361 if (cl->notify_en != request && !cl->status)
1362 cl->status = -EFAULT;
1363
1364 rets = cl->status;
1365
1366 out:
1367 cl_dbg(dev, cl, "rpm: autosuspend\n");
1368 pm_runtime_mark_last_busy(dev->dev);
1369 pm_runtime_put_autosuspend(dev->dev);
1370
1371 mei_io_cb_free(cb);
1372 return rets;
1373 }
1374
1375
1376
1377
1378
1379
1380
1381
1382 void mei_cl_notify(struct mei_cl *cl)
1383 {
1384 struct mei_device *dev;
1385
1386 if (!cl || !cl->dev)
1387 return;
1388
1389 dev = cl->dev;
1390
1391 if (!cl->notify_en)
1392 return;
1393
1394 cl_dbg(dev, cl, "notify event");
1395 cl->notify_ev = true;
1396 if (!mei_cl_bus_notify_event(cl))
1397 wake_up_interruptible(&cl->ev_wait);
1398
1399 if (cl->ev_async)
1400 kill_fasync(&cl->ev_async, SIGIO, POLL_PRI);
1401
1402 }
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415 int mei_cl_notify_get(struct mei_cl *cl, bool block, bool *notify_ev)
1416 {
1417 struct mei_device *dev;
1418 int rets;
1419
1420 *notify_ev = false;
1421
1422 if (WARN_ON(!cl || !cl->dev))
1423 return -ENODEV;
1424
1425 dev = cl->dev;
1426
1427 if (!dev->hbm_f_ev_supported) {
1428 cl_dbg(dev, cl, "notifications not supported\n");
1429 return -EOPNOTSUPP;
1430 }
1431
1432 if (!mei_cl_is_connected(cl))
1433 return -ENODEV;
1434
1435 if (cl->notify_ev)
1436 goto out;
1437
1438 if (!block)
1439 return -EAGAIN;
1440
1441 mutex_unlock(&dev->device_lock);
1442 rets = wait_event_interruptible(cl->ev_wait, cl->notify_ev);
1443 mutex_lock(&dev->device_lock);
1444
1445 if (rets < 0)
1446 return rets;
1447
1448 out:
1449 *notify_ev = cl->notify_ev;
1450 cl->notify_ev = false;
1451 return 0;
1452 }
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463 int mei_cl_read_start(struct mei_cl *cl, size_t length, const struct file *fp)
1464 {
1465 struct mei_device *dev;
1466 struct mei_cl_cb *cb;
1467 int rets;
1468
1469 if (WARN_ON(!cl || !cl->dev))
1470 return -ENODEV;
1471
1472 dev = cl->dev;
1473
1474 if (!mei_cl_is_connected(cl))
1475 return -ENODEV;
1476
1477 if (!mei_me_cl_is_active(cl->me_cl)) {
1478 cl_err(dev, cl, "no such me client\n");
1479 return -ENOTTY;
1480 }
1481
1482 if (mei_cl_is_fixed_address(cl))
1483 return 0;
1484
1485
1486 if (cl->rx_flow_ctrl_creds)
1487 return -EBUSY;
1488
1489 cb = mei_cl_enqueue_ctrl_wr_cb(cl, length, MEI_FOP_READ, fp);
1490 if (!cb)
1491 return -ENOMEM;
1492
1493 rets = pm_runtime_get(dev->dev);
1494 if (rets < 0 && rets != -EINPROGRESS) {
1495 pm_runtime_put_noidle(dev->dev);
1496 cl_err(dev, cl, "rpm: get failed %d\n", rets);
1497 goto nortpm;
1498 }
1499
1500 rets = 0;
1501 if (mei_hbuf_acquire(dev)) {
1502 rets = mei_hbm_cl_flow_control_req(dev, cl);
1503 if (rets < 0)
1504 goto out;
1505
1506 list_move_tail(&cb->list, &cl->rd_pending);
1507 }
1508 cl->rx_flow_ctrl_creds++;
1509
1510 out:
1511 cl_dbg(dev, cl, "rpm: autosuspend\n");
1512 pm_runtime_mark_last_busy(dev->dev);
1513 pm_runtime_put_autosuspend(dev->dev);
1514 nortpm:
1515 if (rets)
1516 mei_io_cb_free(cb);
1517
1518 return rets;
1519 }
1520
1521
1522
1523
1524
1525
1526
1527 static void mei_msg_hdr_init(struct mei_msg_hdr *mei_hdr, struct mei_cl_cb *cb)
1528 {
1529 mei_hdr->host_addr = mei_cl_host_addr(cb->cl);
1530 mei_hdr->me_addr = mei_cl_me_id(cb->cl);
1531 mei_hdr->length = 0;
1532 mei_hdr->reserved = 0;
1533 mei_hdr->msg_complete = 0;
1534 mei_hdr->dma_ring = 0;
1535 mei_hdr->internal = cb->internal;
1536 }
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548 int mei_cl_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb,
1549 struct list_head *cmpl_list)
1550 {
1551 struct mei_device *dev;
1552 struct mei_msg_data *buf;
1553 struct mei_msg_hdr mei_hdr;
1554 size_t hdr_len = sizeof(mei_hdr);
1555 size_t len;
1556 size_t hbuf_len, dr_len;
1557 int hbuf_slots;
1558 u32 dr_slots;
1559 u32 dma_len;
1560 int rets;
1561 bool first_chunk;
1562 const void *data;
1563
1564 if (WARN_ON(!cl || !cl->dev))
1565 return -ENODEV;
1566
1567 dev = cl->dev;
1568
1569 buf = &cb->buf;
1570
1571 first_chunk = cb->buf_idx == 0;
1572
1573 rets = first_chunk ? mei_cl_tx_flow_ctrl_creds(cl) : 1;
1574 if (rets < 0)
1575 goto err;
1576
1577 if (rets == 0) {
1578 cl_dbg(dev, cl, "No flow control credentials: not sending.\n");
1579 return 0;
1580 }
1581
1582 len = buf->size - cb->buf_idx;
1583 data = buf->data + cb->buf_idx;
1584 hbuf_slots = mei_hbuf_empty_slots(dev);
1585 if (hbuf_slots < 0) {
1586 rets = -EOVERFLOW;
1587 goto err;
1588 }
1589
1590 hbuf_len = mei_slots2data(hbuf_slots);
1591 dr_slots = mei_dma_ring_empty_slots(dev);
1592 dr_len = mei_slots2data(dr_slots);
1593
1594 mei_msg_hdr_init(&mei_hdr, cb);
1595
1596
1597
1598
1599
1600 if (len + hdr_len <= hbuf_len) {
1601 mei_hdr.length = len;
1602 mei_hdr.msg_complete = 1;
1603 } else if (dr_slots && hbuf_len >= hdr_len + sizeof(dma_len)) {
1604 mei_hdr.dma_ring = 1;
1605 if (len > dr_len)
1606 len = dr_len;
1607 else
1608 mei_hdr.msg_complete = 1;
1609
1610 mei_hdr.length = sizeof(dma_len);
1611 dma_len = len;
1612 data = &dma_len;
1613 } else if ((u32)hbuf_slots == mei_hbuf_depth(dev)) {
1614 len = hbuf_len - hdr_len;
1615 mei_hdr.length = len;
1616 } else {
1617 return 0;
1618 }
1619
1620 if (mei_hdr.dma_ring)
1621 mei_dma_ring_write(dev, buf->data + cb->buf_idx, len);
1622
1623 rets = mei_write_message(dev, &mei_hdr, hdr_len, data, mei_hdr.length);
1624 if (rets)
1625 goto err;
1626
1627 cl->status = 0;
1628 cl->writing_state = MEI_WRITING;
1629 cb->buf_idx += len;
1630
1631 if (first_chunk) {
1632 if (mei_cl_tx_flow_ctrl_creds_reduce(cl)) {
1633 rets = -EIO;
1634 goto err;
1635 }
1636 }
1637
1638 if (mei_hdr.msg_complete)
1639 list_move_tail(&cb->list, &dev->write_waiting_list);
1640
1641 return 0;
1642
1643 err:
1644 cl->status = rets;
1645 list_move_tail(&cb->list, cmpl_list);
1646 return rets;
1647 }
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658 ssize_t mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb)
1659 {
1660 struct mei_device *dev;
1661 struct mei_msg_data *buf;
1662 struct mei_msg_hdr mei_hdr;
1663 size_t hdr_len = sizeof(mei_hdr);
1664 size_t len, hbuf_len, dr_len;
1665 int hbuf_slots;
1666 u32 dr_slots;
1667 u32 dma_len;
1668 ssize_t rets;
1669 bool blocking;
1670 const void *data;
1671
1672 if (WARN_ON(!cl || !cl->dev))
1673 return -ENODEV;
1674
1675 if (WARN_ON(!cb))
1676 return -EINVAL;
1677
1678 dev = cl->dev;
1679
1680 buf = &cb->buf;
1681 len = buf->size;
1682
1683 cl_dbg(dev, cl, "len=%zd\n", len);
1684
1685 blocking = cb->blocking;
1686 data = buf->data;
1687
1688 rets = pm_runtime_get(dev->dev);
1689 if (rets < 0 && rets != -EINPROGRESS) {
1690 pm_runtime_put_noidle(dev->dev);
1691 cl_err(dev, cl, "rpm: get failed %zd\n", rets);
1692 goto free;
1693 }
1694
1695 cb->buf_idx = 0;
1696 cl->writing_state = MEI_IDLE;
1697
1698
1699 rets = mei_cl_tx_flow_ctrl_creds(cl);
1700 if (rets < 0)
1701 goto err;
1702
1703 mei_msg_hdr_init(&mei_hdr, cb);
1704
1705 if (rets == 0) {
1706 cl_dbg(dev, cl, "No flow control credentials: not sending.\n");
1707 rets = len;
1708 goto out;
1709 }
1710
1711 if (!mei_hbuf_acquire(dev)) {
1712 cl_dbg(dev, cl, "Cannot acquire the host buffer: not sending.\n");
1713 rets = len;
1714 goto out;
1715 }
1716
1717 hbuf_slots = mei_hbuf_empty_slots(dev);
1718 if (hbuf_slots < 0) {
1719 rets = -EOVERFLOW;
1720 goto out;
1721 }
1722
1723 hbuf_len = mei_slots2data(hbuf_slots);
1724 dr_slots = mei_dma_ring_empty_slots(dev);
1725 dr_len = mei_slots2data(dr_slots);
1726
1727 if (len + hdr_len <= hbuf_len) {
1728 mei_hdr.length = len;
1729 mei_hdr.msg_complete = 1;
1730 } else if (dr_slots && hbuf_len >= hdr_len + sizeof(dma_len)) {
1731 mei_hdr.dma_ring = 1;
1732 if (len > dr_len)
1733 len = dr_len;
1734 else
1735 mei_hdr.msg_complete = 1;
1736
1737 mei_hdr.length = sizeof(dma_len);
1738 dma_len = len;
1739 data = &dma_len;
1740 } else {
1741 len = hbuf_len - hdr_len;
1742 mei_hdr.length = len;
1743 }
1744
1745 if (mei_hdr.dma_ring)
1746 mei_dma_ring_write(dev, buf->data, len);
1747
1748 rets = mei_write_message(dev, &mei_hdr, hdr_len,
1749 data, mei_hdr.length);
1750 if (rets)
1751 goto err;
1752
1753 rets = mei_cl_tx_flow_ctrl_creds_reduce(cl);
1754 if (rets)
1755 goto err;
1756
1757 cl->writing_state = MEI_WRITING;
1758 cb->buf_idx = len;
1759
1760 len = buf->size;
1761
1762 out:
1763 if (mei_hdr.msg_complete)
1764 mei_tx_cb_enqueue(cb, &dev->write_waiting_list);
1765 else
1766 mei_tx_cb_enqueue(cb, &dev->write_list);
1767
1768 cb = NULL;
1769 if (blocking && cl->writing_state != MEI_WRITE_COMPLETE) {
1770
1771 mutex_unlock(&dev->device_lock);
1772 rets = wait_event_interruptible(cl->tx_wait,
1773 cl->writing_state == MEI_WRITE_COMPLETE ||
1774 (!mei_cl_is_connected(cl)));
1775 mutex_lock(&dev->device_lock);
1776
1777 if (rets) {
1778 if (signal_pending(current))
1779 rets = -EINTR;
1780 goto err;
1781 }
1782 if (cl->writing_state != MEI_WRITE_COMPLETE) {
1783 rets = -EFAULT;
1784 goto err;
1785 }
1786 }
1787
1788 rets = len;
1789 err:
1790 cl_dbg(dev, cl, "rpm: autosuspend\n");
1791 pm_runtime_mark_last_busy(dev->dev);
1792 pm_runtime_put_autosuspend(dev->dev);
1793 free:
1794 mei_io_cb_free(cb);
1795
1796 return rets;
1797 }
1798
1799
1800
1801
1802
1803
1804
1805
1806 void mei_cl_complete(struct mei_cl *cl, struct mei_cl_cb *cb)
1807 {
1808 struct mei_device *dev = cl->dev;
1809
1810 switch (cb->fop_type) {
1811 case MEI_FOP_WRITE:
1812 mei_tx_cb_dequeue(cb);
1813 cl->writing_state = MEI_WRITE_COMPLETE;
1814 if (waitqueue_active(&cl->tx_wait)) {
1815 wake_up_interruptible(&cl->tx_wait);
1816 } else {
1817 pm_runtime_mark_last_busy(dev->dev);
1818 pm_request_autosuspend(dev->dev);
1819 }
1820 break;
1821
1822 case MEI_FOP_READ:
1823 list_add_tail(&cb->list, &cl->rd_completed);
1824 if (!mei_cl_is_fixed_address(cl) &&
1825 !WARN_ON(!cl->rx_flow_ctrl_creds))
1826 cl->rx_flow_ctrl_creds--;
1827 if (!mei_cl_bus_rx_event(cl))
1828 wake_up_interruptible(&cl->rx_wait);
1829 break;
1830
1831 case MEI_FOP_CONNECT:
1832 case MEI_FOP_DISCONNECT:
1833 case MEI_FOP_NOTIFY_STOP:
1834 case MEI_FOP_NOTIFY_START:
1835 if (waitqueue_active(&cl->wait))
1836 wake_up(&cl->wait);
1837
1838 break;
1839 case MEI_FOP_DISCONNECT_RSP:
1840 mei_io_cb_free(cb);
1841 mei_cl_set_disconnected(cl);
1842 break;
1843 default:
1844 BUG_ON(0);
1845 }
1846 }
1847
1848
1849
1850
1851
1852
1853
1854 void mei_cl_all_disconnect(struct mei_device *dev)
1855 {
1856 struct mei_cl *cl;
1857
1858 list_for_each_entry(cl, &dev->file_list, link)
1859 mei_cl_set_disconnected(cl);
1860 }