0001
0002
0003
0004
0005
0006
0007
0008 #ifndef _ISHTP_DEV_H_
0009 #define _ISHTP_DEV_H_
0010
0011 #include <linux/types.h>
0012 #include <linux/spinlock.h>
0013 #include <linux/intel-ish-client-if.h>
0014 #include "bus.h"
0015 #include "hbm.h"
0016
0017 #define IPC_PAYLOAD_SIZE 128
0018 #define ISHTP_RD_MSG_BUF_SIZE IPC_PAYLOAD_SIZE
0019 #define IPC_FULL_MSG_SIZE 132
0020
0021
0022 #define RD_INT_FIFO_SIZE 64
0023
0024
0025
0026
0027
0028 #define IPC_TX_FIFO_SIZE 512
0029
0030
0031
0032
0033 #define ISHTP_CLIENTS_MAX 256
0034
0035
0036
0037
0038
0039
0040
0041
0042 #define ISHTP_MAX_OPEN_HANDLE_COUNT (ISHTP_CLIENTS_MAX - 1)
0043
0044
0045 #define ISHTP_HOST_CLIENT_ID_ANY (-1)
0046 #define ISHTP_HBM_HOST_CLIENT_ID 0
0047
0048 #define MAX_DMA_DELAY 20
0049
0050
0051 enum ishtp_dev_state {
0052 ISHTP_DEV_INITIALIZING = 0,
0053 ISHTP_DEV_INIT_CLIENTS,
0054 ISHTP_DEV_ENABLED,
0055 ISHTP_DEV_RESETTING,
0056 ISHTP_DEV_DISABLED,
0057 ISHTP_DEV_POWER_DOWN,
0058 ISHTP_DEV_POWER_UP
0059 };
0060 const char *ishtp_dev_state_str(int state);
0061
0062 struct ishtp_cl;
0063
0064
0065
0066
0067
0068
0069
0070 struct ishtp_fw_client {
0071 struct ishtp_client_properties props;
0072 uint8_t client_id;
0073 };
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095 struct wr_msg_ctl_info {
0096
0097 void (*ipc_send_compl)(void *);
0098
0099 void *ipc_send_compl_prm;
0100 size_t length;
0101 struct list_head link;
0102 unsigned char inline_data[IPC_FULL_MSG_SIZE];
0103 };
0104
0105
0106
0107
0108
0109 struct ishtp_hw_ops {
0110 int (*hw_reset)(struct ishtp_device *dev);
0111 int (*ipc_reset)(struct ishtp_device *dev);
0112 uint32_t (*ipc_get_header)(struct ishtp_device *dev, int length,
0113 int busy);
0114 int (*write)(struct ishtp_device *dev,
0115 void (*ipc_send_compl)(void *), void *ipc_send_compl_prm,
0116 unsigned char *msg, int length);
0117 uint32_t (*ishtp_read_hdr)(const struct ishtp_device *dev);
0118 int (*ishtp_read)(struct ishtp_device *dev, unsigned char *buffer,
0119 unsigned long buffer_length);
0120 uint32_t (*get_fw_status)(struct ishtp_device *dev);
0121 void (*sync_fw_clock)(struct ishtp_device *dev);
0122 bool (*dma_no_cache_snooping)(struct ishtp_device *dev);
0123 };
0124
0125
0126
0127
0128 struct ishtp_device {
0129 struct device *devc;
0130 struct pci_dev *pdev;
0131
0132
0133 wait_queue_head_t suspend_wait;
0134 bool suspend_flag;
0135
0136
0137 wait_queue_head_t resume_wait;
0138 bool resume_flag;
0139
0140
0141
0142
0143
0144 spinlock_t device_lock;
0145
0146 bool recvd_hw_ready;
0147 struct hbm_version version;
0148 int transfer_path;
0149
0150
0151 enum ishtp_dev_state dev_state;
0152 enum ishtp_hbm_state hbm_state;
0153
0154
0155 struct ishtp_cl_rb read_list;
0156 spinlock_t read_list_spinlock;
0157
0158
0159 struct list_head cl_list;
0160 spinlock_t cl_list_lock;
0161 long open_handle_count;
0162
0163
0164 struct list_head device_list;
0165 spinlock_t device_list_lock;
0166
0167
0168 wait_queue_head_t wait_hw_ready;
0169 wait_queue_head_t wait_hbm_recvd_msg;
0170
0171
0172 unsigned char rd_msg_fifo[RD_INT_FIFO_SIZE * IPC_PAYLOAD_SIZE];
0173 unsigned int rd_msg_fifo_head, rd_msg_fifo_tail;
0174 spinlock_t rd_msg_spinlock;
0175 struct work_struct bh_hbm_work;
0176
0177
0178 struct list_head wr_processing_list, wr_free_list;
0179
0180 spinlock_t wr_processing_spinlock;
0181
0182 struct ishtp_fw_client *fw_clients;
0183 DECLARE_BITMAP(fw_clients_map, ISHTP_CLIENTS_MAX);
0184 DECLARE_BITMAP(host_clients_map, ISHTP_CLIENTS_MAX);
0185 uint8_t fw_clients_num;
0186 uint8_t fw_client_presentation_num;
0187 uint8_t fw_client_index;
0188 spinlock_t fw_clients_lock;
0189
0190
0191 int ishtp_host_dma_enabled;
0192 void *ishtp_host_dma_tx_buf;
0193 unsigned int ishtp_host_dma_tx_buf_size;
0194 uint64_t ishtp_host_dma_tx_buf_phys;
0195 int ishtp_dma_num_slots;
0196
0197
0198 uint8_t *ishtp_dma_tx_map;
0199 spinlock_t ishtp_dma_tx_lock;
0200
0201
0202 void *ishtp_host_dma_rx_buf;
0203 unsigned int ishtp_host_dma_rx_buf_size;
0204 uint64_t ishtp_host_dma_rx_buf_phys;
0205
0206
0207 ishtp_print_log print_log;
0208
0209
0210 unsigned int ipc_rx_cnt;
0211 unsigned long long ipc_rx_bytes_cnt;
0212 unsigned int ipc_tx_cnt;
0213 unsigned long long ipc_tx_bytes_cnt;
0214
0215 const struct ishtp_hw_ops *ops;
0216 size_t mtu;
0217 uint32_t ishtp_msg_hdr;
0218 char hw[] __aligned(sizeof(void *));
0219 };
0220
0221 static inline unsigned long ishtp_secs_to_jiffies(unsigned long sec)
0222 {
0223 return msecs_to_jiffies(sec * MSEC_PER_SEC);
0224 }
0225
0226
0227
0228
0229 static inline int ish_ipc_reset(struct ishtp_device *dev)
0230 {
0231 return dev->ops->ipc_reset(dev);
0232 }
0233
0234
0235 void ishtp_device_init(struct ishtp_device *dev);
0236 int ishtp_start(struct ishtp_device *dev);
0237
0238 #endif