1 /*
2  * ISHTP bus layer messages handling
3  *
4  * Copyright (c) 2003-2016, 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 #ifndef _ISHTP_HBM_H_
17 #define _ISHTP_HBM_H_
18 
19 #include <linux/uuid.h>
20 
21 struct ishtp_device;
22 struct ishtp_msg_hdr;
23 struct ishtp_cl;
24 
25 /*
26  * Timeouts in Seconds
27  */
28 #define ISHTP_INTEROP_TIMEOUT		7 /* Timeout on ready message */
29 
30 #define ISHTP_CL_CONNECT_TIMEOUT	15 /* HPS: Client Connect Timeout */
31 
32 /*
33  * ISHTP Version
34  */
35 #define HBM_MINOR_VERSION		0
36 #define HBM_MAJOR_VERSION		1
37 
38 /* Host bus message command opcode */
39 #define ISHTP_HBM_CMD_OP_MSK		0x7f
40 /* Host bus message command RESPONSE */
41 #define ISHTP_HBM_CMD_RES_MSK		0x80
42 
43 /*
44  * ISHTP Bus Message Command IDs
45  */
46 #define HOST_START_REQ_CMD		0x01
47 #define HOST_START_RES_CMD		0x81
48 
49 #define HOST_STOP_REQ_CMD		0x02
50 #define HOST_STOP_RES_CMD		0x82
51 
52 #define FW_STOP_REQ_CMD			0x03
53 
54 #define HOST_ENUM_REQ_CMD		0x04
55 #define HOST_ENUM_RES_CMD		0x84
56 
57 #define HOST_CLIENT_PROPERTIES_REQ_CMD	0x05
58 #define HOST_CLIENT_PROPERTIES_RES_CMD	0x85
59 
60 #define CLIENT_CONNECT_REQ_CMD		0x06
61 #define CLIENT_CONNECT_RES_CMD		0x86
62 
63 #define CLIENT_DISCONNECT_REQ_CMD	0x07
64 #define CLIENT_DISCONNECT_RES_CMD	0x87
65 
66 #define ISHTP_FLOW_CONTROL_CMD		0x08
67 
68 #define DMA_BUFFER_ALLOC_NOTIFY		0x11
69 #define DMA_BUFFER_ALLOC_RESPONSE	0x91
70 
71 #define DMA_XFER			0x12
72 #define DMA_XFER_ACK			0x92
73 
74 /*
75  * ISHTP Stop Reason
76  * used by hbm_host_stop_request.reason
77  */
78 #define	DRIVER_STOP_REQUEST		0x00
79 
80 /*
81  * ISHTP BUS Interface Section
82  */
83 struct ishtp_msg_hdr {
84 	uint32_t fw_addr:8;
85 	uint32_t host_addr:8;
86 	uint32_t length:9;
87 	uint32_t reserved:6;
88 	uint32_t msg_complete:1;
89 } __packed;
90 
91 struct ishtp_bus_message {
92 	uint8_t hbm_cmd;
93 	uint8_t data[0];
94 } __packed;
95 
96 /**
97  * struct hbm_cl_cmd - client specific host bus command
98  *	CONNECT, DISCONNECT, and FlOW CONTROL
99  *
100  * @hbm_cmd - bus message command header
101  * @fw_addr - address of the fw client
102  * @host_addr - address of the client in the driver
103  * @data
104  */
105 struct ishtp_hbm_cl_cmd {
106 	uint8_t hbm_cmd;
107 	uint8_t fw_addr;
108 	uint8_t host_addr;
109 	uint8_t data;
110 };
111 
112 struct hbm_version {
113 	uint8_t minor_version;
114 	uint8_t major_version;
115 } __packed;
116 
117 struct hbm_host_version_request {
118 	uint8_t hbm_cmd;
119 	uint8_t reserved;
120 	struct hbm_version host_version;
121 } __packed;
122 
123 struct hbm_host_version_response {
124 	uint8_t hbm_cmd;
125 	uint8_t host_version_supported;
126 	struct hbm_version fw_max_version;
127 } __packed;
128 
129 struct hbm_host_stop_request {
130 	uint8_t hbm_cmd;
131 	uint8_t reason;
132 	uint8_t reserved[2];
133 } __packed;
134 
135 struct hbm_host_stop_response {
136 	uint8_t hbm_cmd;
137 	uint8_t reserved[3];
138 } __packed;
139 
140 struct hbm_host_enum_request {
141 	uint8_t hbm_cmd;
142 	uint8_t reserved[3];
143 } __packed;
144 
145 struct hbm_host_enum_response {
146 	uint8_t hbm_cmd;
147 	uint8_t reserved[3];
148 	uint8_t valid_addresses[32];
149 } __packed;
150 
151 struct ishtp_client_properties {
152 	uuid_le protocol_name;
153 	uint8_t protocol_version;
154 	uint8_t max_number_of_connections;
155 	uint8_t fixed_address;
156 	uint8_t single_recv_buf;
157 	uint32_t max_msg_length;
158 	uint8_t dma_hdr_len;
159 #define	ISHTP_CLIENT_DMA_ENABLED	0x80
160 	uint8_t reserved4;
161 	uint8_t reserved5;
162 	uint8_t reserved6;
163 } __packed;
164 
165 struct hbm_props_request {
166 	uint8_t hbm_cmd;
167 	uint8_t address;
168 	uint8_t reserved[2];
169 } __packed;
170 
171 struct hbm_props_response {
172 	uint8_t hbm_cmd;
173 	uint8_t address;
174 	uint8_t status;
175 	uint8_t reserved[1];
176 	struct ishtp_client_properties client_properties;
177 } __packed;
178 
179 /**
180  * struct hbm_client_connect_request - connect/disconnect request
181  *
182  * @hbm_cmd - bus message command header
183  * @fw_addr - address of the fw client
184  * @host_addr - address of the client in the driver
185  * @reserved
186  */
187 struct hbm_client_connect_request {
188 	uint8_t hbm_cmd;
189 	uint8_t fw_addr;
190 	uint8_t host_addr;
191 	uint8_t reserved;
192 } __packed;
193 
194 /**
195  * struct hbm_client_connect_response - connect/disconnect response
196  *
197  * @hbm_cmd - bus message command header
198  * @fw_addr - address of the fw client
199  * @host_addr - address of the client in the driver
200  * @status - status of the request
201  */
202 struct hbm_client_connect_response {
203 	uint8_t hbm_cmd;
204 	uint8_t fw_addr;
205 	uint8_t host_addr;
206 	uint8_t status;
207 } __packed;
208 
209 
210 #define ISHTP_FC_MESSAGE_RESERVED_LENGTH		5
211 
212 struct hbm_flow_control {
213 	uint8_t hbm_cmd;
214 	uint8_t fw_addr;
215 	uint8_t host_addr;
216 	uint8_t reserved[ISHTP_FC_MESSAGE_RESERVED_LENGTH];
217 } __packed;
218 
219 struct dma_alloc_notify {
220 	uint8_t hbm;
221 	uint8_t status;
222 	uint8_t reserved[2];
223 	uint32_t buf_size;
224 	uint64_t buf_address;
225 	/* [...] May come more size/address pairs */
226 } __packed;
227 
228 struct dma_xfer_hbm {
229 	uint8_t hbm;
230 	uint8_t fw_client_id;
231 	uint8_t host_client_id;
232 	uint8_t reserved;
233 	uint64_t msg_addr;
234 	uint32_t msg_length;
235 	uint32_t reserved2;
236 } __packed;
237 
238 /* System state */
239 #define ISHTP_SYSTEM_STATE_CLIENT_ADDR		13
240 
241 #define SYSTEM_STATE_SUBSCRIBE			0x1
242 #define SYSTEM_STATE_STATUS			0x2
243 #define SYSTEM_STATE_QUERY_SUBSCRIBERS		0x3
244 #define SYSTEM_STATE_STATE_CHANGE_REQ		0x4
245 /*indicates suspend and resume states*/
246 #define SUSPEND_STATE_BIT			(1<<1)
247 
248 struct ish_system_states_header {
249 	uint32_t cmd;
250 	uint32_t cmd_status;	/*responses will have this set*/
251 } __packed;
252 
253 struct ish_system_states_subscribe {
254 	struct ish_system_states_header hdr;
255 	uint32_t states;
256 } __packed;
257 
258 struct ish_system_states_status {
259 	struct ish_system_states_header hdr;
260 	uint32_t supported_states;
261 	uint32_t states_status;
262 } __packed;
263 
264 struct ish_system_states_query_subscribers {
265 	struct ish_system_states_header hdr;
266 } __packed;
267 
268 struct ish_system_states_state_change_req {
269 	struct ish_system_states_header hdr;
270 	uint32_t requested_states;
271 	uint32_t states_status;
272 } __packed;
273 
274 /**
275  * enum ishtp_hbm_state - host bus message protocol state
276  *
277  * @ISHTP_HBM_IDLE : protocol not started
278  * @ISHTP_HBM_START : start request message was sent
279  * @ISHTP_HBM_ENUM_CLIENTS : enumeration request was sent
280  * @ISHTP_HBM_CLIENT_PROPERTIES : acquiring clients properties
281  */
282 enum ishtp_hbm_state {
283 	ISHTP_HBM_IDLE = 0,
284 	ISHTP_HBM_START,
285 	ISHTP_HBM_STARTED,
286 	ISHTP_HBM_ENUM_CLIENTS,
287 	ISHTP_HBM_CLIENT_PROPERTIES,
288 	ISHTP_HBM_WORKING,
289 	ISHTP_HBM_STOPPED,
290 };
291 
ishtp_hbm_hdr(struct ishtp_msg_hdr * hdr,size_t length)292 static inline void ishtp_hbm_hdr(struct ishtp_msg_hdr *hdr, size_t length)
293 {
294 	hdr->host_addr = 0;
295 	hdr->fw_addr = 0;
296 	hdr->length = length;
297 	hdr->msg_complete = 1;
298 	hdr->reserved = 0;
299 }
300 
301 int ishtp_hbm_start_req(struct ishtp_device *dev);
302 int ishtp_hbm_start_wait(struct ishtp_device *dev);
303 int ishtp_hbm_cl_flow_control_req(struct ishtp_device *dev,
304 				  struct ishtp_cl *cl);
305 int ishtp_hbm_cl_disconnect_req(struct ishtp_device *dev, struct ishtp_cl *cl);
306 int ishtp_hbm_cl_connect_req(struct ishtp_device *dev, struct ishtp_cl *cl);
307 void ishtp_hbm_enum_clients_req(struct ishtp_device *dev);
308 void bh_hbm_work_fn(struct work_struct *work);
309 void recv_hbm(struct ishtp_device *dev, struct ishtp_msg_hdr *ishtp_hdr);
310 void recv_fixed_cl_msg(struct ishtp_device *dev,
311 	struct ishtp_msg_hdr *ishtp_hdr);
312 void ishtp_hbm_dispatch(struct ishtp_device *dev,
313 	struct ishtp_bus_message *hdr);
314 
315 void ishtp_query_subscribers(struct ishtp_device *dev);
316 
317 /* Exported I/F */
318 void ishtp_send_suspend(struct ishtp_device *dev);
319 void ishtp_send_resume(struct ishtp_device *dev);
320 
321 #endif /* _ISHTP_HBM_H_ */
322