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