Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (c) 2003-2019, Intel Corporation. All rights reserved.
0004  * Intel Management Engine Interface (Intel MEI) Linux driver
0005  */
0006 
0007 #ifndef _MEI_DEV_H_
0008 #define _MEI_DEV_H_
0009 
0010 #include <linux/types.h>
0011 #include <linux/cdev.h>
0012 #include <linux/poll.h>
0013 #include <linux/mei.h>
0014 #include <linux/mei_cl_bus.h>
0015 
0016 #include "hw.h"
0017 #include "hbm.h"
0018 
0019 #define MEI_SLOT_SIZE             sizeof(u32)
0020 #define MEI_RD_MSG_BUF_SIZE       (128 * MEI_SLOT_SIZE)
0021 
0022 /*
0023  * Number of Maximum MEI Clients
0024  */
0025 #define MEI_CLIENTS_MAX 256
0026 
0027 /*
0028  * maximum number of consecutive resets
0029  */
0030 #define MEI_MAX_CONSEC_RESET  3
0031 
0032 /*
0033  * Number of File descriptors/handles
0034  * that can be opened to the driver.
0035  *
0036  * Limit to 255: 256 Total Clients
0037  * minus internal client for MEI Bus Messages
0038  */
0039 #define  MEI_MAX_OPEN_HANDLE_COUNT (MEI_CLIENTS_MAX - 1)
0040 
0041 /* File state */
0042 enum file_state {
0043     MEI_FILE_UNINITIALIZED = 0,
0044     MEI_FILE_INITIALIZING,
0045     MEI_FILE_CONNECTING,
0046     MEI_FILE_CONNECTED,
0047     MEI_FILE_DISCONNECTING,
0048     MEI_FILE_DISCONNECT_REPLY,
0049     MEI_FILE_DISCONNECT_REQUIRED,
0050     MEI_FILE_DISCONNECTED,
0051 };
0052 
0053 /* MEI device states */
0054 enum mei_dev_state {
0055     MEI_DEV_INITIALIZING = 0,
0056     MEI_DEV_INIT_CLIENTS,
0057     MEI_DEV_ENABLED,
0058     MEI_DEV_RESETTING,
0059     MEI_DEV_DISABLED,
0060     MEI_DEV_POWERING_DOWN,
0061     MEI_DEV_POWER_DOWN,
0062     MEI_DEV_POWER_UP
0063 };
0064 
0065 const char *mei_dev_state_str(int state);
0066 
0067 enum mei_file_transaction_states {
0068     MEI_IDLE,
0069     MEI_WRITING,
0070     MEI_WRITE_COMPLETE,
0071 };
0072 
0073 /**
0074  * enum mei_cb_file_ops  - file operation associated with the callback
0075  * @MEI_FOP_READ:       read
0076  * @MEI_FOP_WRITE:      write
0077  * @MEI_FOP_CONNECT:    connect
0078  * @MEI_FOP_DISCONNECT: disconnect
0079  * @MEI_FOP_DISCONNECT_RSP: disconnect response
0080  * @MEI_FOP_NOTIFY_START:   start notification
0081  * @MEI_FOP_NOTIFY_STOP:    stop notification
0082  * @MEI_FOP_DMA_MAP:   request client dma map
0083  * @MEI_FOP_DMA_UNMAP: request client dma unmap
0084  */
0085 enum mei_cb_file_ops {
0086     MEI_FOP_READ = 0,
0087     MEI_FOP_WRITE,
0088     MEI_FOP_CONNECT,
0089     MEI_FOP_DISCONNECT,
0090     MEI_FOP_DISCONNECT_RSP,
0091     MEI_FOP_NOTIFY_START,
0092     MEI_FOP_NOTIFY_STOP,
0093     MEI_FOP_DMA_MAP,
0094     MEI_FOP_DMA_UNMAP,
0095 };
0096 
0097 /**
0098  * enum mei_cl_io_mode - io mode between driver and fw
0099  *
0100  * @MEI_CL_IO_TX_BLOCKING: send is blocking
0101  * @MEI_CL_IO_TX_INTERNAL: internal communication between driver and FW
0102  *
0103  * @MEI_CL_IO_RX_NONBLOCK: recv is non-blocking
0104  */
0105 enum mei_cl_io_mode {
0106     MEI_CL_IO_TX_BLOCKING = BIT(0),
0107     MEI_CL_IO_TX_INTERNAL = BIT(1),
0108 
0109     MEI_CL_IO_RX_NONBLOCK = BIT(2),
0110 };
0111 
0112 /*
0113  * Intel MEI message data struct
0114  */
0115 struct mei_msg_data {
0116     size_t size;
0117     unsigned char *data;
0118 };
0119 
0120 struct mei_dma_data {
0121     u8 buffer_id;
0122     void *vaddr;
0123     dma_addr_t daddr;
0124     size_t size;
0125 };
0126 
0127 /**
0128  * struct mei_dma_dscr - dma address descriptor
0129  *
0130  * @vaddr: dma buffer virtual address
0131  * @daddr: dma buffer physical address
0132  * @size : dma buffer size
0133  */
0134 struct mei_dma_dscr {
0135     void *vaddr;
0136     dma_addr_t daddr;
0137     size_t size;
0138 };
0139 
0140 /* Maximum number of processed FW status registers */
0141 #define MEI_FW_STATUS_MAX 6
0142 /* Minimal  buffer for FW status string (8 bytes in dw + space or '\0') */
0143 #define MEI_FW_STATUS_STR_SZ (MEI_FW_STATUS_MAX * (8 + 1))
0144 
0145 
0146 /*
0147  * struct mei_fw_status - storage of FW status data
0148  *
0149  * @count: number of actually available elements in array
0150  * @status: FW status registers
0151  */
0152 struct mei_fw_status {
0153     int count;
0154     u32 status[MEI_FW_STATUS_MAX];
0155 };
0156 
0157 /**
0158  * struct mei_me_client - representation of me (fw) client
0159  *
0160  * @list: link in me client list
0161  * @refcnt: struct reference count
0162  * @props: client properties
0163  * @client_id: me client id
0164  * @tx_flow_ctrl_creds: flow control credits
0165  * @connect_count: number connections to this client
0166  * @bus_added: added to bus
0167  */
0168 struct mei_me_client {
0169     struct list_head list;
0170     struct kref refcnt;
0171     struct mei_client_properties props;
0172     u8 client_id;
0173     u8 tx_flow_ctrl_creds;
0174     u8 connect_count;
0175     u8 bus_added;
0176 };
0177 
0178 
0179 struct mei_cl;
0180 
0181 /**
0182  * struct mei_cl_cb - file operation callback structure
0183  *
0184  * @list: link in callback queue
0185  * @cl: file client who is running this operation
0186  * @fop_type: file operation type
0187  * @buf: buffer for data associated with the callback
0188  * @buf_idx: last read index
0189  * @vtag: virtual tag
0190  * @fp: pointer to file structure
0191  * @status: io status of the cb
0192  * @internal: communication between driver and FW flag
0193  * @blocking: transmission blocking mode
0194  */
0195 struct mei_cl_cb {
0196     struct list_head list;
0197     struct mei_cl *cl;
0198     enum mei_cb_file_ops fop_type;
0199     struct mei_msg_data buf;
0200     size_t buf_idx;
0201     u8 vtag;
0202     const struct file *fp;
0203     int status;
0204     u32 internal:1;
0205     u32 blocking:1;
0206 };
0207 
0208 /**
0209  * struct mei_cl_vtag - file pointer to vtag mapping structure
0210  *
0211  * @list: link in map queue
0212  * @fp: file pointer
0213  * @vtag: corresponding vtag
0214  * @pending_read: the read is pending on this file
0215  */
0216 struct mei_cl_vtag {
0217     struct list_head list;
0218     const struct file *fp;
0219     u8 vtag;
0220     u8 pending_read:1;
0221 };
0222 
0223 /**
0224  * struct mei_cl - me client host representation
0225  *    carried in file->private_data
0226  *
0227  * @link: link in the clients list
0228  * @dev: mei parent device
0229  * @state: file operation state
0230  * @tx_wait: wait queue for tx completion
0231  * @rx_wait: wait queue for rx completion
0232  * @wait:  wait queue for management operation
0233  * @ev_wait: notification wait queue
0234  * @ev_async: event async notification
0235  * @status: connection status
0236  * @me_cl: fw client connected
0237  * @fp: file associated with client
0238  * @host_client_id: host id
0239  * @vtag_map: vtag map
0240  * @tx_flow_ctrl_creds: transmit flow credentials
0241  * @rx_flow_ctrl_creds: receive flow credentials
0242  * @timer_count:  watchdog timer for operation completion
0243  * @notify_en: notification - enabled/disabled
0244  * @notify_ev: pending notification event
0245  * @tx_cb_queued: number of tx callbacks in queue
0246  * @writing_state: state of the tx
0247  * @rd_pending: pending read credits
0248  * @rd_completed_lock: protects rd_completed queue
0249  * @rd_completed: completed read
0250  * @dma: dma settings
0251  * @dma_mapped: dma buffer is currently mapped.
0252  *
0253  * @cldev: device on the mei client bus
0254  */
0255 struct mei_cl {
0256     struct list_head link;
0257     struct mei_device *dev;
0258     enum file_state state;
0259     wait_queue_head_t tx_wait;
0260     wait_queue_head_t rx_wait;
0261     wait_queue_head_t wait;
0262     wait_queue_head_t ev_wait;
0263     struct fasync_struct *ev_async;
0264     int status;
0265     struct mei_me_client *me_cl;
0266     const struct file *fp;
0267     u8 host_client_id;
0268     struct list_head vtag_map;
0269     u8 tx_flow_ctrl_creds;
0270     u8 rx_flow_ctrl_creds;
0271     u8 timer_count;
0272     u8 notify_en;
0273     u8 notify_ev;
0274     u8 tx_cb_queued;
0275     enum mei_file_transaction_states writing_state;
0276     struct list_head rd_pending;
0277     spinlock_t rd_completed_lock; /* protects rd_completed queue */
0278     struct list_head rd_completed;
0279     struct mei_dma_data dma;
0280     u8 dma_mapped;
0281 
0282     struct mei_cl_device *cldev;
0283 };
0284 
0285 #define MEI_TX_QUEUE_LIMIT_DEFAULT 50
0286 #define MEI_TX_QUEUE_LIMIT_MAX 255
0287 #define MEI_TX_QUEUE_LIMIT_MIN 30
0288 
0289 /**
0290  * struct mei_hw_ops - hw specific ops
0291  *
0292  * @host_is_ready    : query for host readiness
0293  *
0294  * @hw_is_ready      : query if hw is ready
0295  * @hw_reset         : reset hw
0296  * @hw_start         : start hw after reset
0297  * @hw_config        : configure hw
0298  *
0299  * @fw_status        : get fw status registers
0300  * @trc_status       : get trc status register
0301  * @pg_state         : power gating state of the device
0302  * @pg_in_transition : is device now in pg transition
0303  * @pg_is_enabled    : is power gating enabled
0304  *
0305  * @intr_clear       : clear pending interrupts
0306  * @intr_enable      : enable interrupts
0307  * @intr_disable     : disable interrupts
0308  * @synchronize_irq  : synchronize irqs
0309  *
0310  * @hbuf_free_slots  : query for write buffer empty slots
0311  * @hbuf_is_ready    : query if write buffer is empty
0312  * @hbuf_depth       : query for write buffer depth
0313  *
0314  * @write            : write a message to FW
0315  *
0316  * @rdbuf_full_slots : query how many slots are filled
0317  *
0318  * @read_hdr         : get first 4 bytes (header)
0319  * @read             : read a buffer from the FW
0320  */
0321 struct mei_hw_ops {
0322 
0323     bool (*host_is_ready)(struct mei_device *dev);
0324 
0325     bool (*hw_is_ready)(struct mei_device *dev);
0326     int (*hw_reset)(struct mei_device *dev, bool enable);
0327     int (*hw_start)(struct mei_device *dev);
0328     int (*hw_config)(struct mei_device *dev);
0329 
0330     int (*fw_status)(struct mei_device *dev, struct mei_fw_status *fw_sts);
0331     int (*trc_status)(struct mei_device *dev, u32 *trc);
0332 
0333     enum mei_pg_state (*pg_state)(struct mei_device *dev);
0334     bool (*pg_in_transition)(struct mei_device *dev);
0335     bool (*pg_is_enabled)(struct mei_device *dev);
0336 
0337     void (*intr_clear)(struct mei_device *dev);
0338     void (*intr_enable)(struct mei_device *dev);
0339     void (*intr_disable)(struct mei_device *dev);
0340     void (*synchronize_irq)(struct mei_device *dev);
0341 
0342     int (*hbuf_free_slots)(struct mei_device *dev);
0343     bool (*hbuf_is_ready)(struct mei_device *dev);
0344     u32 (*hbuf_depth)(const struct mei_device *dev);
0345     int (*write)(struct mei_device *dev,
0346              const void *hdr, size_t hdr_len,
0347              const void *data, size_t data_len);
0348 
0349     int (*rdbuf_full_slots)(struct mei_device *dev);
0350 
0351     u32 (*read_hdr)(const struct mei_device *dev);
0352     int (*read)(struct mei_device *dev,
0353              unsigned char *buf, unsigned long len);
0354 };
0355 
0356 /* MEI bus API*/
0357 void mei_cl_bus_rescan_work(struct work_struct *work);
0358 void mei_cl_bus_dev_fixup(struct mei_cl_device *dev);
0359 ssize_t __mei_cl_send(struct mei_cl *cl, const u8 *buf, size_t length, u8 vtag,
0360               unsigned int mode);
0361 ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length, u8 *vtag,
0362               unsigned int mode, unsigned long timeout);
0363 bool mei_cl_bus_rx_event(struct mei_cl *cl);
0364 bool mei_cl_bus_notify_event(struct mei_cl *cl);
0365 void mei_cl_bus_remove_devices(struct mei_device *bus);
0366 int mei_cl_bus_init(void);
0367 void mei_cl_bus_exit(void);
0368 
0369 /**
0370  * enum mei_pg_event - power gating transition events
0371  *
0372  * @MEI_PG_EVENT_IDLE: the driver is not in power gating transition
0373  * @MEI_PG_EVENT_WAIT: the driver is waiting for a pg event to complete
0374  * @MEI_PG_EVENT_RECEIVED: the driver received pg event
0375  * @MEI_PG_EVENT_INTR_WAIT: the driver is waiting for a pg event interrupt
0376  * @MEI_PG_EVENT_INTR_RECEIVED: the driver received pg event interrupt
0377  */
0378 enum mei_pg_event {
0379     MEI_PG_EVENT_IDLE,
0380     MEI_PG_EVENT_WAIT,
0381     MEI_PG_EVENT_RECEIVED,
0382     MEI_PG_EVENT_INTR_WAIT,
0383     MEI_PG_EVENT_INTR_RECEIVED,
0384 };
0385 
0386 /**
0387  * enum mei_pg_state - device internal power gating state
0388  *
0389  * @MEI_PG_OFF: device is not power gated - it is active
0390  * @MEI_PG_ON:  device is power gated - it is in lower power state
0391  */
0392 enum mei_pg_state {
0393     MEI_PG_OFF = 0,
0394     MEI_PG_ON =  1,
0395 };
0396 
0397 const char *mei_pg_state_str(enum mei_pg_state state);
0398 
0399 /**
0400  * struct mei_fw_version - MEI FW version struct
0401  *
0402  * @platform: platform identifier
0403  * @major: major version field
0404  * @minor: minor version field
0405  * @buildno: build number version field
0406  * @hotfix: hotfix number version field
0407  */
0408 struct mei_fw_version {
0409     u8 platform;
0410     u8 major;
0411     u16 minor;
0412     u16 buildno;
0413     u16 hotfix;
0414 };
0415 
0416 #define MEI_MAX_FW_VER_BLOCKS 3
0417 
0418 /**
0419  * struct mei_device -  MEI private device struct
0420  *
0421  * @dev         : device on a bus
0422  * @cdev        : character device
0423  * @minor       : minor number allocated for device
0424  *
0425  * @write_list  : write pending list
0426  * @write_waiting_list : write completion list
0427  * @ctrl_wr_list : pending control write list
0428  * @ctrl_rd_list : pending control read list
0429  * @tx_queue_limit: tx queues per client linit
0430  *
0431  * @file_list   : list of opened handles
0432  * @open_handle_count: number of opened handles
0433  *
0434  * @device_lock : big device lock
0435  * @timer_work  : MEI timer delayed work (timeouts)
0436  *
0437  * @recvd_hw_ready : hw ready message received flag
0438  *
0439  * @wait_hw_ready : wait queue for receive HW ready message form FW
0440  * @wait_pg     : wait queue for receive PG message from FW
0441  * @wait_hbm_start : wait queue for receive HBM start message from FW
0442  *
0443  * @reset_count : number of consecutive resets
0444  * @dev_state   : device state
0445  * @hbm_state   : state of host bus message protocol
0446  * @init_clients_timer : HBM init handshake timeout
0447  *
0448  * @pg_event    : power gating event
0449  * @pg_domain   : runtime PM domain
0450  *
0451  * @rd_msg_buf  : control messages buffer
0452  * @rd_msg_hdr  : read message header storage
0453  * @rd_msg_hdr_count : how many dwords were already read from header
0454  *
0455  * @hbuf_is_ready : query if the host host/write buffer is ready
0456  * @dr_dscr: DMA ring descriptors: TX, RX, and CTRL
0457  *
0458  * @version     : HBM protocol version in use
0459  * @hbm_f_pg_supported  : hbm feature pgi protocol
0460  * @hbm_f_dc_supported  : hbm feature dynamic clients
0461  * @hbm_f_dot_supported : hbm feature disconnect on timeout
0462  * @hbm_f_ev_supported  : hbm feature event notification
0463  * @hbm_f_fa_supported  : hbm feature fixed address client
0464  * @hbm_f_ie_supported  : hbm feature immediate reply to enum request
0465  * @hbm_f_os_supported  : hbm feature support OS ver message
0466  * @hbm_f_dr_supported  : hbm feature dma ring supported
0467  * @hbm_f_vt_supported  : hbm feature vtag supported
0468  * @hbm_f_cap_supported : hbm feature capabilities message supported
0469  * @hbm_f_cd_supported  : hbm feature client dma supported
0470  *
0471  * @fw_ver : FW versions
0472  *
0473  * @fw_f_fw_ver_supported : fw feature: fw version supported
0474  *
0475  * @me_clients_rwsem: rw lock over me_clients list
0476  * @me_clients  : list of FW clients
0477  * @me_clients_map : FW clients bit map
0478  * @host_clients_map : host clients id pool
0479  *
0480  * @allow_fixed_address: allow user space to connect a fixed client
0481  * @override_fixed_address: force allow fixed address behavior
0482  *
0483  * @reset_work  : work item for the device reset
0484  * @bus_rescan_work : work item for the bus rescan
0485  *
0486  * @device_list : mei client bus list
0487  * @cl_bus_lock : client bus list lock
0488  *
0489  * @kind        : kind of mei device
0490  *
0491  * @dbgfs_dir   : debugfs mei root directory
0492  *
0493  * @ops:        : hw specific operations
0494  * @hw          : hw specific data
0495  */
0496 struct mei_device {
0497     struct device *dev;
0498     struct cdev cdev;
0499     int minor;
0500 
0501     struct list_head write_list;
0502     struct list_head write_waiting_list;
0503     struct list_head ctrl_wr_list;
0504     struct list_head ctrl_rd_list;
0505     u8 tx_queue_limit;
0506 
0507     struct list_head file_list;
0508     long open_handle_count;
0509 
0510     struct mutex device_lock;
0511     struct delayed_work timer_work;
0512 
0513     bool recvd_hw_ready;
0514     /*
0515      * waiting queue for receive message from FW
0516      */
0517     wait_queue_head_t wait_hw_ready;
0518     wait_queue_head_t wait_pg;
0519     wait_queue_head_t wait_hbm_start;
0520 
0521     /*
0522      * mei device  states
0523      */
0524     unsigned long reset_count;
0525     enum mei_dev_state dev_state;
0526     enum mei_hbm_state hbm_state;
0527     u16 init_clients_timer;
0528 
0529     /*
0530      * Power Gating support
0531      */
0532     enum mei_pg_event pg_event;
0533 #ifdef CONFIG_PM
0534     struct dev_pm_domain pg_domain;
0535 #endif /* CONFIG_PM */
0536 
0537     unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE];
0538     u32 rd_msg_hdr[MEI_RD_MSG_BUF_SIZE];
0539     int rd_msg_hdr_count;
0540 
0541     /* write buffer */
0542     bool hbuf_is_ready;
0543 
0544     struct mei_dma_dscr dr_dscr[DMA_DSCR_NUM];
0545 
0546     struct hbm_version version;
0547     unsigned int hbm_f_pg_supported:1;
0548     unsigned int hbm_f_dc_supported:1;
0549     unsigned int hbm_f_dot_supported:1;
0550     unsigned int hbm_f_ev_supported:1;
0551     unsigned int hbm_f_fa_supported:1;
0552     unsigned int hbm_f_ie_supported:1;
0553     unsigned int hbm_f_os_supported:1;
0554     unsigned int hbm_f_dr_supported:1;
0555     unsigned int hbm_f_vt_supported:1;
0556     unsigned int hbm_f_cap_supported:1;
0557     unsigned int hbm_f_cd_supported:1;
0558 
0559     struct mei_fw_version fw_ver[MEI_MAX_FW_VER_BLOCKS];
0560 
0561     unsigned int fw_f_fw_ver_supported:1;
0562 
0563     struct rw_semaphore me_clients_rwsem;
0564     struct list_head me_clients;
0565     DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
0566     DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
0567 
0568     bool allow_fixed_address;
0569     bool override_fixed_address;
0570 
0571     struct work_struct reset_work;
0572     struct work_struct bus_rescan_work;
0573 
0574     /* List of bus devices */
0575     struct list_head device_list;
0576     struct mutex cl_bus_lock;
0577 
0578     const char *kind;
0579 
0580 #if IS_ENABLED(CONFIG_DEBUG_FS)
0581     struct dentry *dbgfs_dir;
0582 #endif /* CONFIG_DEBUG_FS */
0583 
0584     const struct mei_hw_ops *ops;
0585     char hw[] __aligned(sizeof(void *));
0586 };
0587 
0588 static inline unsigned long mei_secs_to_jiffies(unsigned long sec)
0589 {
0590     return msecs_to_jiffies(sec * MSEC_PER_SEC);
0591 }
0592 
0593 /**
0594  * mei_data2slots - get slots number from a message length
0595  *
0596  * @length: size of the messages in bytes
0597  *
0598  * Return: number of slots
0599  */
0600 static inline u32 mei_data2slots(size_t length)
0601 {
0602     return DIV_ROUND_UP(length, MEI_SLOT_SIZE);
0603 }
0604 
0605 /**
0606  * mei_hbm2slots - get slots number from a hbm message length
0607  *                 length + size of the mei message header
0608  *
0609  * @length: size of the messages in bytes
0610  *
0611  * Return: number of slots
0612  */
0613 static inline u32 mei_hbm2slots(size_t length)
0614 {
0615     return DIV_ROUND_UP(sizeof(struct mei_msg_hdr) + length, MEI_SLOT_SIZE);
0616 }
0617 
0618 /**
0619  * mei_slots2data - get data in slots - bytes from slots
0620  *
0621  * @slots: number of available slots
0622  *
0623  * Return: number of bytes in slots
0624  */
0625 static inline u32 mei_slots2data(int slots)
0626 {
0627     return slots * MEI_SLOT_SIZE;
0628 }
0629 
0630 /*
0631  * mei init function prototypes
0632  */
0633 void mei_device_init(struct mei_device *dev,
0634              struct device *device,
0635              const struct mei_hw_ops *hw_ops);
0636 int mei_reset(struct mei_device *dev);
0637 int mei_start(struct mei_device *dev);
0638 int mei_restart(struct mei_device *dev);
0639 void mei_stop(struct mei_device *dev);
0640 void mei_cancel_work(struct mei_device *dev);
0641 
0642 void mei_set_devstate(struct mei_device *dev, enum mei_dev_state state);
0643 
0644 int mei_dmam_ring_alloc(struct mei_device *dev);
0645 void mei_dmam_ring_free(struct mei_device *dev);
0646 bool mei_dma_ring_is_allocated(struct mei_device *dev);
0647 void mei_dma_ring_reset(struct mei_device *dev);
0648 void mei_dma_ring_read(struct mei_device *dev, unsigned char *buf, u32 len);
0649 void mei_dma_ring_write(struct mei_device *dev, unsigned char *buf, u32 len);
0650 u32 mei_dma_ring_empty_slots(struct mei_device *dev);
0651 
0652 /*
0653  *  MEI interrupt functions prototype
0654  */
0655 
0656 void mei_timer(struct work_struct *work);
0657 void mei_schedule_stall_timer(struct mei_device *dev);
0658 int mei_irq_read_handler(struct mei_device *dev,
0659              struct list_head *cmpl_list, s32 *slots);
0660 
0661 int mei_irq_write_handler(struct mei_device *dev, struct list_head *cmpl_list);
0662 void mei_irq_compl_handler(struct mei_device *dev, struct list_head *cmpl_list);
0663 
0664 /*
0665  * Register Access Function
0666  */
0667 
0668 
0669 static inline int mei_hw_config(struct mei_device *dev)
0670 {
0671     return dev->ops->hw_config(dev);
0672 }
0673 
0674 static inline enum mei_pg_state mei_pg_state(struct mei_device *dev)
0675 {
0676     return dev->ops->pg_state(dev);
0677 }
0678 
0679 static inline bool mei_pg_in_transition(struct mei_device *dev)
0680 {
0681     return dev->ops->pg_in_transition(dev);
0682 }
0683 
0684 static inline bool mei_pg_is_enabled(struct mei_device *dev)
0685 {
0686     return dev->ops->pg_is_enabled(dev);
0687 }
0688 
0689 static inline int mei_hw_reset(struct mei_device *dev, bool enable)
0690 {
0691     return dev->ops->hw_reset(dev, enable);
0692 }
0693 
0694 static inline int mei_hw_start(struct mei_device *dev)
0695 {
0696     return dev->ops->hw_start(dev);
0697 }
0698 
0699 static inline void mei_clear_interrupts(struct mei_device *dev)
0700 {
0701     dev->ops->intr_clear(dev);
0702 }
0703 
0704 static inline void mei_enable_interrupts(struct mei_device *dev)
0705 {
0706     dev->ops->intr_enable(dev);
0707 }
0708 
0709 static inline void mei_disable_interrupts(struct mei_device *dev)
0710 {
0711     dev->ops->intr_disable(dev);
0712 }
0713 
0714 static inline void mei_synchronize_irq(struct mei_device *dev)
0715 {
0716     dev->ops->synchronize_irq(dev);
0717 }
0718 
0719 static inline bool mei_host_is_ready(struct mei_device *dev)
0720 {
0721     return dev->ops->host_is_ready(dev);
0722 }
0723 static inline bool mei_hw_is_ready(struct mei_device *dev)
0724 {
0725     return dev->ops->hw_is_ready(dev);
0726 }
0727 
0728 static inline bool mei_hbuf_is_ready(struct mei_device *dev)
0729 {
0730     return dev->ops->hbuf_is_ready(dev);
0731 }
0732 
0733 static inline int mei_hbuf_empty_slots(struct mei_device *dev)
0734 {
0735     return dev->ops->hbuf_free_slots(dev);
0736 }
0737 
0738 static inline u32 mei_hbuf_depth(const struct mei_device *dev)
0739 {
0740     return dev->ops->hbuf_depth(dev);
0741 }
0742 
0743 static inline int mei_write_message(struct mei_device *dev,
0744                     const void *hdr, size_t hdr_len,
0745                     const void *data, size_t data_len)
0746 {
0747     return dev->ops->write(dev, hdr, hdr_len, data, data_len);
0748 }
0749 
0750 static inline u32 mei_read_hdr(const struct mei_device *dev)
0751 {
0752     return dev->ops->read_hdr(dev);
0753 }
0754 
0755 static inline void mei_read_slots(struct mei_device *dev,
0756              unsigned char *buf, unsigned long len)
0757 {
0758     dev->ops->read(dev, buf, len);
0759 }
0760 
0761 static inline int mei_count_full_read_slots(struct mei_device *dev)
0762 {
0763     return dev->ops->rdbuf_full_slots(dev);
0764 }
0765 
0766 static inline int mei_trc_status(struct mei_device *dev, u32 *trc)
0767 {
0768     if (dev->ops->trc_status)
0769         return dev->ops->trc_status(dev, trc);
0770     return -EOPNOTSUPP;
0771 }
0772 
0773 static inline int mei_fw_status(struct mei_device *dev,
0774                 struct mei_fw_status *fw_status)
0775 {
0776     return dev->ops->fw_status(dev, fw_status);
0777 }
0778 
0779 bool mei_hbuf_acquire(struct mei_device *dev);
0780 
0781 bool mei_write_is_idle(struct mei_device *dev);
0782 
0783 #if IS_ENABLED(CONFIG_DEBUG_FS)
0784 void mei_dbgfs_register(struct mei_device *dev, const char *name);
0785 void mei_dbgfs_deregister(struct mei_device *dev);
0786 #else
0787 static inline void mei_dbgfs_register(struct mei_device *dev, const char *name) {}
0788 static inline void mei_dbgfs_deregister(struct mei_device *dev) {}
0789 #endif /* CONFIG_DEBUG_FS */
0790 
0791 int mei_register(struct mei_device *dev, struct device *parent);
0792 void mei_deregister(struct mei_device *dev);
0793 
0794 #define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d dma=%1d ext=%1d internal=%1d comp=%1d"
0795 #define MEI_HDR_PRM(hdr)                  \
0796     (hdr)->host_addr, (hdr)->me_addr, \
0797     (hdr)->length, (hdr)->dma_ring, (hdr)->extended, \
0798     (hdr)->internal, (hdr)->msg_complete
0799 
0800 ssize_t mei_fw_status2str(struct mei_fw_status *fw_sts, char *buf, size_t len);
0801 /**
0802  * mei_fw_status_str - fetch and convert fw status registers to printable string
0803  *
0804  * @dev: the device structure
0805  * @buf: string buffer at minimal size MEI_FW_STATUS_STR_SZ
0806  * @len: buffer len must be >= MEI_FW_STATUS_STR_SZ
0807  *
0808  * Return: number of bytes written or < 0 on failure
0809  */
0810 static inline ssize_t mei_fw_status_str(struct mei_device *dev,
0811                     char *buf, size_t len)
0812 {
0813     struct mei_fw_status fw_status;
0814     int ret;
0815 
0816     buf[0] = '\0';
0817 
0818     ret = mei_fw_status(dev, &fw_status);
0819     if (ret)
0820         return ret;
0821 
0822     ret = mei_fw_status2str(&fw_status, buf, MEI_FW_STATUS_STR_SZ);
0823 
0824     return ret;
0825 }
0826 
0827 
0828 #endif