summaryrefslogtreecommitdiff
path: root/drivers/hid/intel-ish-hid/ishtp/hbm.h
blob: d96111cef7f84d2e47495c4dd5ccd724c54bfe69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/*
 * ISHTP bus layer messages handling
 *
 * Copyright (c) 2003-2016, Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 */

#ifndef _ISHTP_HBM_H_
#define _ISHTP_HBM_H_

#include <linux/uuid.h>

struct ishtp_device;
struct ishtp_msg_hdr;
struct ishtp_cl;

/*
 * Timeouts in Seconds
 */
#define ISHTP_INTEROP_TIMEOUT		7 /* Timeout on ready message */

#define ISHTP_CL_CONNECT_TIMEOUT	15 /* HPS: Client Connect Timeout */

/*
 * ISHTP Version
 */
#define HBM_MINOR_VERSION		0
#define HBM_MAJOR_VERSION		1

/* Host bus message command opcode */
#define ISHTP_HBM_CMD_OP_MSK		0x7f
/* Host bus message command RESPONSE */
#define ISHTP_HBM_CMD_RES_MSK		0x80

/*
 * ISHTP Bus Message Command IDs
 */
#define HOST_START_REQ_CMD		0x01
#define HOST_START_RES_CMD		0x81

#define HOST_STOP_REQ_CMD		0x02
#define HOST_STOP_RES_CMD		0x82

#define FW_STOP_REQ_CMD			0x03

#define HOST_ENUM_REQ_CMD		0x04
#define HOST_ENUM_RES_CMD		0x84

#define HOST_CLIENT_PROPERTIES_REQ_CMD	0x05
#define HOST_CLIENT_PROPERTIES_RES_CMD	0x85

#define CLIENT_CONNECT_REQ_CMD		0x06
#define CLIENT_CONNECT_RES_CMD		0x86

#define CLIENT_DISCONNECT_REQ_CMD	0x07
#define CLIENT_DISCONNECT_RES_CMD	0x87

#define ISHTP_FLOW_CONTROL_CMD		0x08

#define DMA_BUFFER_ALLOC_NOTIFY		0x11
#define DMA_BUFFER_ALLOC_RESPONSE	0x91

#define DMA_XFER			0x12
#define DMA_XFER_ACK			0x92

/*
 * ISHTP Stop Reason
 * used by hbm_host_stop_request.reason
 */
#define	DRIVER_STOP_REQUEST		0x00

/*
 * ISHTP BUS Interface Section
 */
struct ishtp_msg_hdr {
	uint32_t fw_addr:8;
	uint32_t host_addr:8;
	uint32_t length:9;
	uint32_t reserved:6;
	uint32_t msg_complete:1;
} __packed;

struct ishtp_bus_message {
	uint8_t hbm_cmd;
	uint8_t data[0];
} __packed;

/**
 * struct hbm_cl_cmd - client specific host bus command
 *	CONNECT, DISCONNECT, and FlOW CONTROL
 *
 * @hbm_cmd - bus message command header
 * @fw_addr - address of the fw client
 * @host_addr - address of the client in the driver
 * @data
 */
struct ishtp_hbm_cl_cmd {
	uint8_t hbm_cmd;
	uint8_t fw_addr;
	uint8_t host_addr;
	uint8_t data;
};

struct hbm_version {
	uint8_t minor_version;
	uint8_t major_version;
} __packed;

struct hbm_host_version_request {
	uint8_t hbm_cmd;
	uint8_t reserved;
	struct hbm_version host_version;
} __packed;

struct hbm_host_version_response {
	uint8_t hbm_cmd;
	uint8_t host_version_supported;
	struct hbm_version fw_max_version;
} __packed;

struct hbm_host_stop_request {
	uint8_t hbm_cmd;
	uint8_t reason;
	uint8_t reserved[2];
} __packed;

struct hbm_host_stop_response {
	uint8_t hbm_cmd;
	uint8_t reserved[3];
} __packed;

struct hbm_host_enum_request {
	uint8_t hbm_cmd;
	uint8_t reserved[3];
} __packed;

struct hbm_host_enum_response {
	uint8_t hbm_cmd;
	uint8_t reserved[3];
	uint8_t valid_addresses[32];
} __packed;

struct ishtp_client_properties {
	uuid_le protocol_name;
	uint8_t protocol_version;
	uint8_t max_number_of_connections;
	uint8_t fixed_address;
	uint8_t single_recv_buf;
	uint32_t max_msg_length;
	uint8_t dma_hdr_len;
#define	ISHTP_CLIENT_DMA_ENABLED	0x80
	uint8_t reserved4;
	uint8_t reserved5;
	uint8_t reserved6;
} __packed;

struct hbm_props_request {
	uint8_t hbm_cmd;
	uint8_t address;
	uint8_t reserved[2];
} __packed;

struct hbm_props_response {
	uint8_t hbm_cmd;
	uint8_t address;
	uint8_t status;
	uint8_t reserved[1];
	struct ishtp_client_properties client_properties;
} __packed;

/**
 * struct hbm_client_connect_request - connect/disconnect request
 *
 * @hbm_cmd - bus message command header
 * @fw_addr - address of the fw client
 * @host_addr - address of the client in the driver
 * @reserved
 */
struct hbm_client_connect_request {
	uint8_t hbm_cmd;
	uint8_t fw_addr;
	uint8_t host_addr;
	uint8_t reserved;
} __packed;

/**
 * struct hbm_client_connect_response - connect/disconnect response
 *
 * @hbm_cmd - bus message command header
 * @fw_addr - address of the fw client
 * @host_addr - address of the client in the driver
 * @status - status of the request
 */
struct hbm_client_connect_response {
	uint8_t hbm_cmd;
	uint8_t fw_addr;
	uint8_t host_addr;
	uint8_t status;
} __packed;


#define ISHTP_FC_MESSAGE_RESERVED_LENGTH		5

struct hbm_flow_control {
	uint8_t hbm_cmd;
	uint8_t fw_addr;
	uint8_t host_addr;
	uint8_t reserved[ISHTP_FC_MESSAGE_RESERVED_LENGTH];
} __packed;

struct dma_alloc_notify {
	uint8_t hbm;
	uint8_t status;
	uint8_t reserved[2];
	uint32_t buf_size;
	uint64_t buf_address;
	/* [...] May come more size/address pairs */
} __packed;

struct dma_xfer_hbm {
	uint8_t hbm;
	uint8_t fw_client_id;
	uint8_t host_client_id;
	uint8_t reserved;
	uint64_t msg_addr;
	uint32_t msg_length;
	uint32_t reserved2;
} __packed;

/* System state */
#define ISHTP_SYSTEM_STATE_CLIENT_ADDR		13

#define SYSTEM_STATE_SUBSCRIBE			0x1
#define SYSTEM_STATE_STATUS			0x2
#define SYSTEM_STATE_QUERY_SUBSCRIBERS		0x3
#define SYSTEM_STATE_STATE_CHANGE_REQ		0x4
/*indicates suspend and resume states*/
#define SUSPEND_STATE_BIT			(1<<1)

struct ish_system_states_header {
	uint32_t cmd;
	uint32_t cmd_status;	/*responses will have this set*/
} __packed;

struct ish_system_states_subscribe {
	struct ish_system_states_header hdr;
	uint32_t states;
} __packed;

struct ish_system_states_status {
	struct ish_system_states_header hdr;
	uint32_t supported_states;
	uint32_t states_status;
} __packed;

struct ish_system_states_query_subscribers {
	struct ish_system_states_header hdr;
} __packed;

struct ish_system_states_state_change_req {
	struct ish_system_states_header hdr;
	uint32_t requested_states;
	uint32_t states_status;
} __packed;

/**
 * enum ishtp_hbm_state - host bus message protocol state
 *
 * @ISHTP_HBM_IDLE : protocol not started
 * @ISHTP_HBM_START : start request message was sent
 * @ISHTP_HBM_ENUM_CLIENTS : enumeration request was sent
 * @ISHTP_HBM_CLIENT_PROPERTIES : acquiring clients properties
 */
enum ishtp_hbm_state {
	ISHTP_HBM_IDLE = 0,
	ISHTP_HBM_START,
	ISHTP_HBM_STARTED,
	ISHTP_HBM_ENUM_CLIENTS,
	ISHTP_HBM_CLIENT_PROPERTIES,
	ISHTP_HBM_WORKING,
	ISHTP_HBM_STOPPED,
};

static inline void ishtp_hbm_hdr(struct ishtp_msg_hdr *hdr, size_t length)
{
	hdr->host_addr = 0;
	hdr->fw_addr = 0;
	hdr->length = length;
	hdr->msg_complete = 1;
	hdr->reserved = 0;
}

int ishtp_hbm_start_req(struct ishtp_device *dev);
int ishtp_hbm_start_wait(struct ishtp_device *dev);
int ishtp_hbm_cl_flow_control_req(struct ishtp_device *dev,
				  struct ishtp_cl *cl);
int ishtp_hbm_cl_disconnect_req(struct ishtp_device *dev, struct ishtp_cl *cl);
int ishtp_hbm_cl_connect_req(struct ishtp_device *dev, struct ishtp_cl *cl);
void ishtp_hbm_enum_clients_req(struct ishtp_device *dev);
void bh_hbm_work_fn(struct work_struct *work);
void recv_hbm(struct ishtp_device *dev, struct ishtp_msg_hdr *ishtp_hdr);
void recv_fixed_cl_msg(struct ishtp_device *dev,
	struct ishtp_msg_hdr *ishtp_hdr);
void ishtp_hbm_dispatch(struct ishtp_device *dev,
	struct ishtp_bus_message *hdr);

void ishtp_query_subscribers(struct ishtp_device *dev);

/* Exported I/F */
void ishtp_send_suspend(struct ishtp_device *dev);
void ishtp_send_resume(struct ishtp_device *dev);

#endif /* _ISHTP_HBM_H_ */