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