This source file includes following definitions.
- mei_secs_to_jiffies
- mei_data2slots
- mei_hbm2slots
- mei_slots2data
- mei_hw_config
- mei_pg_in_transition
- mei_pg_is_enabled
- mei_hw_reset
- mei_hw_start
- mei_clear_interrupts
- mei_enable_interrupts
- mei_disable_interrupts
- mei_synchronize_irq
- mei_host_is_ready
- mei_hw_is_ready
- mei_hbuf_is_ready
- mei_hbuf_empty_slots
- mei_hbuf_depth
- mei_write_message
- mei_read_hdr
- mei_read_slots
- mei_count_full_read_slots
- mei_fw_status
- mei_dbgfs_register
- mei_dbgfs_deregister
- mei_fw_status_str
1
2
3
4
5
6
7 #ifndef _MEI_DEV_H_
8 #define _MEI_DEV_H_
9
10 #include <linux/types.h>
11 #include <linux/cdev.h>
12 #include <linux/poll.h>
13 #include <linux/mei.h>
14 #include <linux/mei_cl_bus.h>
15
16 #include "hw.h"
17 #include "hbm.h"
18
19 #define MEI_SLOT_SIZE sizeof(u32)
20 #define MEI_RD_MSG_BUF_SIZE (128 * MEI_SLOT_SIZE)
21
22
23
24
25 #define MEI_CLIENTS_MAX 256
26
27
28
29
30 #define MEI_MAX_CONSEC_RESET 3
31
32
33
34
35
36
37
38
39 #define MEI_MAX_OPEN_HANDLE_COUNT (MEI_CLIENTS_MAX - 1)
40
41
42 enum file_state {
43 MEI_FILE_UNINITIALIZED = 0,
44 MEI_FILE_INITIALIZING,
45 MEI_FILE_CONNECTING,
46 MEI_FILE_CONNECTED,
47 MEI_FILE_DISCONNECTING,
48 MEI_FILE_DISCONNECT_REPLY,
49 MEI_FILE_DISCONNECT_REQUIRED,
50 MEI_FILE_DISCONNECTED,
51 };
52
53
54 enum mei_dev_state {
55 MEI_DEV_INITIALIZING = 0,
56 MEI_DEV_INIT_CLIENTS,
57 MEI_DEV_ENABLED,
58 MEI_DEV_RESETTING,
59 MEI_DEV_DISABLED,
60 MEI_DEV_POWER_DOWN,
61 MEI_DEV_POWER_UP
62 };
63
64 const char *mei_dev_state_str(int state);
65
66 enum mei_file_transaction_states {
67 MEI_IDLE,
68 MEI_WRITING,
69 MEI_WRITE_COMPLETE,
70 };
71
72
73
74
75
76
77
78
79
80
81
82 enum mei_cb_file_ops {
83 MEI_FOP_READ = 0,
84 MEI_FOP_WRITE,
85 MEI_FOP_CONNECT,
86 MEI_FOP_DISCONNECT,
87 MEI_FOP_DISCONNECT_RSP,
88 MEI_FOP_NOTIFY_START,
89 MEI_FOP_NOTIFY_STOP,
90 };
91
92
93
94
95
96
97
98
99
100 enum mei_cl_io_mode {
101 MEI_CL_IO_TX_BLOCKING = BIT(0),
102 MEI_CL_IO_TX_INTERNAL = BIT(1),
103
104 MEI_CL_IO_RX_NONBLOCK = BIT(2),
105 };
106
107
108
109
110 struct mei_msg_data {
111 size_t size;
112 unsigned char *data;
113 };
114
115
116
117
118
119
120
121
122 struct mei_dma_dscr {
123 void *vaddr;
124 dma_addr_t daddr;
125 size_t size;
126 };
127
128
129 #define MEI_FW_STATUS_MAX 6
130
131 #define MEI_FW_STATUS_STR_SZ (MEI_FW_STATUS_MAX * (8 + 1))
132
133
134
135
136
137
138
139
140 struct mei_fw_status {
141 int count;
142 u32 status[MEI_FW_STATUS_MAX];
143 };
144
145
146
147
148
149
150
151
152
153
154
155
156 struct mei_me_client {
157 struct list_head list;
158 struct kref refcnt;
159 struct mei_client_properties props;
160 u8 client_id;
161 u8 tx_flow_ctrl_creds;
162 u8 connect_count;
163 u8 bus_added;
164 };
165
166
167 struct mei_cl;
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182 struct mei_cl_cb {
183 struct list_head list;
184 struct mei_cl *cl;
185 enum mei_cb_file_ops fop_type;
186 struct mei_msg_data buf;
187 size_t buf_idx;
188 const struct file *fp;
189 int status;
190 u32 internal:1;
191 u32 blocking:1;
192 };
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222 struct mei_cl {
223 struct list_head link;
224 struct mei_device *dev;
225 enum file_state state;
226 wait_queue_head_t tx_wait;
227 wait_queue_head_t rx_wait;
228 wait_queue_head_t wait;
229 wait_queue_head_t ev_wait;
230 struct fasync_struct *ev_async;
231 int status;
232 struct mei_me_client *me_cl;
233 const struct file *fp;
234 u8 host_client_id;
235 u8 tx_flow_ctrl_creds;
236 u8 rx_flow_ctrl_creds;
237 u8 timer_count;
238 u8 notify_en;
239 u8 notify_ev;
240 u8 tx_cb_queued;
241 enum mei_file_transaction_states writing_state;
242 struct list_head rd_pending;
243 struct list_head rd_completed;
244
245 struct mei_cl_device *cldev;
246 };
247
248 #define MEI_TX_QUEUE_LIMIT_DEFAULT 50
249 #define MEI_TX_QUEUE_LIMIT_MAX 255
250 #define MEI_TX_QUEUE_LIMIT_MIN 30
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283 struct mei_hw_ops {
284
285 bool (*host_is_ready)(struct mei_device *dev);
286
287 bool (*hw_is_ready)(struct mei_device *dev);
288 int (*hw_reset)(struct mei_device *dev, bool enable);
289 int (*hw_start)(struct mei_device *dev);
290 void (*hw_config)(struct mei_device *dev);
291
292 int (*fw_status)(struct mei_device *dev, struct mei_fw_status *fw_sts);
293 enum mei_pg_state (*pg_state)(struct mei_device *dev);
294 bool (*pg_in_transition)(struct mei_device *dev);
295 bool (*pg_is_enabled)(struct mei_device *dev);
296
297 void (*intr_clear)(struct mei_device *dev);
298 void (*intr_enable)(struct mei_device *dev);
299 void (*intr_disable)(struct mei_device *dev);
300 void (*synchronize_irq)(struct mei_device *dev);
301
302 int (*hbuf_free_slots)(struct mei_device *dev);
303 bool (*hbuf_is_ready)(struct mei_device *dev);
304 u32 (*hbuf_depth)(const struct mei_device *dev);
305 int (*write)(struct mei_device *dev,
306 const void *hdr, size_t hdr_len,
307 const void *data, size_t data_len);
308
309 int (*rdbuf_full_slots)(struct mei_device *dev);
310
311 u32 (*read_hdr)(const struct mei_device *dev);
312 int (*read)(struct mei_device *dev,
313 unsigned char *buf, unsigned long len);
314 };
315
316
317 void mei_cl_bus_rescan_work(struct work_struct *work);
318 void mei_cl_bus_dev_fixup(struct mei_cl_device *dev);
319 ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,
320 unsigned int mode);
321 ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length,
322 unsigned int mode, unsigned long timeout);
323 bool mei_cl_bus_rx_event(struct mei_cl *cl);
324 bool mei_cl_bus_notify_event(struct mei_cl *cl);
325 void mei_cl_bus_remove_devices(struct mei_device *bus);
326 int mei_cl_bus_init(void);
327 void mei_cl_bus_exit(void);
328
329
330
331
332
333
334
335
336
337
338 enum mei_pg_event {
339 MEI_PG_EVENT_IDLE,
340 MEI_PG_EVENT_WAIT,
341 MEI_PG_EVENT_RECEIVED,
342 MEI_PG_EVENT_INTR_WAIT,
343 MEI_PG_EVENT_INTR_RECEIVED,
344 };
345
346
347
348
349
350
351
352 enum mei_pg_state {
353 MEI_PG_OFF = 0,
354 MEI_PG_ON = 1,
355 };
356
357 const char *mei_pg_state_str(enum mei_pg_state state);
358
359
360
361
362
363
364
365
366
367
368 struct mei_fw_version {
369 u8 platform;
370 u8 major;
371 u16 minor;
372 u16 buildno;
373 u16 hotfix;
374 };
375
376 #define MEI_MAX_FW_VER_BLOCKS 3
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450 struct mei_device {
451 struct device *dev;
452 struct cdev cdev;
453 int minor;
454
455 struct list_head write_list;
456 struct list_head write_waiting_list;
457 struct list_head ctrl_wr_list;
458 struct list_head ctrl_rd_list;
459 u8 tx_queue_limit;
460
461 struct list_head file_list;
462 long open_handle_count;
463
464 struct mutex device_lock;
465 struct delayed_work timer_work;
466
467 bool recvd_hw_ready;
468
469
470
471 wait_queue_head_t wait_hw_ready;
472 wait_queue_head_t wait_pg;
473 wait_queue_head_t wait_hbm_start;
474
475
476
477
478 unsigned long reset_count;
479 enum mei_dev_state dev_state;
480 enum mei_hbm_state hbm_state;
481 u16 init_clients_timer;
482
483
484
485
486 enum mei_pg_event pg_event;
487 #ifdef CONFIG_PM
488 struct dev_pm_domain pg_domain;
489 #endif
490
491 unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE];
492 u32 rd_msg_hdr[MEI_MSG_HDR_MAX];
493
494
495 bool hbuf_is_ready;
496
497 struct mei_dma_dscr dr_dscr[DMA_DSCR_NUM];
498
499 struct hbm_version version;
500 unsigned int hbm_f_pg_supported:1;
501 unsigned int hbm_f_dc_supported:1;
502 unsigned int hbm_f_dot_supported:1;
503 unsigned int hbm_f_ev_supported:1;
504 unsigned int hbm_f_fa_supported:1;
505 unsigned int hbm_f_ie_supported:1;
506 unsigned int hbm_f_os_supported:1;
507 unsigned int hbm_f_dr_supported:1;
508
509 struct mei_fw_version fw_ver[MEI_MAX_FW_VER_BLOCKS];
510
511 unsigned int fw_f_fw_ver_supported:1;
512
513 struct rw_semaphore me_clients_rwsem;
514 struct list_head me_clients;
515 DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
516 DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
517
518 bool allow_fixed_address;
519 bool override_fixed_address;
520
521 struct work_struct reset_work;
522 struct work_struct bus_rescan_work;
523
524
525 struct list_head device_list;
526 struct mutex cl_bus_lock;
527
528 #if IS_ENABLED(CONFIG_DEBUG_FS)
529 struct dentry *dbgfs_dir;
530 #endif
531
532 const struct mei_hw_ops *ops;
533 char hw[0] __aligned(sizeof(void *));
534 };
535
536 static inline unsigned long mei_secs_to_jiffies(unsigned long sec)
537 {
538 return msecs_to_jiffies(sec * MSEC_PER_SEC);
539 }
540
541
542
543
544
545
546
547
548 static inline u32 mei_data2slots(size_t length)
549 {
550 return DIV_ROUND_UP(length, MEI_SLOT_SIZE);
551 }
552
553
554
555
556
557
558
559
560
561 static inline u32 mei_hbm2slots(size_t length)
562 {
563 return DIV_ROUND_UP(sizeof(struct mei_msg_hdr) + length, MEI_SLOT_SIZE);
564 }
565
566
567
568
569
570
571
572
573 static inline u32 mei_slots2data(int slots)
574 {
575 return slots * MEI_SLOT_SIZE;
576 }
577
578
579
580
581 void mei_device_init(struct mei_device *dev,
582 struct device *device,
583 const struct mei_hw_ops *hw_ops);
584 int mei_reset(struct mei_device *dev);
585 int mei_start(struct mei_device *dev);
586 int mei_restart(struct mei_device *dev);
587 void mei_stop(struct mei_device *dev);
588 void mei_cancel_work(struct mei_device *dev);
589
590 void mei_set_devstate(struct mei_device *dev, enum mei_dev_state state);
591
592 int mei_dmam_ring_alloc(struct mei_device *dev);
593 void mei_dmam_ring_free(struct mei_device *dev);
594 bool mei_dma_ring_is_allocated(struct mei_device *dev);
595 void mei_dma_ring_reset(struct mei_device *dev);
596 void mei_dma_ring_read(struct mei_device *dev, unsigned char *buf, u32 len);
597 void mei_dma_ring_write(struct mei_device *dev, unsigned char *buf, u32 len);
598 u32 mei_dma_ring_empty_slots(struct mei_device *dev);
599
600
601
602
603
604 void mei_timer(struct work_struct *work);
605 void mei_schedule_stall_timer(struct mei_device *dev);
606 int mei_irq_read_handler(struct mei_device *dev,
607 struct list_head *cmpl_list, s32 *slots);
608
609 int mei_irq_write_handler(struct mei_device *dev, struct list_head *cmpl_list);
610 void mei_irq_compl_handler(struct mei_device *dev, struct list_head *cmpl_list);
611
612
613
614
615
616
617 static inline void mei_hw_config(struct mei_device *dev)
618 {
619 dev->ops->hw_config(dev);
620 }
621
622 static inline enum mei_pg_state mei_pg_state(struct mei_device *dev)
623 {
624 return dev->ops->pg_state(dev);
625 }
626
627 static inline bool mei_pg_in_transition(struct mei_device *dev)
628 {
629 return dev->ops->pg_in_transition(dev);
630 }
631
632 static inline bool mei_pg_is_enabled(struct mei_device *dev)
633 {
634 return dev->ops->pg_is_enabled(dev);
635 }
636
637 static inline int mei_hw_reset(struct mei_device *dev, bool enable)
638 {
639 return dev->ops->hw_reset(dev, enable);
640 }
641
642 static inline int mei_hw_start(struct mei_device *dev)
643 {
644 return dev->ops->hw_start(dev);
645 }
646
647 static inline void mei_clear_interrupts(struct mei_device *dev)
648 {
649 dev->ops->intr_clear(dev);
650 }
651
652 static inline void mei_enable_interrupts(struct mei_device *dev)
653 {
654 dev->ops->intr_enable(dev);
655 }
656
657 static inline void mei_disable_interrupts(struct mei_device *dev)
658 {
659 dev->ops->intr_disable(dev);
660 }
661
662 static inline void mei_synchronize_irq(struct mei_device *dev)
663 {
664 dev->ops->synchronize_irq(dev);
665 }
666
667 static inline bool mei_host_is_ready(struct mei_device *dev)
668 {
669 return dev->ops->host_is_ready(dev);
670 }
671 static inline bool mei_hw_is_ready(struct mei_device *dev)
672 {
673 return dev->ops->hw_is_ready(dev);
674 }
675
676 static inline bool mei_hbuf_is_ready(struct mei_device *dev)
677 {
678 return dev->ops->hbuf_is_ready(dev);
679 }
680
681 static inline int mei_hbuf_empty_slots(struct mei_device *dev)
682 {
683 return dev->ops->hbuf_free_slots(dev);
684 }
685
686 static inline u32 mei_hbuf_depth(const struct mei_device *dev)
687 {
688 return dev->ops->hbuf_depth(dev);
689 }
690
691 static inline int mei_write_message(struct mei_device *dev,
692 const void *hdr, size_t hdr_len,
693 const void *data, size_t data_len)
694 {
695 return dev->ops->write(dev, hdr, hdr_len, data, data_len);
696 }
697
698 static inline u32 mei_read_hdr(const struct mei_device *dev)
699 {
700 return dev->ops->read_hdr(dev);
701 }
702
703 static inline void mei_read_slots(struct mei_device *dev,
704 unsigned char *buf, unsigned long len)
705 {
706 dev->ops->read(dev, buf, len);
707 }
708
709 static inline int mei_count_full_read_slots(struct mei_device *dev)
710 {
711 return dev->ops->rdbuf_full_slots(dev);
712 }
713
714 static inline int mei_fw_status(struct mei_device *dev,
715 struct mei_fw_status *fw_status)
716 {
717 return dev->ops->fw_status(dev, fw_status);
718 }
719
720 bool mei_hbuf_acquire(struct mei_device *dev);
721
722 bool mei_write_is_idle(struct mei_device *dev);
723
724 #if IS_ENABLED(CONFIG_DEBUG_FS)
725 void mei_dbgfs_register(struct mei_device *dev, const char *name);
726 void mei_dbgfs_deregister(struct mei_device *dev);
727 #else
728 static inline void mei_dbgfs_register(struct mei_device *dev, const char *name) {}
729 static inline void mei_dbgfs_deregister(struct mei_device *dev) {}
730 #endif
731
732 int mei_register(struct mei_device *dev, struct device *parent);
733 void mei_deregister(struct mei_device *dev);
734
735 #define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d dma=%1d internal=%1d comp=%1d"
736 #define MEI_HDR_PRM(hdr) \
737 (hdr)->host_addr, (hdr)->me_addr, \
738 (hdr)->length, (hdr)->dma_ring, (hdr)->internal, (hdr)->msg_complete
739
740 ssize_t mei_fw_status2str(struct mei_fw_status *fw_sts, char *buf, size_t len);
741
742
743
744
745
746
747
748
749
750 static inline ssize_t mei_fw_status_str(struct mei_device *dev,
751 char *buf, size_t len)
752 {
753 struct mei_fw_status fw_status;
754 int ret;
755
756 buf[0] = '\0';
757
758 ret = mei_fw_status(dev, &fw_status);
759 if (ret)
760 return ret;
761
762 ret = mei_fw_status2str(&fw_status, buf, MEI_FW_STATUS_STR_SZ);
763
764 return ret;
765 }
766
767
768 #endif