batman-adv: Decrease hardif refcnt on fragmentation send error
[linux-2.6-block.git] / drivers / misc / mei / mei_dev.h
1 /*
2  *
3  * Intel Management Engine Interface (Intel MEI) Linux driver
4  * Copyright (c) 2003-2012, Intel Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  */
16
17 #ifndef _MEI_DEV_H_
18 #define _MEI_DEV_H_
19
20 #include <linux/types.h>
21 #include <linux/cdev.h>
22 #include <linux/poll.h>
23 #include <linux/mei.h>
24 #include <linux/mei_cl_bus.h>
25
26 #include "hw.h"
27 #include "hbm.h"
28
29
30 /*
31  * AMTHI Client UUID
32  */
33 extern const uuid_le mei_amthif_guid;
34
35 #define MEI_RD_MSG_BUF_SIZE           (128 * sizeof(u32))
36
37 /*
38  * Number of Maximum MEI Clients
39  */
40 #define MEI_CLIENTS_MAX 256
41
42 /*
43  * maximum number of consecutive resets
44  */
45 #define MEI_MAX_CONSEC_RESET  3
46
47 /*
48  * Number of File descriptors/handles
49  * that can be opened to the driver.
50  *
51  * Limit to 255: 256 Total Clients
52  * minus internal client for MEI Bus Messages
53  */
54 #define  MEI_MAX_OPEN_HANDLE_COUNT (MEI_CLIENTS_MAX - 1)
55
56 /* File state */
57 enum file_state {
58         MEI_FILE_UNINITIALIZED = 0,
59         MEI_FILE_INITIALIZING,
60         MEI_FILE_CONNECTING,
61         MEI_FILE_CONNECTED,
62         MEI_FILE_DISCONNECTING,
63         MEI_FILE_DISCONNECT_REPLY,
64         MEI_FILE_DISCONNECT_REQUIRED,
65         MEI_FILE_DISCONNECTED,
66 };
67
68 /* MEI device states */
69 enum mei_dev_state {
70         MEI_DEV_INITIALIZING = 0,
71         MEI_DEV_INIT_CLIENTS,
72         MEI_DEV_ENABLED,
73         MEI_DEV_RESETTING,
74         MEI_DEV_DISABLED,
75         MEI_DEV_POWER_DOWN,
76         MEI_DEV_POWER_UP
77 };
78
79 const char *mei_dev_state_str(int state);
80
81 enum iamthif_states {
82         MEI_IAMTHIF_IDLE,
83         MEI_IAMTHIF_WRITING,
84         MEI_IAMTHIF_READING,
85 };
86
87 enum mei_file_transaction_states {
88         MEI_IDLE,
89         MEI_WRITING,
90         MEI_WRITE_COMPLETE,
91 };
92
93 /**
94  * enum mei_cb_file_ops  - file operation associated with the callback
95  * @MEI_FOP_READ:       read
96  * @MEI_FOP_WRITE:      write
97  * @MEI_FOP_CONNECT:    connect
98  * @MEI_FOP_DISCONNECT: disconnect
99  * @MEI_FOP_DISCONNECT_RSP: disconnect response
100  * @MEI_FOP_NOTIFY_START:   start notification
101  * @MEI_FOP_NOTIFY_STOP:    stop notification
102  */
103 enum mei_cb_file_ops {
104         MEI_FOP_READ = 0,
105         MEI_FOP_WRITE,
106         MEI_FOP_CONNECT,
107         MEI_FOP_DISCONNECT,
108         MEI_FOP_DISCONNECT_RSP,
109         MEI_FOP_NOTIFY_START,
110         MEI_FOP_NOTIFY_STOP,
111 };
112
113 /**
114  * enum mei_cl_io_mode - io mode between driver and fw
115  *
116  * @MEI_CL_IO_TX_BLOCKING: send is blocking
117  * @MEI_CL_IO_TX_INTERNAL: internal communication between driver and FW
118  *
119  * @MEI_CL_IO_RX_NONBLOCK: recv is non-blocking
120  */
121 enum mei_cl_io_mode {
122         MEI_CL_IO_TX_BLOCKING = BIT(0),
123         MEI_CL_IO_TX_INTERNAL = BIT(1),
124
125         MEI_CL_IO_RX_NONBLOCK = BIT(2),
126 };
127
128 /*
129  * Intel MEI message data struct
130  */
131 struct mei_msg_data {
132         size_t size;
133         unsigned char *data;
134 };
135
136 /* Maximum number of processed FW status registers */
137 #define MEI_FW_STATUS_MAX 6
138 /* Minimal  buffer for FW status string (8 bytes in dw + space or '\0') */
139 #define MEI_FW_STATUS_STR_SZ (MEI_FW_STATUS_MAX * (8 + 1))
140
141
142 /*
143  * struct mei_fw_status - storage of FW status data
144  *
145  * @count: number of actually available elements in array
146  * @status: FW status registers
147  */
148 struct mei_fw_status {
149         int count;
150         u32 status[MEI_FW_STATUS_MAX];
151 };
152
153 /**
154  * struct mei_me_client - representation of me (fw) client
155  *
156  * @list: link in me client list
157  * @refcnt: struct reference count
158  * @props: client properties
159  * @client_id: me client id
160  * @tx_flow_ctrl_creds: flow control credits
161  * @connect_count: number connections to this client
162  * @bus_added: added to bus
163  */
164 struct mei_me_client {
165         struct list_head list;
166         struct kref refcnt;
167         struct mei_client_properties props;
168         u8 client_id;
169         u8 tx_flow_ctrl_creds;
170         u8 connect_count;
171         u8 bus_added;
172 };
173
174
175 struct mei_cl;
176
177 /**
178  * struct mei_cl_cb - file operation callback structure
179  *
180  * @list: link in callback queue
181  * @cl: file client who is running this operation
182  * @fop_type: file operation type
183  * @buf: buffer for data associated with the callback
184  * @buf_idx: last read index
185  * @fp: pointer to file structure
186  * @status: io status of the cb
187  * @internal: communication between driver and FW flag
188  * @blocking: transmission blocking mode
189  * @completed: the transfer or reception has completed
190  */
191 struct mei_cl_cb {
192         struct list_head list;
193         struct mei_cl *cl;
194         enum mei_cb_file_ops fop_type;
195         struct mei_msg_data buf;
196         size_t buf_idx;
197         const struct file *fp;
198         int status;
199         u32 internal:1;
200         u32 blocking:1;
201         u32 completed:1;
202 };
203
204 /**
205  * struct mei_cl - me client host representation
206  *    carried in file->private_data
207  *
208  * @link: link in the clients list
209  * @dev: mei parent device
210  * @state: file operation state
211  * @tx_wait: wait queue for tx completion
212  * @rx_wait: wait queue for rx completion
213  * @wait:  wait queue for management operation
214  * @ev_wait: notification wait queue
215  * @ev_async: event async notification
216  * @status: connection status
217  * @me_cl: fw client connected
218  * @fp: file associated with client
219  * @host_client_id: host id
220  * @tx_flow_ctrl_creds: transmit flow credentials
221  * @rx_flow_ctrl_creds: receive flow credentials
222  * @timer_count:  watchdog timer for operation completion
223  * @notify_en: notification - enabled/disabled
224  * @notify_ev: pending notification event
225  * @writing_state: state of the tx
226  * @rd_pending: pending read credits
227  * @rd_completed: completed read
228  *
229  * @cldev: device on the mei client bus
230  */
231 struct mei_cl {
232         struct list_head link;
233         struct mei_device *dev;
234         enum file_state state;
235         wait_queue_head_t tx_wait;
236         wait_queue_head_t rx_wait;
237         wait_queue_head_t wait;
238         wait_queue_head_t ev_wait;
239         struct fasync_struct *ev_async;
240         int status;
241         struct mei_me_client *me_cl;
242         const struct file *fp;
243         u8 host_client_id;
244         u8 tx_flow_ctrl_creds;
245         u8 rx_flow_ctrl_creds;
246         u8 timer_count;
247         u8 notify_en;
248         u8 notify_ev;
249         enum mei_file_transaction_states writing_state;
250         struct list_head rd_pending;
251         struct list_head rd_completed;
252
253         struct mei_cl_device *cldev;
254 };
255
256 /**
257  * struct mei_hw_ops - hw specific ops
258  *
259  * @host_is_ready    : query for host readiness
260  *
261  * @hw_is_ready      : query if hw is ready
262  * @hw_reset         : reset hw
263  * @hw_start         : start hw after reset
264  * @hw_config        : configure hw
265  *
266  * @fw_status        : get fw status registers
267  * @pg_state         : power gating state of the device
268  * @pg_in_transition : is device now in pg transition
269  * @pg_is_enabled    : is power gating enabled
270  *
271  * @intr_clear       : clear pending interrupts
272  * @intr_enable      : enable interrupts
273  * @intr_disable     : disable interrupts
274  * @synchronize_irq  : synchronize irqs
275  *
276  * @hbuf_free_slots  : query for write buffer empty slots
277  * @hbuf_is_ready    : query if write buffer is empty
278  * @hbuf_max_len     : query for write buffer max len
279  *
280  * @write            : write a message to FW
281  *
282  * @rdbuf_full_slots : query how many slots are filled
283  *
284  * @read_hdr         : get first 4 bytes (header)
285  * @read             : read a buffer from the FW
286  */
287 struct mei_hw_ops {
288
289         bool (*host_is_ready)(struct mei_device *dev);
290
291         bool (*hw_is_ready)(struct mei_device *dev);
292         int (*hw_reset)(struct mei_device *dev, bool enable);
293         int (*hw_start)(struct mei_device *dev);
294         void (*hw_config)(struct mei_device *dev);
295
296         int (*fw_status)(struct mei_device *dev, struct mei_fw_status *fw_sts);
297         enum mei_pg_state (*pg_state)(struct mei_device *dev);
298         bool (*pg_in_transition)(struct mei_device *dev);
299         bool (*pg_is_enabled)(struct mei_device *dev);
300
301         void (*intr_clear)(struct mei_device *dev);
302         void (*intr_enable)(struct mei_device *dev);
303         void (*intr_disable)(struct mei_device *dev);
304         void (*synchronize_irq)(struct mei_device *dev);
305
306         int (*hbuf_free_slots)(struct mei_device *dev);
307         bool (*hbuf_is_ready)(struct mei_device *dev);
308         size_t (*hbuf_max_len)(const struct mei_device *dev);
309         int (*write)(struct mei_device *dev,
310                      struct mei_msg_hdr *hdr,
311                      const unsigned char *buf);
312
313         int (*rdbuf_full_slots)(struct mei_device *dev);
314
315         u32 (*read_hdr)(const struct mei_device *dev);
316         int (*read)(struct mei_device *dev,
317                      unsigned char *buf, unsigned long len);
318 };
319
320 /* MEI bus API*/
321 void mei_cl_bus_rescan(struct mei_device *bus);
322 void mei_cl_bus_rescan_work(struct work_struct *work);
323 void mei_cl_bus_dev_fixup(struct mei_cl_device *dev);
324 ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,
325                       unsigned int mode);
326 ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length,
327                       unsigned int mode);
328 bool mei_cl_bus_rx_event(struct mei_cl *cl);
329 bool mei_cl_bus_notify_event(struct mei_cl *cl);
330 void mei_cl_bus_remove_devices(struct mei_device *bus);
331 int mei_cl_bus_init(void);
332 void mei_cl_bus_exit(void);
333
334 /**
335  * enum mei_pg_event - power gating transition events
336  *
337  * @MEI_PG_EVENT_IDLE: the driver is not in power gating transition
338  * @MEI_PG_EVENT_WAIT: the driver is waiting for a pg event to complete
339  * @MEI_PG_EVENT_RECEIVED: the driver received pg event
340  * @MEI_PG_EVENT_INTR_WAIT: the driver is waiting for a pg event interrupt
341  * @MEI_PG_EVENT_INTR_RECEIVED: the driver received pg event interrupt
342  */
343 enum mei_pg_event {
344         MEI_PG_EVENT_IDLE,
345         MEI_PG_EVENT_WAIT,
346         MEI_PG_EVENT_RECEIVED,
347         MEI_PG_EVENT_INTR_WAIT,
348         MEI_PG_EVENT_INTR_RECEIVED,
349 };
350
351 /**
352  * enum mei_pg_state - device internal power gating state
353  *
354  * @MEI_PG_OFF: device is not power gated - it is active
355  * @MEI_PG_ON:  device is power gated - it is in lower power state
356  */
357 enum mei_pg_state {
358         MEI_PG_OFF = 0,
359         MEI_PG_ON =  1,
360 };
361
362 const char *mei_pg_state_str(enum mei_pg_state state);
363
364 /**
365  * struct mei_device -  MEI private device struct
366  *
367  * @dev         : device on a bus
368  * @cdev        : character device
369  * @minor       : minor number allocated for device
370  *
371  * @write_list  : write pending list
372  * @write_waiting_list : write completion list
373  * @ctrl_wr_list : pending control write list
374  * @ctrl_rd_list : pending control read list
375  *
376  * @file_list   : list of opened handles
377  * @open_handle_count: number of opened handles
378  *
379  * @device_lock : big device lock
380  * @timer_work  : MEI timer delayed work (timeouts)
381  *
382  * @recvd_hw_ready : hw ready message received flag
383  *
384  * @wait_hw_ready : wait queue for receive HW ready message form FW
385  * @wait_pg     : wait queue for receive PG message from FW
386  * @wait_hbm_start : wait queue for receive HBM start message from FW
387  *
388  * @reset_count : number of consecutive resets
389  * @dev_state   : device state
390  * @hbm_state   : state of host bus message protocol
391  * @init_clients_timer : HBM init handshake timeout
392  *
393  * @pg_event    : power gating event
394  * @pg_domain   : runtime PM domain
395  *
396  * @rd_msg_buf  : control messages buffer
397  * @rd_msg_hdr  : read message header storage
398  *
399  * @hbuf_depth  : depth of hardware host/write buffer is slots
400  * @hbuf_is_ready : query if the host host/write buffer is ready
401  *
402  * @version     : HBM protocol version in use
403  * @hbm_f_pg_supported  : hbm feature pgi protocol
404  * @hbm_f_dc_supported  : hbm feature dynamic clients
405  * @hbm_f_dot_supported : hbm feature disconnect on timeout
406  * @hbm_f_ev_supported  : hbm feature event notification
407  * @hbm_f_fa_supported  : hbm feature fixed address client
408  * @hbm_f_ie_supported  : hbm feature immediate reply to enum request
409  *
410  * @me_clients_rwsem: rw lock over me_clients list
411  * @me_clients  : list of FW clients
412  * @me_clients_map : FW clients bit map
413  * @host_clients_map : host clients id pool
414  *
415  * @allow_fixed_address: allow user space to connect a fixed client
416  * @override_fixed_address: force allow fixed address behavior
417  *
418  * @amthif_cmd_list : amthif list for cmd waiting
419  * @iamthif_cl  : amthif host client
420  * @iamthif_open_count : number of opened amthif connections
421  * @iamthif_stall_timer : timer to detect amthif hang
422  * @iamthif_state : amthif processor state
423  * @iamthif_canceled : current amthif command is canceled
424  *
425  * @reset_work  : work item for the device reset
426  * @bus_rescan_work : work item for the bus rescan
427  *
428  * @device_list : mei client bus list
429  * @cl_bus_lock : client bus list lock
430  *
431  * @dbgfs_dir   : debugfs mei root directory
432  *
433  * @ops:        : hw specific operations
434  * @hw          : hw specific data
435  */
436 struct mei_device {
437         struct device *dev;
438         struct cdev cdev;
439         int minor;
440
441         struct mei_cl_cb write_list;
442         struct mei_cl_cb write_waiting_list;
443         struct mei_cl_cb ctrl_wr_list;
444         struct mei_cl_cb ctrl_rd_list;
445
446         struct list_head file_list;
447         long open_handle_count;
448
449         struct mutex device_lock;
450         struct delayed_work timer_work;
451
452         bool recvd_hw_ready;
453         /*
454          * waiting queue for receive message from FW
455          */
456         wait_queue_head_t wait_hw_ready;
457         wait_queue_head_t wait_pg;
458         wait_queue_head_t wait_hbm_start;
459
460         /*
461          * mei device  states
462          */
463         unsigned long reset_count;
464         enum mei_dev_state dev_state;
465         enum mei_hbm_state hbm_state;
466         u16 init_clients_timer;
467
468         /*
469          * Power Gating support
470          */
471         enum mei_pg_event pg_event;
472 #ifdef CONFIG_PM
473         struct dev_pm_domain pg_domain;
474 #endif /* CONFIG_PM */
475
476         unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE];
477         u32 rd_msg_hdr;
478
479         /* write buffer */
480         u8 hbuf_depth;
481         bool hbuf_is_ready;
482
483         struct hbm_version version;
484         unsigned int hbm_f_pg_supported:1;
485         unsigned int hbm_f_dc_supported:1;
486         unsigned int hbm_f_dot_supported:1;
487         unsigned int hbm_f_ev_supported:1;
488         unsigned int hbm_f_fa_supported:1;
489         unsigned int hbm_f_ie_supported:1;
490
491         struct rw_semaphore me_clients_rwsem;
492         struct list_head me_clients;
493         DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
494         DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
495
496         bool allow_fixed_address;
497         bool override_fixed_address;
498
499         /* amthif list for cmd waiting */
500         struct mei_cl_cb amthif_cmd_list;
501         struct mei_cl iamthif_cl;
502         long iamthif_open_count;
503         u32 iamthif_stall_timer;
504         enum iamthif_states iamthif_state;
505         bool iamthif_canceled;
506
507         struct work_struct reset_work;
508         struct work_struct bus_rescan_work;
509
510         /* List of bus devices */
511         struct list_head device_list;
512         struct mutex cl_bus_lock;
513
514 #if IS_ENABLED(CONFIG_DEBUG_FS)
515         struct dentry *dbgfs_dir;
516 #endif /* CONFIG_DEBUG_FS */
517
518
519         const struct mei_hw_ops *ops;
520         char hw[0] __aligned(sizeof(void *));
521 };
522
523 static inline unsigned long mei_secs_to_jiffies(unsigned long sec)
524 {
525         return msecs_to_jiffies(sec * MSEC_PER_SEC);
526 }
527
528 /**
529  * mei_data2slots - get slots - number of (dwords) from a message length
530  *      + size of the mei header
531  *
532  * @length: size of the messages in bytes
533  *
534  * Return: number of slots
535  */
536 static inline u32 mei_data2slots(size_t length)
537 {
538         return DIV_ROUND_UP(sizeof(struct mei_msg_hdr) + length, 4);
539 }
540
541 /**
542  * mei_slots2data - get data in slots - bytes from slots
543  *
544  * @slots: number of available slots
545  *
546  * Return: number of bytes in slots
547  */
548 static inline u32 mei_slots2data(int slots)
549 {
550         return slots * 4;
551 }
552
553 /*
554  * mei init function prototypes
555  */
556 void mei_device_init(struct mei_device *dev,
557                      struct device *device,
558                      const struct mei_hw_ops *hw_ops);
559 int mei_reset(struct mei_device *dev);
560 int mei_start(struct mei_device *dev);
561 int mei_restart(struct mei_device *dev);
562 void mei_stop(struct mei_device *dev);
563 void mei_cancel_work(struct mei_device *dev);
564
565 /*
566  *  MEI interrupt functions prototype
567  */
568
569 void mei_timer(struct work_struct *work);
570 void mei_schedule_stall_timer(struct mei_device *dev);
571 int mei_irq_read_handler(struct mei_device *dev,
572                 struct mei_cl_cb *cmpl_list, s32 *slots);
573
574 int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list);
575 void mei_irq_compl_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list);
576
577 /*
578  * AMTHIF - AMT Host Interface Functions
579  */
580 void mei_amthif_reset_params(struct mei_device *dev);
581
582 int mei_amthif_host_init(struct mei_device *dev, struct mei_me_client *me_cl);
583
584 unsigned int mei_amthif_poll(struct file *file, poll_table *wait);
585
586 int mei_amthif_release(struct mei_device *dev, struct file *file);
587
588 int mei_amthif_write(struct mei_cl *cl, struct mei_cl_cb *cb);
589 int mei_amthif_run_next_cmd(struct mei_device *dev);
590 int mei_amthif_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb,
591                         struct mei_cl_cb *cmpl_list);
592
593 void mei_amthif_complete(struct mei_cl *cl, struct mei_cl_cb *cb);
594 int mei_amthif_irq_read_msg(struct mei_cl *cl,
595                             struct mei_msg_hdr *mei_hdr,
596                             struct mei_cl_cb *complete_list);
597 int mei_amthif_irq_read(struct mei_device *dev, s32 *slots);
598
599 /*
600  * Register Access Function
601  */
602
603
604 static inline void mei_hw_config(struct mei_device *dev)
605 {
606         dev->ops->hw_config(dev);
607 }
608
609 static inline enum mei_pg_state mei_pg_state(struct mei_device *dev)
610 {
611         return dev->ops->pg_state(dev);
612 }
613
614 static inline bool mei_pg_in_transition(struct mei_device *dev)
615 {
616         return dev->ops->pg_in_transition(dev);
617 }
618
619 static inline bool mei_pg_is_enabled(struct mei_device *dev)
620 {
621         return dev->ops->pg_is_enabled(dev);
622 }
623
624 static inline int mei_hw_reset(struct mei_device *dev, bool enable)
625 {
626         return dev->ops->hw_reset(dev, enable);
627 }
628
629 static inline int mei_hw_start(struct mei_device *dev)
630 {
631         return dev->ops->hw_start(dev);
632 }
633
634 static inline void mei_clear_interrupts(struct mei_device *dev)
635 {
636         dev->ops->intr_clear(dev);
637 }
638
639 static inline void mei_enable_interrupts(struct mei_device *dev)
640 {
641         dev->ops->intr_enable(dev);
642 }
643
644 static inline void mei_disable_interrupts(struct mei_device *dev)
645 {
646         dev->ops->intr_disable(dev);
647 }
648
649 static inline void mei_synchronize_irq(struct mei_device *dev)
650 {
651         dev->ops->synchronize_irq(dev);
652 }
653
654 static inline bool mei_host_is_ready(struct mei_device *dev)
655 {
656         return dev->ops->host_is_ready(dev);
657 }
658 static inline bool mei_hw_is_ready(struct mei_device *dev)
659 {
660         return dev->ops->hw_is_ready(dev);
661 }
662
663 static inline bool mei_hbuf_is_ready(struct mei_device *dev)
664 {
665         return dev->ops->hbuf_is_ready(dev);
666 }
667
668 static inline int mei_hbuf_empty_slots(struct mei_device *dev)
669 {
670         return dev->ops->hbuf_free_slots(dev);
671 }
672
673 static inline size_t mei_hbuf_max_len(const struct mei_device *dev)
674 {
675         return dev->ops->hbuf_max_len(dev);
676 }
677
678 static inline int mei_write_message(struct mei_device *dev,
679                                     struct mei_msg_hdr *hdr, const void *buf)
680 {
681         return dev->ops->write(dev, hdr, buf);
682 }
683
684 static inline u32 mei_read_hdr(const struct mei_device *dev)
685 {
686         return dev->ops->read_hdr(dev);
687 }
688
689 static inline void mei_read_slots(struct mei_device *dev,
690                      unsigned char *buf, unsigned long len)
691 {
692         dev->ops->read(dev, buf, len);
693 }
694
695 static inline int mei_count_full_read_slots(struct mei_device *dev)
696 {
697         return dev->ops->rdbuf_full_slots(dev);
698 }
699
700 static inline int mei_fw_status(struct mei_device *dev,
701                                 struct mei_fw_status *fw_status)
702 {
703         return dev->ops->fw_status(dev, fw_status);
704 }
705
706 bool mei_hbuf_acquire(struct mei_device *dev);
707
708 bool mei_write_is_idle(struct mei_device *dev);
709
710 void mei_irq_discard_msg(struct mei_device *dev, struct mei_msg_hdr *hdr);
711
712 #if IS_ENABLED(CONFIG_DEBUG_FS)
713 int mei_dbgfs_register(struct mei_device *dev, const char *name);
714 void mei_dbgfs_deregister(struct mei_device *dev);
715 #else
716 static inline int mei_dbgfs_register(struct mei_device *dev, const char *name)
717 {
718         return 0;
719 }
720 static inline void mei_dbgfs_deregister(struct mei_device *dev) {}
721 #endif /* CONFIG_DEBUG_FS */
722
723 int mei_register(struct mei_device *dev, struct device *parent);
724 void mei_deregister(struct mei_device *dev);
725
726 #define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d internal=%1d comp=%1d"
727 #define MEI_HDR_PRM(hdr)                  \
728         (hdr)->host_addr, (hdr)->me_addr, \
729         (hdr)->length, (hdr)->internal, (hdr)->msg_complete
730
731 ssize_t mei_fw_status2str(struct mei_fw_status *fw_sts, char *buf, size_t len);
732 /**
733  * mei_fw_status_str - fetch and convert fw status registers to printable string
734  *
735  * @dev: the device structure
736  * @buf: string buffer at minimal size MEI_FW_STATUS_STR_SZ
737  * @len: buffer len must be >= MEI_FW_STATUS_STR_SZ
738  *
739  * Return: number of bytes written or < 0 on failure
740  */
741 static inline ssize_t mei_fw_status_str(struct mei_device *dev,
742                                         char *buf, size_t len)
743 {
744         struct mei_fw_status fw_status;
745         int ret;
746
747         buf[0] = '\0';
748
749         ret = mei_fw_status(dev, &fw_status);
750         if (ret)
751                 return ret;
752
753         ret = mei_fw_status2str(&fw_status, buf, MEI_FW_STATUS_STR_SZ);
754
755         return ret;
756 }
757
758
759 #endif