1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright (c) 2003-2019, Intel Corporation. All rights reserved.
4 * Intel Management Engine Interface (Intel MEI) Linux driver
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 * Number of Maximum MEI Clients
24 */
25 #define MEI_CLIENTS_MAX 256
26
27 /*
28 * maximum number of consecutive resets
29 */
30 #define MEI_MAX_CONSEC_RESET 3
31
32 /*
33 * Number of File descriptors/handles
34 * that can be opened to the driver.
35 *
36 * Limit to 255: 256 Total Clients
37 * minus internal client for MEI Bus Messages
38 */
39 #define MEI_MAX_OPEN_HANDLE_COUNT (MEI_CLIENTS_MAX - 1)
40
41 /* File state */
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 /* MEI device states */
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_POWERING_DOWN,
61 MEI_DEV_POWER_DOWN,
62 MEI_DEV_POWER_UP
63 };
64
65 const char *mei_dev_state_str(int state);
66
67 enum mei_file_transaction_states {
68 MEI_IDLE,
69 MEI_WRITING,
70 MEI_WRITE_COMPLETE,
71 };
72
73 /**
74 * enum mei_cb_file_ops - file operation associated with the callback
75 * @MEI_FOP_READ: read
76 * @MEI_FOP_WRITE: write
77 * @MEI_FOP_CONNECT: connect
78 * @MEI_FOP_DISCONNECT: disconnect
79 * @MEI_FOP_DISCONNECT_RSP: disconnect response
80 * @MEI_FOP_NOTIFY_START: start notification
81 * @MEI_FOP_NOTIFY_STOP: stop notification
82 * @MEI_FOP_DMA_MAP: request client dma map
83 * @MEI_FOP_DMA_UNMAP: request client dma unmap
84 */
85 enum mei_cb_file_ops {
86 MEI_FOP_READ = 0,
87 MEI_FOP_WRITE,
88 MEI_FOP_CONNECT,
89 MEI_FOP_DISCONNECT,
90 MEI_FOP_DISCONNECT_RSP,
91 MEI_FOP_NOTIFY_START,
92 MEI_FOP_NOTIFY_STOP,
93 MEI_FOP_DMA_MAP,
94 MEI_FOP_DMA_UNMAP,
95 };
96
97 /**
98 * enum mei_cl_io_mode - io mode between driver and fw
99 *
100 * @MEI_CL_IO_TX_BLOCKING: send is blocking
101 * @MEI_CL_IO_TX_INTERNAL: internal communication between driver and FW
102 *
103 * @MEI_CL_IO_RX_NONBLOCK: recv is non-blocking
104 */
105 enum mei_cl_io_mode {
106 MEI_CL_IO_TX_BLOCKING = BIT(0),
107 MEI_CL_IO_TX_INTERNAL = BIT(1),
108
109 MEI_CL_IO_RX_NONBLOCK = BIT(2),
110 };
111
112 /*
113 * Intel MEI message data struct
114 */
115 struct mei_msg_data {
116 size_t size;
117 unsigned char *data;
118 };
119
120 struct mei_dma_data {
121 u8 buffer_id;
122 void *vaddr;
123 dma_addr_t daddr;
124 size_t size;
125 };
126
127 /**
128 * struct mei_dma_dscr - dma address descriptor
129 *
130 * @vaddr: dma buffer virtual address
131 * @daddr: dma buffer physical address
132 * @size : dma buffer size
133 */
134 struct mei_dma_dscr {
135 void *vaddr;
136 dma_addr_t daddr;
137 size_t size;
138 };
139
140 /* Maximum number of processed FW status registers */
141 #define MEI_FW_STATUS_MAX 6
142 /* Minimal buffer for FW status string (8 bytes in dw + space or '\0') */
143 #define MEI_FW_STATUS_STR_SZ (MEI_FW_STATUS_MAX * (8 + 1))
144
145
146 /*
147 * struct mei_fw_status - storage of FW status data
148 *
149 * @count: number of actually available elements in array
150 * @status: FW status registers
151 */
152 struct mei_fw_status {
153 int count;
154 u32 status[MEI_FW_STATUS_MAX];
155 };
156
157 /**
158 * struct mei_me_client - representation of me (fw) client
159 *
160 * @list: link in me client list
161 * @refcnt: struct reference count
162 * @props: client properties
163 * @client_id: me client id
164 * @tx_flow_ctrl_creds: flow control credits
165 * @connect_count: number connections to this client
166 * @bus_added: added to bus
167 */
168 struct mei_me_client {
169 struct list_head list;
170 struct kref refcnt;
171 struct mei_client_properties props;
172 u8 client_id;
173 u8 tx_flow_ctrl_creds;
174 u8 connect_count;
175 u8 bus_added;
176 };
177
178
179 struct mei_cl;
180
181 /**
182 * struct mei_cl_cb - file operation callback structure
183 *
184 * @list: link in callback queue
185 * @cl: file client who is running this operation
186 * @fop_type: file operation type
187 * @buf: buffer for data associated with the callback
188 * @buf_idx: last read index
189 * @vtag: virtual tag
190 * @fp: pointer to file structure
191 * @status: io status of the cb
192 * @internal: communication between driver and FW flag
193 * @blocking: transmission blocking mode
194 */
195 struct mei_cl_cb {
196 struct list_head list;
197 struct mei_cl *cl;
198 enum mei_cb_file_ops fop_type;
199 struct mei_msg_data buf;
200 size_t buf_idx;
201 u8 vtag;
202 const struct file *fp;
203 int status;
204 u32 internal:1;
205 u32 blocking:1;
206 };
207
208 /**
209 * struct mei_cl_vtag - file pointer to vtag mapping structure
210 *
211 * @list: link in map queue
212 * @fp: file pointer
213 * @vtag: corresponding vtag
214 * @pending_read: the read is pending on this file
215 */
216 struct mei_cl_vtag {
217 struct list_head list;
218 const struct file *fp;
219 u8 vtag;
220 u8 pending_read:1;
221 };
222
223 /**
224 * struct mei_cl - me client host representation
225 * carried in file->private_data
226 *
227 * @link: link in the clients list
228 * @dev: mei parent device
229 * @state: file operation state
230 * @tx_wait: wait queue for tx completion
231 * @rx_wait: wait queue for rx completion
232 * @wait: wait queue for management operation
233 * @ev_wait: notification wait queue
234 * @ev_async: event async notification
235 * @status: connection status
236 * @me_cl: fw client connected
237 * @fp: file associated with client
238 * @host_client_id: host id
239 * @vtag_map: vtag map
240 * @tx_flow_ctrl_creds: transmit flow credentials
241 * @rx_flow_ctrl_creds: receive flow credentials
242 * @timer_count: watchdog timer for operation completion
243 * @notify_en: notification - enabled/disabled
244 * @notify_ev: pending notification event
245 * @tx_cb_queued: number of tx callbacks in queue
246 * @writing_state: state of the tx
247 * @rd_pending: pending read credits
248 * @rd_completed_lock: protects rd_completed queue
249 * @rd_completed: completed read
250 * @dma: dma settings
251 * @dma_mapped: dma buffer is currently mapped.
252 *
253 * @cldev: device on the mei client bus
254 */
255 struct mei_cl {
256 struct list_head link;
257 struct mei_device *dev;
258 enum file_state state;
259 wait_queue_head_t tx_wait;
260 wait_queue_head_t rx_wait;
261 wait_queue_head_t wait;
262 wait_queue_head_t ev_wait;
263 struct fasync_struct *ev_async;
264 int status;
265 struct mei_me_client *me_cl;
266 const struct file *fp;
267 u8 host_client_id;
268 struct list_head vtag_map;
269 u8 tx_flow_ctrl_creds;
270 u8 rx_flow_ctrl_creds;
271 u8 timer_count;
272 u8 notify_en;
273 u8 notify_ev;
274 u8 tx_cb_queued;
275 enum mei_file_transaction_states writing_state;
276 struct list_head rd_pending;
277 spinlock_t rd_completed_lock; /* protects rd_completed queue */
278 struct list_head rd_completed;
279 struct mei_dma_data dma;
280 u8 dma_mapped;
281
282 struct mei_cl_device *cldev;
283 };
284
285 #define MEI_TX_QUEUE_LIMIT_DEFAULT 50
286 #define MEI_TX_QUEUE_LIMIT_MAX 255
287 #define MEI_TX_QUEUE_LIMIT_MIN 30
288
289 /**
290 * struct mei_hw_ops - hw specific ops
291 *
292 * @host_is_ready : query for host readiness
293 *
294 * @hw_is_ready : query if hw is ready
295 * @hw_reset : reset hw
296 * @hw_start : start hw after reset
297 * @hw_config : configure hw
298 *
299 * @fw_status : get fw status registers
300 * @trc_status : get trc status register
301 * @pg_state : power gating state of the device
302 * @pg_in_transition : is device now in pg transition
303 * @pg_is_enabled : is power gating enabled
304 *
305 * @intr_clear : clear pending interrupts
306 * @intr_enable : enable interrupts
307 * @intr_disable : disable interrupts
308 * @synchronize_irq : synchronize irqs
309 *
310 * @hbuf_free_slots : query for write buffer empty slots
311 * @hbuf_is_ready : query if write buffer is empty
312 * @hbuf_depth : query for write buffer depth
313 *
314 * @write : write a message to FW
315 *
316 * @rdbuf_full_slots : query how many slots are filled
317 *
318 * @read_hdr : get first 4 bytes (header)
319 * @read : read a buffer from the FW
320 */
321 struct mei_hw_ops {
322
323 bool (*host_is_ready)(struct mei_device *dev);
324
325 bool (*hw_is_ready)(struct mei_device *dev);
326 int (*hw_reset)(struct mei_device *dev, bool enable);
327 int (*hw_start)(struct mei_device *dev);
328 int (*hw_config)(struct mei_device *dev);
329
330 int (*fw_status)(struct mei_device *dev, struct mei_fw_status *fw_sts);
331 int (*trc_status)(struct mei_device *dev, u32 *trc);
332
333 enum mei_pg_state (*pg_state)(struct mei_device *dev);
334 bool (*pg_in_transition)(struct mei_device *dev);
335 bool (*pg_is_enabled)(struct mei_device *dev);
336
337 void (*intr_clear)(struct mei_device *dev);
338 void (*intr_enable)(struct mei_device *dev);
339 void (*intr_disable)(struct mei_device *dev);
340 void (*synchronize_irq)(struct mei_device *dev);
341
342 int (*hbuf_free_slots)(struct mei_device *dev);
343 bool (*hbuf_is_ready)(struct mei_device *dev);
344 u32 (*hbuf_depth)(const struct mei_device *dev);
345 int (*write)(struct mei_device *dev,
346 const void *hdr, size_t hdr_len,
347 const void *data, size_t data_len);
348
349 int (*rdbuf_full_slots)(struct mei_device *dev);
350
351 u32 (*read_hdr)(const struct mei_device *dev);
352 int (*read)(struct mei_device *dev,
353 unsigned char *buf, unsigned long len);
354 };
355
356 /* MEI bus API*/
357 void mei_cl_bus_rescan_work(struct work_struct *work);
358 void mei_cl_bus_dev_fixup(struct mei_cl_device *dev);
359 ssize_t __mei_cl_send(struct mei_cl *cl, const u8 *buf, size_t length, u8 vtag,
360 unsigned int mode);
361 ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length, u8 *vtag,
362 unsigned int mode, unsigned long timeout);
363 bool mei_cl_bus_rx_event(struct mei_cl *cl);
364 bool mei_cl_bus_notify_event(struct mei_cl *cl);
365 void mei_cl_bus_remove_devices(struct mei_device *bus);
366 int mei_cl_bus_init(void);
367 void mei_cl_bus_exit(void);
368
369 /**
370 * enum mei_pg_event - power gating transition events
371 *
372 * @MEI_PG_EVENT_IDLE: the driver is not in power gating transition
373 * @MEI_PG_EVENT_WAIT: the driver is waiting for a pg event to complete
374 * @MEI_PG_EVENT_RECEIVED: the driver received pg event
375 * @MEI_PG_EVENT_INTR_WAIT: the driver is waiting for a pg event interrupt
376 * @MEI_PG_EVENT_INTR_RECEIVED: the driver received pg event interrupt
377 */
378 enum mei_pg_event {
379 MEI_PG_EVENT_IDLE,
380 MEI_PG_EVENT_WAIT,
381 MEI_PG_EVENT_RECEIVED,
382 MEI_PG_EVENT_INTR_WAIT,
383 MEI_PG_EVENT_INTR_RECEIVED,
384 };
385
386 /**
387 * enum mei_pg_state - device internal power gating state
388 *
389 * @MEI_PG_OFF: device is not power gated - it is active
390 * @MEI_PG_ON: device is power gated - it is in lower power state
391 */
392 enum mei_pg_state {
393 MEI_PG_OFF = 0,
394 MEI_PG_ON = 1,
395 };
396
397 const char *mei_pg_state_str(enum mei_pg_state state);
398
399 /**
400 * struct mei_fw_version - MEI FW version struct
401 *
402 * @platform: platform identifier
403 * @major: major version field
404 * @minor: minor version field
405 * @buildno: build number version field
406 * @hotfix: hotfix number version field
407 */
408 struct mei_fw_version {
409 u8 platform;
410 u8 major;
411 u16 minor;
412 u16 buildno;
413 u16 hotfix;
414 };
415
416 #define MEI_MAX_FW_VER_BLOCKS 3
417
418 /**
419 * struct mei_device - MEI private device struct
420 *
421 * @dev : device on a bus
422 * @cdev : character device
423 * @minor : minor number allocated for device
424 *
425 * @write_list : write pending list
426 * @write_waiting_list : write completion list
427 * @ctrl_wr_list : pending control write list
428 * @ctrl_rd_list : pending control read list
429 * @tx_queue_limit: tx queues per client linit
430 *
431 * @file_list : list of opened handles
432 * @open_handle_count: number of opened handles
433 *
434 * @device_lock : big device lock
435 * @timer_work : MEI timer delayed work (timeouts)
436 *
437 * @recvd_hw_ready : hw ready message received flag
438 *
439 * @wait_hw_ready : wait queue for receive HW ready message form FW
440 * @wait_pg : wait queue for receive PG message from FW
441 * @wait_hbm_start : wait queue for receive HBM start message from FW
442 *
443 * @reset_count : number of consecutive resets
444 * @dev_state : device state
445 * @hbm_state : state of host bus message protocol
446 * @init_clients_timer : HBM init handshake timeout
447 *
448 * @pg_event : power gating event
449 * @pg_domain : runtime PM domain
450 *
451 * @rd_msg_buf : control messages buffer
452 * @rd_msg_hdr : read message header storage
453 * @rd_msg_hdr_count : how many dwords were already read from header
454 *
455 * @hbuf_is_ready : query if the host host/write buffer is ready
456 * @dr_dscr: DMA ring descriptors: TX, RX, and CTRL
457 *
458 * @version : HBM protocol version in use
459 * @hbm_f_pg_supported : hbm feature pgi protocol
460 * @hbm_f_dc_supported : hbm feature dynamic clients
461 * @hbm_f_dot_supported : hbm feature disconnect on timeout
462 * @hbm_f_ev_supported : hbm feature event notification
463 * @hbm_f_fa_supported : hbm feature fixed address client
464 * @hbm_f_ie_supported : hbm feature immediate reply to enum request
465 * @hbm_f_os_supported : hbm feature support OS ver message
466 * @hbm_f_dr_supported : hbm feature dma ring supported
467 * @hbm_f_vt_supported : hbm feature vtag supported
468 * @hbm_f_cap_supported : hbm feature capabilities message supported
469 * @hbm_f_cd_supported : hbm feature client dma supported
470 *
471 * @fw_ver : FW versions
472 *
473 * @fw_f_fw_ver_supported : fw feature: fw version supported
474 *
475 * @me_clients_rwsem: rw lock over me_clients list
476 * @me_clients : list of FW clients
477 * @me_clients_map : FW clients bit map
478 * @host_clients_map : host clients id pool
479 *
480 * @allow_fixed_address: allow user space to connect a fixed client
481 * @override_fixed_address: force allow fixed address behavior
482 *
483 * @reset_work : work item for the device reset
484 * @bus_rescan_work : work item for the bus rescan
485 *
486 * @device_list : mei client bus list
487 * @cl_bus_lock : client bus list lock
488 *
489 * @kind : kind of mei device
490 *
491 * @dbgfs_dir : debugfs mei root directory
492 *
493 * @ops: : hw specific operations
494 * @hw : hw specific data
495 */
496 struct mei_device {
497 struct device *dev;
498 struct cdev cdev;
499 int minor;
500
501 struct list_head write_list;
502 struct list_head write_waiting_list;
503 struct list_head ctrl_wr_list;
504 struct list_head ctrl_rd_list;
505 u8 tx_queue_limit;
506
507 struct list_head file_list;
508 long open_handle_count;
509
510 struct mutex device_lock;
511 struct delayed_work timer_work;
512
513 bool recvd_hw_ready;
514 /*
515 * waiting queue for receive message from FW
516 */
517 wait_queue_head_t wait_hw_ready;
518 wait_queue_head_t wait_pg;
519 wait_queue_head_t wait_hbm_start;
520
521 /*
522 * mei device states
523 */
524 unsigned long reset_count;
525 enum mei_dev_state dev_state;
526 enum mei_hbm_state hbm_state;
527 u16 init_clients_timer;
528
529 /*
530 * Power Gating support
531 */
532 enum mei_pg_event pg_event;
533 #ifdef CONFIG_PM
534 struct dev_pm_domain pg_domain;
535 #endif /* CONFIG_PM */
536
537 unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE];
538 u32 rd_msg_hdr[MEI_RD_MSG_BUF_SIZE];
539 int rd_msg_hdr_count;
540
541 /* write buffer */
542 bool hbuf_is_ready;
543
544 struct mei_dma_dscr dr_dscr[DMA_DSCR_NUM];
545
546 struct hbm_version version;
547 unsigned int hbm_f_pg_supported:1;
548 unsigned int hbm_f_dc_supported:1;
549 unsigned int hbm_f_dot_supported:1;
550 unsigned int hbm_f_ev_supported:1;
551 unsigned int hbm_f_fa_supported:1;
552 unsigned int hbm_f_ie_supported:1;
553 unsigned int hbm_f_os_supported:1;
554 unsigned int hbm_f_dr_supported:1;
555 unsigned int hbm_f_vt_supported:1;
556 unsigned int hbm_f_cap_supported:1;
557 unsigned int hbm_f_cd_supported:1;
558
559 struct mei_fw_version fw_ver[MEI_MAX_FW_VER_BLOCKS];
560
561 unsigned int fw_f_fw_ver_supported:1;
562
563 struct rw_semaphore me_clients_rwsem;
564 struct list_head me_clients;
565 DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
566 DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
567
568 bool allow_fixed_address;
569 bool override_fixed_address;
570
571 struct work_struct reset_work;
572 struct work_struct bus_rescan_work;
573
574 /* List of bus devices */
575 struct list_head device_list;
576 struct mutex cl_bus_lock;
577
578 const char *kind;
579
580 #if IS_ENABLED(CONFIG_DEBUG_FS)
581 struct dentry *dbgfs_dir;
582 #endif /* CONFIG_DEBUG_FS */
583
584 const struct mei_hw_ops *ops;
585 char hw[] __aligned(sizeof(void *));
586 };
587
mei_secs_to_jiffies(unsigned long sec)588 static inline unsigned long mei_secs_to_jiffies(unsigned long sec)
589 {
590 return msecs_to_jiffies(sec * MSEC_PER_SEC);
591 }
592
593 /**
594 * mei_data2slots - get slots number from a message length
595 *
596 * @length: size of the messages in bytes
597 *
598 * Return: number of slots
599 */
mei_data2slots(size_t length)600 static inline u32 mei_data2slots(size_t length)
601 {
602 return DIV_ROUND_UP(length, MEI_SLOT_SIZE);
603 }
604
605 /**
606 * mei_hbm2slots - get slots number from a hbm message length
607 * length + size of the mei message header
608 *
609 * @length: size of the messages in bytes
610 *
611 * Return: number of slots
612 */
mei_hbm2slots(size_t length)613 static inline u32 mei_hbm2slots(size_t length)
614 {
615 return DIV_ROUND_UP(sizeof(struct mei_msg_hdr) + length, MEI_SLOT_SIZE);
616 }
617
618 /**
619 * mei_slots2data - get data in slots - bytes from slots
620 *
621 * @slots: number of available slots
622 *
623 * Return: number of bytes in slots
624 */
mei_slots2data(int slots)625 static inline u32 mei_slots2data(int slots)
626 {
627 return slots * MEI_SLOT_SIZE;
628 }
629
630 /*
631 * mei init function prototypes
632 */
633 void mei_device_init(struct mei_device *dev,
634 struct device *device,
635 const struct mei_hw_ops *hw_ops);
636 int mei_reset(struct mei_device *dev);
637 int mei_start(struct mei_device *dev);
638 int mei_restart(struct mei_device *dev);
639 void mei_stop(struct mei_device *dev);
640 void mei_cancel_work(struct mei_device *dev);
641
642 void mei_set_devstate(struct mei_device *dev, enum mei_dev_state state);
643
644 int mei_dmam_ring_alloc(struct mei_device *dev);
645 void mei_dmam_ring_free(struct mei_device *dev);
646 bool mei_dma_ring_is_allocated(struct mei_device *dev);
647 void mei_dma_ring_reset(struct mei_device *dev);
648 void mei_dma_ring_read(struct mei_device *dev, unsigned char *buf, u32 len);
649 void mei_dma_ring_write(struct mei_device *dev, unsigned char *buf, u32 len);
650 u32 mei_dma_ring_empty_slots(struct mei_device *dev);
651
652 /*
653 * MEI interrupt functions prototype
654 */
655
656 void mei_timer(struct work_struct *work);
657 void mei_schedule_stall_timer(struct mei_device *dev);
658 int mei_irq_read_handler(struct mei_device *dev,
659 struct list_head *cmpl_list, s32 *slots);
660
661 int mei_irq_write_handler(struct mei_device *dev, struct list_head *cmpl_list);
662 void mei_irq_compl_handler(struct mei_device *dev, struct list_head *cmpl_list);
663
664 /*
665 * Register Access Function
666 */
667
668
mei_hw_config(struct mei_device * dev)669 static inline int mei_hw_config(struct mei_device *dev)
670 {
671 return dev->ops->hw_config(dev);
672 }
673
mei_pg_state(struct mei_device * dev)674 static inline enum mei_pg_state mei_pg_state(struct mei_device *dev)
675 {
676 return dev->ops->pg_state(dev);
677 }
678
mei_pg_in_transition(struct mei_device * dev)679 static inline bool mei_pg_in_transition(struct mei_device *dev)
680 {
681 return dev->ops->pg_in_transition(dev);
682 }
683
mei_pg_is_enabled(struct mei_device * dev)684 static inline bool mei_pg_is_enabled(struct mei_device *dev)
685 {
686 return dev->ops->pg_is_enabled(dev);
687 }
688
mei_hw_reset(struct mei_device * dev,bool enable)689 static inline int mei_hw_reset(struct mei_device *dev, bool enable)
690 {
691 return dev->ops->hw_reset(dev, enable);
692 }
693
mei_hw_start(struct mei_device * dev)694 static inline int mei_hw_start(struct mei_device *dev)
695 {
696 return dev->ops->hw_start(dev);
697 }
698
mei_clear_interrupts(struct mei_device * dev)699 static inline void mei_clear_interrupts(struct mei_device *dev)
700 {
701 dev->ops->intr_clear(dev);
702 }
703
mei_enable_interrupts(struct mei_device * dev)704 static inline void mei_enable_interrupts(struct mei_device *dev)
705 {
706 dev->ops->intr_enable(dev);
707 }
708
mei_disable_interrupts(struct mei_device * dev)709 static inline void mei_disable_interrupts(struct mei_device *dev)
710 {
711 dev->ops->intr_disable(dev);
712 }
713
mei_synchronize_irq(struct mei_device * dev)714 static inline void mei_synchronize_irq(struct mei_device *dev)
715 {
716 dev->ops->synchronize_irq(dev);
717 }
718
mei_host_is_ready(struct mei_device * dev)719 static inline bool mei_host_is_ready(struct mei_device *dev)
720 {
721 return dev->ops->host_is_ready(dev);
722 }
mei_hw_is_ready(struct mei_device * dev)723 static inline bool mei_hw_is_ready(struct mei_device *dev)
724 {
725 return dev->ops->hw_is_ready(dev);
726 }
727
mei_hbuf_is_ready(struct mei_device * dev)728 static inline bool mei_hbuf_is_ready(struct mei_device *dev)
729 {
730 return dev->ops->hbuf_is_ready(dev);
731 }
732
mei_hbuf_empty_slots(struct mei_device * dev)733 static inline int mei_hbuf_empty_slots(struct mei_device *dev)
734 {
735 return dev->ops->hbuf_free_slots(dev);
736 }
737
mei_hbuf_depth(const struct mei_device * dev)738 static inline u32 mei_hbuf_depth(const struct mei_device *dev)
739 {
740 return dev->ops->hbuf_depth(dev);
741 }
742
mei_write_message(struct mei_device * dev,const void * hdr,size_t hdr_len,const void * data,size_t data_len)743 static inline int mei_write_message(struct mei_device *dev,
744 const void *hdr, size_t hdr_len,
745 const void *data, size_t data_len)
746 {
747 return dev->ops->write(dev, hdr, hdr_len, data, data_len);
748 }
749
mei_read_hdr(const struct mei_device * dev)750 static inline u32 mei_read_hdr(const struct mei_device *dev)
751 {
752 return dev->ops->read_hdr(dev);
753 }
754
mei_read_slots(struct mei_device * dev,unsigned char * buf,unsigned long len)755 static inline void mei_read_slots(struct mei_device *dev,
756 unsigned char *buf, unsigned long len)
757 {
758 dev->ops->read(dev, buf, len);
759 }
760
mei_count_full_read_slots(struct mei_device * dev)761 static inline int mei_count_full_read_slots(struct mei_device *dev)
762 {
763 return dev->ops->rdbuf_full_slots(dev);
764 }
765
mei_trc_status(struct mei_device * dev,u32 * trc)766 static inline int mei_trc_status(struct mei_device *dev, u32 *trc)
767 {
768 if (dev->ops->trc_status)
769 return dev->ops->trc_status(dev, trc);
770 return -EOPNOTSUPP;
771 }
772
mei_fw_status(struct mei_device * dev,struct mei_fw_status * fw_status)773 static inline int mei_fw_status(struct mei_device *dev,
774 struct mei_fw_status *fw_status)
775 {
776 return dev->ops->fw_status(dev, fw_status);
777 }
778
779 bool mei_hbuf_acquire(struct mei_device *dev);
780
781 bool mei_write_is_idle(struct mei_device *dev);
782
783 #if IS_ENABLED(CONFIG_DEBUG_FS)
784 void mei_dbgfs_register(struct mei_device *dev, const char *name);
785 void mei_dbgfs_deregister(struct mei_device *dev);
786 #else
mei_dbgfs_register(struct mei_device * dev,const char * name)787 static inline void mei_dbgfs_register(struct mei_device *dev, const char *name) {}
mei_dbgfs_deregister(struct mei_device * dev)788 static inline void mei_dbgfs_deregister(struct mei_device *dev) {}
789 #endif /* CONFIG_DEBUG_FS */
790
791 int mei_register(struct mei_device *dev, struct device *parent);
792 void mei_deregister(struct mei_device *dev);
793
794 #define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d dma=%1d ext=%1d internal=%1d comp=%1d"
795 #define MEI_HDR_PRM(hdr) \
796 (hdr)->host_addr, (hdr)->me_addr, \
797 (hdr)->length, (hdr)->dma_ring, (hdr)->extended, \
798 (hdr)->internal, (hdr)->msg_complete
799
800 ssize_t mei_fw_status2str(struct mei_fw_status *fw_sts, char *buf, size_t len);
801 /**
802 * mei_fw_status_str - fetch and convert fw status registers to printable string
803 *
804 * @dev: the device structure
805 * @buf: string buffer at minimal size MEI_FW_STATUS_STR_SZ
806 * @len: buffer len must be >= MEI_FW_STATUS_STR_SZ
807 *
808 * Return: number of bytes written or < 0 on failure
809 */
mei_fw_status_str(struct mei_device * dev,char * buf,size_t len)810 static inline ssize_t mei_fw_status_str(struct mei_device *dev,
811 char *buf, size_t len)
812 {
813 struct mei_fw_status fw_status;
814 int ret;
815
816 buf[0] = '\0';
817
818 ret = mei_fw_status(dev, &fw_status);
819 if (ret)
820 return ret;
821
822 ret = mei_fw_status2str(&fw_status, buf, MEI_FW_STATUS_STR_SZ);
823
824 return ret;
825 }
826
827
828 #endif
829