sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / hid / intel-ish-hid / ishtp / ishtp-dev.h
bloba94f9a8a96a022f7684d33c79b15115aae91e2b1
1 /*
2 * Most ISHTP provider device and ISHTP logic declarations
4 * Copyright (c) 2003-2016, Intel Corporation.
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.
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.
16 #ifndef _ISHTP_DEV_H_
17 #define _ISHTP_DEV_H_
19 #include <linux/types.h>
20 #include <linux/spinlock.h>
21 #include "bus.h"
22 #include "hbm.h"
24 #define IPC_PAYLOAD_SIZE 128
25 #define ISHTP_RD_MSG_BUF_SIZE IPC_PAYLOAD_SIZE
26 #define IPC_FULL_MSG_SIZE 132
28 /* Number of messages to be held in ISR->BH FIFO */
29 #define RD_INT_FIFO_SIZE 64
32 * Number of IPC messages to be held in Tx FIFO, to be sent by ISR -
33 * Tx complete interrupt or RX_COMPLETE handler
35 #define IPC_TX_FIFO_SIZE 512
38 * Number of Maximum ISHTP Clients
40 #define ISHTP_CLIENTS_MAX 256
43 * Number of File descriptors/handles
44 * that can be opened to the driver.
46 * Limit to 255: 256 Total Clients
47 * minus internal client for ISHTP Bus Messages
49 #define ISHTP_MAX_OPEN_HANDLE_COUNT (ISHTP_CLIENTS_MAX - 1)
51 /* Internal Clients Number */
52 #define ISHTP_HOST_CLIENT_ID_ANY (-1)
53 #define ISHTP_HBM_HOST_CLIENT_ID 0
55 #define MAX_DMA_DELAY 20
57 /* ISHTP device states */
58 enum ishtp_dev_state {
59 ISHTP_DEV_INITIALIZING = 0,
60 ISHTP_DEV_INIT_CLIENTS,
61 ISHTP_DEV_ENABLED,
62 ISHTP_DEV_RESETTING,
63 ISHTP_DEV_DISABLED,
64 ISHTP_DEV_POWER_DOWN,
65 ISHTP_DEV_POWER_UP
67 const char *ishtp_dev_state_str(int state);
69 struct ishtp_cl;
71 /**
72 * struct ishtp_fw_client - representation of fw client
74 * @props - client properties
75 * @client_id - fw client id
77 struct ishtp_fw_client {
78 struct ishtp_client_properties props;
79 uint8_t client_id;
82 /**
83 * struct ishtp_msg_data - ISHTP message data struct
84 * @size: Size of data in the *data
85 * @data: Pointer to data
87 struct ishtp_msg_data {
88 uint32_t size;
89 unsigned char *data;
93 * struct ishtp_cl_rb - request block structure
94 * @list: Link to list members
95 * @cl: ISHTP client instance
96 * @buffer: message header
97 * @buf_idx: Index into buffer
98 * @read_time: unused at this time
100 struct ishtp_cl_rb {
101 struct list_head list;
102 struct ishtp_cl *cl;
103 struct ishtp_msg_data buffer;
104 unsigned long buf_idx;
105 unsigned long read_time;
109 * Control info for IPC messages ISHTP/IPC sending FIFO -
110 * list with inline data buffer
111 * This structure will be filled with parameters submitted
112 * by the caller glue layer
113 * 'buf' may be pointing to the external buffer or to 'inline_data'
114 * 'offset' will be initialized to 0 by submitting
116 * 'ipc_send_compl' is intended for use by clients that send fragmented
117 * messages. When a fragment is sent down to IPC msg regs,
118 * it will be called.
119 * If it has more fragments to send, it will do it. With last fragment
120 * it will send appropriate ISHTP "message-complete" flag.
121 * It will remove the outstanding message
122 * (mark outstanding buffer as available).
123 * If counting flow control is in work and there are more flow control
124 * credits, it can put the next client message queued in cl.
125 * structure for IPC processing.
128 struct wr_msg_ctl_info {
129 /* Will be called with 'ipc_send_compl_prm' as parameter */
130 void (*ipc_send_compl)(void *);
132 void *ipc_send_compl_prm;
133 size_t length;
134 struct list_head link;
135 unsigned char inline_data[IPC_FULL_MSG_SIZE];
139 * The ISHTP layer talks to hardware IPC message using the following
140 * callbacks
142 struct ishtp_hw_ops {
143 int (*hw_reset)(struct ishtp_device *dev);
144 int (*ipc_reset)(struct ishtp_device *dev);
145 uint32_t (*ipc_get_header)(struct ishtp_device *dev, int length,
146 int busy);
147 int (*write)(struct ishtp_device *dev,
148 void (*ipc_send_compl)(void *), void *ipc_send_compl_prm,
149 unsigned char *msg, int length);
150 uint32_t (*ishtp_read_hdr)(const struct ishtp_device *dev);
151 int (*ishtp_read)(struct ishtp_device *dev, unsigned char *buffer,
152 unsigned long buffer_length);
153 uint32_t (*get_fw_status)(struct ishtp_device *dev);
154 void (*sync_fw_clock)(struct ishtp_device *dev);
158 * struct ishtp_device - ISHTP private device struct
160 struct ishtp_device {
161 struct device *devc; /* pointer to lowest device */
162 struct pci_dev *pdev; /* PCI device to get device ids */
164 /* waitq for waiting for suspend response */
165 wait_queue_head_t suspend_wait;
166 bool suspend_flag; /* Suspend is active */
168 /* waitq for waiting for resume response */
169 wait_queue_head_t resume_wait;
170 bool resume_flag; /*Resume is active */
173 * lock for the device, for everything that doesn't have
174 * a dedicated spinlock
176 spinlock_t device_lock;
178 bool recvd_hw_ready;
179 struct hbm_version version;
180 int transfer_path; /* Choice of transfer path: IPC or DMA */
182 /* ishtp device states */
183 enum ishtp_dev_state dev_state;
184 enum ishtp_hbm_state hbm_state;
186 /* driver read queue */
187 struct ishtp_cl_rb read_list;
188 spinlock_t read_list_spinlock;
190 /* list of ishtp_cl's */
191 struct list_head cl_list;
192 spinlock_t cl_list_lock;
193 long open_handle_count;
195 /* List of bus devices */
196 struct list_head device_list;
197 spinlock_t device_list_lock;
199 /* waiting queues for receive message from FW */
200 wait_queue_head_t wait_hw_ready;
201 wait_queue_head_t wait_hbm_recvd_msg;
203 /* FIFO for input messages for BH processing */
204 unsigned char rd_msg_fifo[RD_INT_FIFO_SIZE * IPC_PAYLOAD_SIZE];
205 unsigned int rd_msg_fifo_head, rd_msg_fifo_tail;
206 spinlock_t rd_msg_spinlock;
207 struct work_struct bh_hbm_work;
209 /* IPC write queue */
210 struct wr_msg_ctl_info wr_processing_list_head, wr_free_list_head;
211 /* For both processing list and free list */
212 spinlock_t wr_processing_spinlock;
214 spinlock_t out_ipc_spinlock;
216 struct ishtp_fw_client *fw_clients; /*Note:memory has to be allocated*/
217 DECLARE_BITMAP(fw_clients_map, ISHTP_CLIENTS_MAX);
218 DECLARE_BITMAP(host_clients_map, ISHTP_CLIENTS_MAX);
219 uint8_t fw_clients_num;
220 uint8_t fw_client_presentation_num;
221 uint8_t fw_client_index;
222 spinlock_t fw_clients_lock;
224 /* TX DMA buffers and slots */
225 int ishtp_host_dma_enabled;
226 void *ishtp_host_dma_tx_buf;
227 unsigned int ishtp_host_dma_tx_buf_size;
228 uint64_t ishtp_host_dma_tx_buf_phys;
229 int ishtp_dma_num_slots;
231 /* map of 4k blocks in Tx dma buf: 0-free, 1-used */
232 uint8_t *ishtp_dma_tx_map;
233 spinlock_t ishtp_dma_tx_lock;
235 /* RX DMA buffers and slots */
236 void *ishtp_host_dma_rx_buf;
237 unsigned int ishtp_host_dma_rx_buf_size;
238 uint64_t ishtp_host_dma_rx_buf_phys;
240 /* Dump to trace buffers if enabled*/
241 void (*print_log)(struct ishtp_device *dev, char *format, ...);
243 /* Debug stats */
244 unsigned int ipc_rx_cnt;
245 unsigned long long ipc_rx_bytes_cnt;
246 unsigned int ipc_tx_cnt;
247 unsigned long long ipc_tx_bytes_cnt;
249 const struct ishtp_hw_ops *ops;
250 size_t mtu;
251 uint32_t ishtp_msg_hdr;
252 char hw[0] __aligned(sizeof(void *));
255 static inline unsigned long ishtp_secs_to_jiffies(unsigned long sec)
257 return msecs_to_jiffies(sec * MSEC_PER_SEC);
261 * Register Access Function
263 static inline int ish_ipc_reset(struct ishtp_device *dev)
265 return dev->ops->ipc_reset(dev);
268 static inline int ish_hw_reset(struct ishtp_device *dev)
270 return dev->ops->hw_reset(dev);
273 /* Exported function */
274 void ishtp_device_init(struct ishtp_device *dev);
275 int ishtp_start(struct ishtp_device *dev);
277 #endif /*_ISHTP_DEV_H_*/